import type { Stream, Streamable } from '@rimbu/stream'; import { HashMap, HashSet } from '@rimbu/hashed'; import type { ArrowGraphHashedCreators, GraphElement, } from '@rimbu/graph/custom'; import { type ArrowGraphBase, GraphContext } from '@rimbu/graph/custom'; /** * A type-invariant immutable arrow (directed) graph. * The connections are internally maintained using hashed collections. * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowGraphHashed API documentation](https://rimbu.org/api/rimbu/graph/ArrowGraphHashed/interface) * @typeparam N - the node type * @example * ```ts * const g1 = ArrowGraphHashed.empty() * const g2 = ArrowGraphHashed.of([1], [2, 3], [2, 4]) * ``` */ export interface ArrowGraphHashed extends ArrowGraphBase {} export namespace ArrowGraphHashed { /** * A non-empty type-invariant immutable arrow (directed) graph. * The connections are internally maintained using hashed collections. * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowGraphHashed API documentation](https://rimbu.org/api/rimbu/graph/ArrowGraphHashed/interface) * @typeparam N - the node type */ export interface NonEmpty extends ArrowGraphBase.NonEmpty, Omit, keyof ArrowGraphBase.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 * ArrowGraphHashed.of([1], [2, 3]).stream().toArray() // => [[1], [2, 3]] * ``` */ stream(): Stream.NonEmpty>; } /** * A mutable `ArrowGraphHashed` builder used to efficiently create new immutable instances. * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowGraphHashed.Builder API documentation](https://rimbu.org/api/rimbu/graph/ArrowGraphHashed/Builder/interface) * @typeparam N - the node type */ export interface Builder extends ArrowGraphBase.Builder {} /** * The ArrowGraphHashed'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 ArrowGraphBase.Context { readonly typeTag: 'ArrowGraphHashed'; } /** * Utility interface that provides higher-kinded types for this collection. */ export interface Types extends ArrowGraphBase.Types { readonly normal: ArrowGraphHashed; readonly nonEmpty: ArrowGraphHashed.NonEmpty; readonly context: ArrowGraphHashed.Context; readonly builder: ArrowGraphHashed.Builder; readonly linkMap: HashMap>; readonly linkMapNonEmpty: HashMap.NonEmpty>; readonly linkMapContext: HashMap.Context; readonly linkConnectionsContext: HashSet.Context; readonly linkMapBuilder: HashMap.Builder< this['_N'], HashSet.Builder >; readonly linkConnectionsBuilder: HashSet.Builder; readonly linkConnections: HashSet; } } function createContext(options?: { linkMapContext?: HashMap.Context; linkConnectionsContext?: HashSet.Context; }): ArrowGraphHashed.Context { return Object.freeze( new GraphContext( true, 'ArrowGraphHashed', options?.linkMapContext ?? HashMap.defaultContext(), options?.linkConnectionsContext ?? HashSet.defaultContext() ) ); } const _defaultContext: ArrowGraphHashed.Context = createContext(); export const ArrowGraphHashed: ArrowGraphHashedCreators = Object.freeze({ ..._defaultContext, createContext, defaultContext(): ArrowGraphHashed.Context { return _defaultContext; }, });