import { c as TableValue, s as TableRow, t as IMapImmutable } from "./map-Dgj9_4Jy.js"; //#region src/table.d.ts /** * Stores values in a table of rows (vertical) and columns (horizontal) */ declare class Table { #private; rows: TableRow[]; rowLabels: string[]; colLabels: string[]; /** * Keep track of widest row */ columnMaxLength: number; /** * Gets the label for a given column index, * returning _undefined_ if not found. * * Case-sensitive * @param label Label to seek * @returns Index of column, or _undefined_ if not found */ getColumnLabelIndex(label: string): number | undefined; /** * Gets the label for a given row index, * returning _undefined_ if not found. * * Case-sensitive * @param label Label to seek * @returns Index of row, or _undefined_ if not found */ getRowLabelIndex(label: string): number | undefined; /** * Dumps the values of the table to the console */ print(): void; /** * Return a copy of table as nested array * * ```js * const t = new Table(); * // add stuff * // ... * const m = t.asArray(); * for (const row of m) { * for (const colValue of row) { * // iterate over all column values for this row * } * } * ``` * * Alternative: get value at row Y and column X * ```js * const value = m[y][x]; * ``` * @returns */ asArray(): (V | undefined)[][]; /** * Return the number of rows */ get rowCount(): number; /** * Return the maximum number of columns in any row */ get columnCount(): number; /** * Iterates over the table row-wise, in object format. * @see {@link rowsWithLabelsArray} to get rows in array format */ rowsWithLabelsObject(): Generator; /** * Iterates over each row, including the labels if available * @see {@link rowsWithLabelsObject} to get rows in object format */ rowsWithLabelsArray(): Generator<[label: string | undefined, value: V | undefined][] | undefined, void, unknown>; /** * Assign labels to columns * @param labels */ labelColumns(...labels: string[]): void; /** * Assign label to a specific column * First column has an index of 0 * @param columnIndex * @param label */ labelColumn(columnIndex: number, label: string): void; /** * Label rows * @param labels Labels */ labelRows(...labels: string[]): void; /** * Assign label to a specific row * First row has an index of 0 * @param rowIndex * @param label */ labelRow(rowIndex: number, label: string): void; /** * Adds a new row * @param data Columns */ appendRow(...data: TableValue[]): TableRow; /** * Gets a row along with labels, as an array * @param rowIndex * @returns */ getRowWithLabelsArray(rowIndex: number): [label: string | undefined, value: V | undefined][] | undefined; /** * Return a row of objects. Keys use the column labels. * * ```js * const row = table.getRowWithLabelsObject(10); * // eg: * // [{ colour: red, size: 10}, { colour: blue, size: 20 }] * ``` * @param rowIndex * @returns */ getRowWithLabelsObject(rowIndex: number): object | undefined; /** * Gets a copy of values at given row, specified by index or label * @param row * @returns Returns row or throws an error if label or index not found */ row(row: number | string): readonly (V | undefined)[] | undefined; /** * Set the value of row,columm. * Row is created if it doesn't exist, with the other column values being _undefined_ * @param row Index or label * @param column Column * @param value Value to set at row,column */ set(row: number | string, column: number | string, value: V | undefined): void; /** * Gets the value at a specified row and column. * Throws an error if coordinates are out of range or missing. * @param row Row index or label * @param column Column index or label * @returns */ get(row: number | string, column: number | string): TableValue; /** * Set all the columns of a row to a specified value. * * By default, sets the number of columns corresponding to * the table's maximum column length. To set an arbitrary * length of the row, use `length` * @param row Index or label of row * @param length How wide the row is. If unset, uses the current maximum width of rows. * @param value Value to set */ setRow(row: number | string, value: V | undefined, length?: number): TableRow; } declare namespace directed_graph_d_exports { export { ConnectOptions$1 as ConnectOptions, DirectedGraph, DistanceCompute, Edge$1 as Edge, Vertex$1 as Vertex, adjacentVertices$1 as adjacentVertices, areAdjacent, bfs, clone, connect$1 as connect, connectTo$1 as connectTo, connectWithEdges$1 as connectWithEdges, createVertex$1 as createVertex, dfs, disconnect, distance, distanceDefault, dumpGraph$1 as dumpGraph, edges, get, getCycles, getOrCreate$1 as getOrCreate, getOrFail, graph$1 as graph, graphFromVertices, hasKey, hasNoOuts, hasOnlyOuts, hasOut, isAcyclic, pathDijkstra, toAdjacencyMatrix$1 as toAdjacencyMatrix, topologicalSort, transitiveReduction, updateGraphVertex$1 as updateGraphVertex, vertexHasOut, vertices }; } type DistanceCompute = (graph: DirectedGraph, edge: Edge$1) => number; /** * Vertex. These are the _nodes_ of the graph. Immutable. * * They keep track of all of their outgoing edges, and * a unique id. * * Ids are used for accessing/updating vertices as well as in the * {@link Edge} type. They must be unique. */ type Vertex$1 = Readonly<{ out: readonly Edge$1[]; id: string; }>; /** * Edge. Immutable. * * Only encodes the destination vertex. The from * is known since edges are stored on the from vertex. */ type Edge$1 = Readonly<{ /** * Vertex id edge connects to (ie. destination) */ id: string; /** * Optional weight of edge */ weight?: number; }>; /** * Create a vertex with given id * @param id * @returns */ declare const createVertex$1: (id: string) => Vertex$1; /** * Options for connecting vertices */ type ConnectOptions$1 = Readonly<{ /** * From, or source of connection */ from: string; /** * To, or destination of connection. Can be multiple vertices for quick use */ to: string | string[]; /** * If true, edges in opposite direction are made as well */ bidi?: boolean; /** * Weight for this connection (optional) */ weight?: number; }>; /** * Directed graph. Immutable. * * Consists of {@link Vertex|vertices}, which all have zero or more outgoing {@link Edge|Edges}. */ type DirectedGraph = Readonly<{ vertices: IMapImmutable; }>; /** * Returns _true_ if graph contains `key`. * * ```js * // Same as * g.vertices.has(key) * ``` * @param graph * @param key * @returns */ declare function hasKey(graph: DirectedGraph, key: string): boolean; /** * Returns {@link Vertex} under `key`, or _undefined_ * if not found. * * ```js * // Same as * g.vertices.get(key) * ``` * @param graph * @param key * @returns */ declare function get(graph: DirectedGraph, key: string): Vertex$1 | undefined; /** * Returns the graph connections as an adjacency matrix * @param graph * @returns */ declare function toAdjacencyMatrix$1(graph: DirectedGraph): Table; /** * Return a string representation of the graph for debug inspection * @param graph * @returns */ declare const dumpGraph$1: (graph: DirectedGraph | Iterable) => string; /** * Returns the weight of an edge, or 1 if undefined. * @param graph * @param edge * @returns */ declare const distance: (graph: DirectedGraph, edge: Edge$1) => number; /** * Iterate over all the edges in the graph * @param graph */ declare function edges(graph: DirectedGraph): Generator, void, unknown>; /** * Iterate over all the vertices of the graph * @param graph */ declare function vertices(graph: DirectedGraph): Generator, void, unknown>; /** * Iterate over all the vertices connected to `context` vertex * @param graph Graph * @param context id or Vertex. * @returns */ declare function adjacentVertices$1(graph: DirectedGraph, context: Vertex$1 | string | undefined): Generator, void, unknown>; /** * Returns _true_ if `vertex` has an outgoing connection to * the supplied id or vertex. * * If `vertex` is undefined, _false_ is returned. * @param vertex From vertex * @param outIdOrVertex To vertex * @returns */ declare const vertexHasOut: (vertex: Vertex$1, outIdOrVertex: string | Vertex$1) => boolean; /** * Returns _true_ if `vertex` has no outgoing connections * @param graph * @param vertex * @returns */ declare const hasNoOuts: (graph: DirectedGraph, vertex: string | Vertex$1) => boolean; /** * Returns _true_ if `vertex` only has the given list of vertices. * Returns _false_ early if the length of the list does not match up with `vertex.out` * @param graph * @param vertex * @param outIdOrVertex * @returns */ declare const hasOnlyOuts: (graph: DirectedGraph, vertex: string | Vertex$1, ...outIdOrVertex: (string | Vertex$1)[]) => boolean; /** * Returns _true_ if `vertex` has an outgoing connection to the given vertex. * @param graph * @param vertex * @param outIdOrVertex * @returns */ declare const hasOut: (graph: DirectedGraph, vertex: string | Vertex$1, outIdOrVertex: string | Vertex$1) => boolean; /** * Gets a vertex by id, creating it if it does not exist. * @param graph * @param id * @returns */ declare const getOrCreate$1: (graph: DirectedGraph, id: string) => Readonly<{ graph: DirectedGraph; vertex: Vertex$1; }>; /** * Gets a vertex by id, throwing an error if it does not exist * @param graph * @param id * @returns */ declare const getOrFail: (graph: DirectedGraph, id: string) => Vertex$1; /** * Updates a vertex by returning a mutated graph * @param graph Graph * @param vertex Newly changed vertex * @returns */ declare const updateGraphVertex$1: (graph: DirectedGraph, vertex: Vertex$1) => DirectedGraph; /** * Default distance computer. Uses `weight` property of edge, or `1` if not found. * @param graph * @param edge * @returns */ declare const distanceDefault: (graph: DirectedGraph, edge: Edge$1) => number; /** * Returns a mutation of `graph`, with a given edge removed. * * If edge was not there, original graph is returned. * @param graph * @param from * @param to * @returns */ declare function disconnect(graph: DirectedGraph, from: string | Vertex$1, to: string | Vertex$1): DirectedGraph; /** * Make a connection between two vertices with a given weight. * It returns the new graph as wll as the created edge. * @param graph * @param from * @param to * @param weight * @returns */ declare function connectTo$1(graph: DirectedGraph, from: string, to: string, weight?: number): { graph: DirectedGraph; edge: Edge$1; }; /** * Connect from -> to. Same as {@link connectWithEdges}, but this version just returns the graph. * * By default unidirectional, meaning a connection is made only from->to. Use `bidi` option to set a bidirection connection, adding also to->from. * * Returns a result of `{ graph, edges }`, where `graph` is the new {@link DirectedGraph} and `edges` * is an array of {@link Edge Edges}. One for unidirectional, or two for bidirectional. * @param graph * @param options * @returns */ declare function connect$1(graph: DirectedGraph, options: ConnectOptions$1): DirectedGraph; /** * Connect from -> to. Same as {@link connect} except you get back the edges as well. * * By default unidirectional, meaning a connection is made only from->to. Use `bidi` option to set a bidirection connection, adding also to->from. * * Returns a result of `{ graph, edges }`, where `graph` is the new {@link DirectedGraph} and `edges` * is an array of {@link Edge Edges}. One for unidirectional, or two for bidirectional. * @param graph * @param options * @returns */ declare function connectWithEdges$1(graph: DirectedGraph, options: ConnectOptions$1): { graph: DirectedGraph; edges: Edge$1[]; }; /** * Returns _true_ if a->b or b->a * @param graph * @param a * @param b * @returns */ declare function areAdjacent(graph: DirectedGraph, a: Vertex$1, b: Vertex$1): true | undefined; /** * Iterates over vertices from a starting vertex in an bread-first-search * @param graph * @param startIdOrVertex * @param targetIdOrVertex * @returns */ declare function bfs(graph: DirectedGraph, startIdOrVertex: string | Vertex$1, targetIdOrVertex?: string | Vertex$1): Generator, void, unknown>; /** * Iterates over vertices from a starting vertex in an depth-first-search * @param graph * @param startIdOrVertex */ declare function dfs(graph: DirectedGraph, startIdOrVertex: string | Vertex$1): Generator, void, unknown>; /** * Compute shortest distance from the source vertex to the rest of the graph. * @param graph * @param sourceOrId * @returns */ declare const pathDijkstra: (graph: DirectedGraph, sourceOrId: Vertex$1 | string) => { distances: Map; previous: Map | null>; pathTo: (id: string) => Edge$1[]; }; /** * Clones the graph. Uses shallow clone, because it's all immutable * @param graph * @returns */ declare const clone: (graph: DirectedGraph) => DirectedGraph; /** * Create a graph * ```js * let g = graph(); * ``` * * Can optionally provide initial connections: * ```js * let g = graph( * { from: `a`, to: `b` }, * { from: `b`, to: `c` } * ) * ``` * @param initialConnections * @returns */ declare const graph$1: (...initialConnections: ConnectOptions$1[]) => DirectedGraph; /** * Returns _true_ if the graph contains is acyclic - that is, it has no loops * @param graph */ declare function isAcyclic(graph: DirectedGraph): boolean; /** * Topological sort using Kahn's algorithm. * Returns a new graph that is sorted * @param graph */ declare function topologicalSort(graph: DirectedGraph): DirectedGraph; /** * Create a graph from an iterable of vertices * @param vertices * @returns */ declare function graphFromVertices(vertices: Iterable): DirectedGraph; /** * Get all the cycles ('strongly-connected-components') within the graph * [Read more](https://en.wikipedia.org/wiki/Strongly_connected_component) * @param graph * @returns */ declare function getCycles(graph: DirectedGraph): Vertex$1[][]; /** * Returns a new graph which is transitively reduced. * That is, redundant edges are removed * @param graph * @returns */ declare function transitiveReduction(graph: DirectedGraph): Readonly<{ vertices: IMapImmutable; }>; declare namespace undirected_graph_d_exports { export { ConnectOptions, Edge, Graph, Vertex, adjacentVertices, connect, connectTo, connectWithEdges, createVertex, dumpGraph, edgesForVertex, getConnection, getOrCreate, graph, hasConnection, toAdjacencyMatrix, updateGraphVertex }; } type Vertex = Readonly<{ id: string; }>; type Edge = Readonly<{ a: string; b: string; weight?: number; }>; type Graph = Readonly<{ edges: readonly Edge[]; vertices: IMapImmutable; }>; type ConnectOptions = Readonly<{ a: string; b: string | string[]; weight?: number; }>; declare const createVertex: (id: string) => Vertex; declare const updateGraphVertex: (graph: Graph, vertex: Vertex) => Graph; declare const getOrCreate: (graph: Graph, id: string) => Readonly<{ graph: Graph; vertex: Vertex; }>; /** * Returns _true/false_ if there is a connection between `a` and `b` in `graph`. * Use {@link getConnection} if you want to the edge. * @param graph Graph to search * @param a * @param b * @returns _true_ if edge exists */ declare const hasConnection: (graph: Graph, a: string | Vertex, b: string | Vertex) => boolean; /** * Gets the connection, if it exists between `a` and `b` in `graph`. * If it doesn't exist, _undefined_ is returned. * Use {@link hasConnection} for a simple true/false if edge exists. * @param graph Graph * @param a * @param b * @returns */ declare const getConnection: (graph: Graph, a: string | Vertex, b: string | Vertex) => Edge | undefined; /** * Connects A with B, returning the changed graph and created edge. * If the connection already exists, the original graph & edge is returned. * @param graph * @param a * @param b * @param weight * @returns */ declare function connectTo(graph: Graph, a: string, b: string, weight?: number): { graph: Graph; edge: Edge; }; /** * Makes a connection between `options.a` and one or more nodes in `options.b`. * Same as {@link connectWithEdges} but only the {@link Graph} is returned. * * ```js * let g = graph(); // Create an empty graph * // Make a connection between `red` and `orange` * g = connect(g, { a: `red`, b: `orange` }); * * // Make a connection between `red` and `orange as well as `red` and `yellow`. * g = connect(g, { a: `red`, b: [`orange`, `yellow`] }) * ``` * @param graph Initial graph * @param options Options */ declare function connect(graph: Graph, options: ConnectOptions): Graph; /** * Makes a connection between `options.a` and one or more nodes in `options.b`. * Same as {@link connect} but graph and edges are returned. * * ```js * let g = graph(); // Create an empty graph * * // Make a connection between `red` and `orange` * result = connectWithEdges(g, { a: `red`, b: `orange` }); * * // Make a connection between `red` and `orange as well as `red` and `yellow`. * result = connectWithEdges(g, { a: `red`, b: [`orange`, `yellow`] }) * ``` * @param graph Initial graph * @param options Options */ declare function connectWithEdges(graph: Graph, options: ConnectOptions): { graph: Graph; edges: Edge[]; }; declare const graph: (...initialConnections: ConnectOptions[]) => Graph; declare function toAdjacencyMatrix(graph: Graph): Table; /** * Return a string representation of the graph for debug inspection * @param graph * @returns */ declare const dumpGraph: (graph: Graph) => string; /** * Iterate over all the vertices connectd to `context` vertex * * If `context` is _undefined_, returns nothing * @param graph Graph * @param context id or Vertex * @returns */ declare function adjacentVertices(graph: Graph, context: Vertex | string | undefined): Generator, void, unknown>; /** * Get all the edges for a vertex. * * ```js * // Iterate all edges for vertex with id '0' * for (const edge of edgesForVertex(graph, '0')) { * } * ``` * * If the vertex has no edges, no values are returned. If the vertex was not found in the graph, an error is thrown. * @throws Throws an error if `context` was not found, if it's _undefined_ or `graph` is invalid. * @param graph * @param context * @returns */ declare function edgesForVertex(graph: Graph, context: Vertex | string | undefined): Generator, void, unknown>; declare namespace index_d_exports { export { directed_graph_d_exports as Directed, undirected_graph_d_exports as Undirected }; } //#endregion export { Table as i, undirected_graph_d_exports as n, directed_graph_d_exports as r, index_d_exports as t };