import { type BiMultiMapSorted, type BiMultiMapBase, BiMultiMapContext, } from '@rimbu/bimultimap/custom'; import { SortedMultiMapSortedValue } from '@rimbu/multimap'; import type { Streamable } from '@rimbu/stream'; import type { SortedSet } from '@rimbu/sorted'; /** * A type-invariant immutable bi-directional MultiMap where keys and values have a * many-to-many mapping. Its keys and values are sorted. * See the [BiMultiMap documentation](https://rimbu.org/docs/collections/bimultimap) and the [SortedBiMultiMap API documentation](https://rimbu.org/api/rimbu/bimultimap/SortedBiMultiMap/interface) * @typeparam K - the key type * @typeparam V - the value type * @example * ```ts * const h1 = SortedBiMultiMap.empty() * const h2 = SortedBiMultiMap.of([1, 'a'], [1, 'b']) * ``` */ export interface SortedBiMultiMap extends BiMultiMapBase {} export namespace SortedBiMultiMap { /** * A non-empty type-invariant immutable bi-directional MultiMap where keys and values have a * many-to-many mapping. Its keys and values are sorted. * See the [BiMultiMap documentation](https://rimbu.org/docs/collections/bimultimap) and the [SortedBiMultiMap API documentation](https://rimbu.org/api/rimbu/bimultimap/SortedBiMultiMap/interface) * @typeparam K - the key type * @typeparam V - the value type */ export interface NonEmpty extends BiMultiMapBase.NonEmpty, Omit< SortedBiMultiMap, keyof BiMultiMapBase.NonEmpty >, Streamable.NonEmpty<[K, V]> {} /** * The SortedBiMultiMap'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: 'SortedBiMultiMap'; } /** * A mutable `SortedBiMultiMap` 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/SortedBiMultiMap/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: SortedBiMultiMap.Context; readonly normal: SortedBiMultiMap; readonly nonEmpty: SortedBiMultiMap.NonEmpty; readonly builder: SortedBiMultiMap.Builder; readonly keyValueMultiMapContext: SortedMultiMapSortedValue.Context< this['_K'], this['_V'] >; readonly valueKeyMultiMapContext: SortedMultiMapSortedValue.Context< this['_V'], this['_K'] >; readonly keyValueMultiMap: SortedMultiMapSortedValue< this['_K'], this['_V'] >; readonly valueKeyMultiMap: SortedMultiMapSortedValue< this['_V'], this['_K'] >; readonly keyValueMultiMapNonEmpty: SortedMultiMapSortedValue.NonEmpty< this['_K'], this['_V'] >; readonly valueKeyMultiMapNonEmpty: SortedMultiMapSortedValue.NonEmpty< this['_V'], this['_K'] >; readonly keyMultiMapValues: SortedSet; readonly valueMultiMapValues: SortedSet; } } function createContext(options?: { keyValueMultiMapContext?: SortedMultiMapSortedValue.Context; valueKeyMultiMapContext?: SortedMultiMapSortedValue.Context; }): SortedBiMultiMap.Context { return Object.freeze( new BiMultiMapContext( 'SortedBiMultiMap', options?.keyValueMultiMapContext ?? SortedMultiMapSortedValue.defaultContext(), options?.valueKeyMultiMapContext ?? SortedMultiMapSortedValue.defaultContext() ) ); } const _defaultContext: SortedBiMultiMap.Context = createContext(); export const SortedBiMultiMap: BiMultiMapSorted.Creators = Object.freeze({ ..._defaultContext, createContext, defaultContext(): SortedBiMultiMap.Context { return _defaultContext; }, });