import type { BiMultiMapHashed } from '@rimbu/bimultimap/custom'; import { type BiMultiMapBase, BiMultiMapContext, } from '@rimbu/bimultimap/custom'; import type { HashSet } from '@rimbu/hashed'; import { HashMultiMapHashValue } from '@rimbu/multimap'; import type { Streamable } from '@rimbu/stream'; /** * A type-invariant immutable bi-directional MultiMap where keys and values have a * many-to-many mapping. Its keys and values are hashed. * See the [BiMultiMap documentation](https://rimbu.org/docs/collections/bimultimap) and the [HashBiMultiMap API documentation](https://rimbu.org/api/rimbu/bimultimap/HashBiMultiMap/interface) * @typeparam K - the key type * @typeparam V - the value type * @example * ```ts * const h1 = HashBiMultiMap.empty() * const h2 = HashBiMultiMap.of([1, 'a'], [1, 'b']) * ``` */ export interface HashBiMultiMap extends BiMultiMapBase {} export namespace HashBiMultiMap { /** * A non-empty type-invariant immutable bi-directional MultiMap where keys and values have a * many-to-many mapping. Its keys and values are hashed. * See the [BiMultiMap documentation](https://rimbu.org/docs/collections/bimultimap) and the [HashBiMultiMap API documentation](https://rimbu.org/api/rimbu/bimultimap/HashBiMultiMap/interface) * @typeparam K - the key type * @typeparam V - the value type */ export interface NonEmpty extends BiMultiMapBase.NonEmpty, Omit, keyof BiMultiMapBase>, Streamable.NonEmpty<[K, V]> {} /** * The HashBiMultiMap's Context instance that serves as a factory for all related immutable instances and builders. * @typeparam UK - the upper type limit for key types for which this context can create instances * @typeparam UV - the upper type limit for value types for which this context can create instances */ export interface Context extends BiMultiMapBase.Context { readonly typeTag: 'HashBiMultiMap'; } /** * A mutable `HashBiMultiMap` builder used to efficiently create new immutable instances. * See the [BiMultiMap documentation](https://rimbu.org/docs/collections/bimultimap) and the [HashBiMultiMap.Builder API documentation](https://rimbu.org/api/rimbu/bimultimap/HashBiMultiMap/Builder/interface) * @typeparam K - the key type * @typeparam V - the value type */ export interface Builder extends BiMultiMapBase.Builder {} /** * Utility interface that provides higher-kinded types for this collection. */ export interface Types extends BiMultiMapBase.Types { readonly context: HashBiMultiMap.Context; readonly normal: HashBiMultiMap; readonly nonEmpty: HashBiMultiMap.NonEmpty; readonly builder: HashBiMultiMap.Builder; readonly keyValueMultiMap: HashMultiMapHashValue; readonly valueKeyMultiMap: HashMultiMapHashValue; readonly keyMultiMapValues: HashSet; readonly valueMultiMapValues: HashSet; } } function createContext(options?: { keyValueMultiMapContext?: HashMultiMapHashValue.Context; valueKeyMultiMapContext?: HashMultiMapHashValue.Context; }): HashBiMultiMap.Context { return Object.freeze( new BiMultiMapContext( 'HashBiMultiMap', options?.keyValueMultiMapContext ?? HashMultiMapHashValue.defaultContext(), options?.valueKeyMultiMapContext ?? HashMultiMapHashValue.defaultContext() ) ); } const _defaultContext: HashBiMultiMap.Context = createContext(); export const HashBiMultiMap: BiMultiMapHashed.Creators = Object.freeze({ ..._defaultContext, createContext, defaultContext(): HashBiMultiMap.Context { return _defaultContext; }, });