import type { Stream, Streamable } from '@rimbu/stream'; import { SortedMap } from '@rimbu/sorted'; import type { ArrowValuedGraphSortedCreators, ValuedGraphElement, } from '@rimbu/graph/custom'; import { type ArrowValuedGraphBase, ValuedGraphContext, } from '@rimbu/graph/custom'; /** * A type-invariant immutable valued arrow (directed) graph. * The nodes are internally maintained using SortedMaps * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowValuedGraphSorted API documentation](https://rimbu.org/api/rimbu/graph/ArrowValuedGraphSorted/interface) * @typeparam N - the node type * @typeparam V - the connection value type * @example * ```ts * const g1 = ArrowValuedGraphSorted.empty() * const g2 = ArrowValuedGraphSorted.of([1], [2, 3, 'a'], [2, 4, 'b']) * ``` */ export interface ArrowValuedGraphSorted extends ArrowValuedGraphBase {} export namespace ArrowValuedGraphSorted { /** * A non-empty type-invariant immutable valued arrow (directed) graph. * The nodes are internally maintained using SortedMaps * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowValuedGraphSorted API documentation](https://rimbu.org/api/rimbu/graph/ArrowValuedGraphSorted/interface) * @typeparam N - the node type * @typeparam V - the connection value type */ export interface NonEmpty extends ArrowValuedGraphBase.NonEmpty, Omit< ArrowValuedGraphSorted, keyof ArrowValuedGraphBase.NonEmpty >, Streamable.NonEmpty> { /** * Returns a non-empty `Stream` containing all graph elements of this collection as single tuples for isolated nodes * and 3-valued tuples containing the source node, target node, and connection value for connections. * @example * ```ts * ArrowValuedGraphHashed.of([1, 2, 'a'], [2, 3, 'b']).stream().toArray() * // => [[1, 2, 'a'], [2, 3, 'b']] * ``` */ stream(): Stream.NonEmpty>; } /** * A mutable `ArrowValuedGraphSorted` builder used to efficiently create new immutable instances. * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [ArrowValuedGraphSorted.Builder API documentation](https://rimbu.org/api/rimbu/graph/ArrowValuedGraphSorted/Builder/interface) * @typeparam N - the node type * @typeparam V - the connection value type */ export interface Builder extends ArrowValuedGraphBase.Builder {} /** * The ArrowValuedGraphSorted'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 ArrowValuedGraphBase.Context { readonly typeTag: 'ArrowValuedGraphSorted'; } /** * Utility interface that provides higher-kinded types for this collection. */ export interface Types extends ArrowValuedGraphBase.Types { readonly normal: ArrowValuedGraphSorted; readonly nonEmpty: ArrowValuedGraphSorted.NonEmpty; readonly context: ArrowValuedGraphSorted.Context; readonly builder: ArrowValuedGraphSorted.Builder; readonly linkMap: SortedMap>; readonly linkMapNonEmpty: SortedMap.NonEmpty< this['_N'], SortedMap >; readonly linkMapContext: SortedMap.Context; readonly linkConnectionsContext: SortedMap.Context; readonly linkMapBuilder: SortedMap.Builder< this['_N'], SortedMap.Builder >; readonly linkConnectionsBuilder: SortedMap.Builder; readonly linkConnections: SortedMap; } } function createContext(options?: { linkMapContext?: SortedMap.Context; linkConnectionsContext?: SortedMap.Context; }): ArrowValuedGraphSorted.Context { return Object.freeze( new ValuedGraphContext( true, 'ArrowValuedGraphSorted', options?.linkMapContext ?? SortedMap.defaultContext(), options?.linkConnectionsContext ?? SortedMap.defaultContext() ) ); } const _defaultContext: ArrowValuedGraphSorted.Context = createContext(); export const ArrowValuedGraphSorted: ArrowValuedGraphSortedCreators = Object.freeze({ ..._defaultContext, createContext, defaultContext(): ArrowValuedGraphSorted.Context { return _defaultContext; }, });