import type { RMap, RSet } from '@rimbu/collection-types'; import type { Stream, Streamable } from '@rimbu/stream'; import type { EdgeGraphCreators, GraphElement } from '@rimbu/graph/custom'; import { type EdgeGraphBase, GraphContext } from '@rimbu/graph/custom'; /** * A type-invariant immutable edge (undirected) graph. * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [EdgeGraph API documentation](https://rimbu.org/api/rimbu/graph/EdgeGraph/interface) * @typeparam N - the node type */ export interface EdgeGraph extends EdgeGraphBase {} export namespace EdgeGraph { /** * A non-empty type-invariant immutable edge (undirected) graph. * @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. * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [EdgeGraph API documentation](https://rimbu.org/api/rimbu/graph/EdgeGraph/interface) * @example * ```ts * EdgeGraphHashed.of([1], [2, 3]).stream().toArray() // => [[1], [2, 3]] * ``` */ stream(): Stream.NonEmpty>; } /** * A mutable `EdgeGraph` builder used to efficiently create new immutable instances. * See the [Graph documentation](https://rimbu.org/docs/collections/graph) and the [EdgeGraph.Builder API documentation](https://rimbu.org/api/rimbu/graph/EdgeGraph/Builder/interface) * @typeparam N - the node type */ export interface Builder extends EdgeGraphBase.Builder {} /** * The EdgeGraph'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 {} /** * Utility interface that provides higher-kinded types for this collection. */ export interface Types extends EdgeGraphBase.Types { readonly normal: EdgeGraph; readonly nonEmpty: EdgeGraph.NonEmpty; readonly context: EdgeGraph.Context; readonly builder: EdgeGraph.Builder; } } export const EdgeGraph: EdgeGraphCreators = Object.freeze({ createContext(options: { linkMapContext: RMap.Context; linkConnectionsContext: RSet.Context; }): EdgeGraph.Context { return Object.freeze( new GraphContext( false, 'EdgeGraph', options.linkMapContext, options.linkConnectionsContext ) ); }, });