import { SortedMap, SortedSet } from '@rimbu/sorted'; import type { Stream, Streamable } from '@rimbu/stream'; import type { EdgeGraphSortedCreators, GraphElement, } from '@rimbu/graph/custom'; import { type EdgeGraphBase, GraphContext } from '@rimbu/graph/custom'; /** * A type-invariant immutable edge (undirected) graph. * The connections are internally maintained using sorted collections. * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [EdgeGraphSorted API documentation](https://rimbu.org/api/rimbu/graph/EdgeGraphSorted/interface) * @typeparam N - the node type * @example * ```ts * const g1 = EdgeGraphSorted.empty() * const g2 = EdgeGraphSorted.of([1], [2, 3], [2, 4]) * ``` */ export interface EdgeGraphSorted extends EdgeGraphBase {} export namespace EdgeGraphSorted { /** * A non-empty type-invariant immutable edge (undirected) graph. * The connections are internally maintained using sorted collections. * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [EdgeGraphSorted API documentation](https://rimbu.org/api/rimbu/graph/EdgeGraphSorted/interface) * @typeparam N - the node type */ export interface NonEmpty extends EdgeGraphBase.NonEmpty, Omit, keyof EdgeGraphBase.NonEmpty>, Streamable.NonEmpty> { /** * Returns a non-empty `Stream` containing all graph elements of this collection as single tuples for isolated nodes * and 2-valued tuples of nodes for connections. * @example * ```ts * EdgeGraphSorted.of([1], [2, 3]).stream().toArray() // => [[1], [2, 3]] * ``` */ stream(): Stream.NonEmpty>; } /** * A mutable `EdgeGraphSorted` builder used to efficiently create new immutable instances. * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [EdgeGraphSorted.Builder API documentation](https://rimbu.org/api/rimbu/graph/EdgeGraphSorted/Builder/interface) * @typeparam N - the node type */ export interface Builder extends EdgeGraphBase.Builder {} /** * The EdgeGraphSorted's Context instance that serves as a factory for all related immutable instances and builders. * @typeparam UN - the upper type limit for node types for which this context can create instances */ export interface Context extends EdgeGraphBase.Context { readonly typeTag: 'EdgeGraphSorted'; } /** * Utility interface that provides higher-kinded types for this collection. */ export interface Types extends EdgeGraphBase.Types { readonly normal: EdgeGraphSorted; readonly nonEmpty: EdgeGraphSorted.NonEmpty; readonly context: EdgeGraphSorted.Context; readonly builder: EdgeGraphSorted.Builder; readonly linkMap: SortedMap>; readonly linkMapNonEmpty: SortedMap.NonEmpty< this['_N'], SortedSet >; readonly linkMapContext: SortedMap.Context; readonly linkConnectionsContext: SortedSet.Context; readonly linkMapBuilder: SortedMap.Builder< this['_N'], SortedSet.Builder >; readonly linkConnectionsBuilder: SortedSet.Builder; readonly linkConnections: SortedSet; } } function createContext(options?: { linkMapContext?: SortedMap.Context; linkConnectionsContext?: SortedSet.Context; }): EdgeGraphSorted.Context { return Object.freeze( new GraphContext( false, 'EdgeGraphSorted', options?.linkMapContext ?? SortedMap.defaultContext(), options?.linkConnectionsContext ?? SortedSet.defaultContext() ) ); } const _defaultContext: EdgeGraphSorted.Context = createContext(); export const EdgeGraphSorted: EdgeGraphSortedCreators = Object.freeze({ ..._defaultContext, createContext, defaultContext(): EdgeGraphSorted.Context { return _defaultContext; }, });