UNPKG

@thi.ng/adjacency

Version:

Sparse & bitwise adjacency matrices, lists and selected traversal algorithms for directed & undirected graphs

46 lines 1.89 kB
import { BitMatrix } from "@thi.ng/bitfield/bitmatrix"; import type { DegreeType, Edge, IGraph } from "./api.js"; /** * Adjacency matrix representation for both directed and undirected graphs and * using a compact bit matrix to store edges. Each edge requires only 1 bit * in directed graphs or 2 bits in undirected graphs. E.g. this is allows * storing 16384 directed edges in just 2KB of memory (128 * 128 / 8 = 2048). */ export declare class AdjacencyBitMatrix implements IGraph<number> { mat: BitMatrix; protected undirected: boolean; protected numE: number; constructor(n: number, edges?: Iterable<Edge>, undirected?: boolean); edges(): Generator<Edge, void, unknown>; numEdges(): number; numVertices(): number; /** * Resizes matrix to new size given. * * @param n - new max vertices */ resize(n: number): this; addEdge(from: number, to: number): boolean; removeEdge(from: number, to: number): boolean; hasEdge(from: number, to: number): boolean; hasVertex(id: number): boolean; degree(id: number, type?: DegreeType): number; neighbors(id: number): number[]; similarity(id: number, threshold?: number): number[][]; invert(): AdjacencyBitMatrix; toString(): string; toDot(ids?: string[]): string; } /** * Creates adjacency matrix backed by a * [`BitMatrix`](https://docs.thi.ng/umbrella/bitfield/classes/BitMatrix.html) * with capacity `n` (max vertices), optionally initialized with given edge * pairs. Each edge is `[src-node dest-node]`. If `undirected` is true (default: * false), creates symmetrical adjacencies. * * @param n - max vertices * @param edges - edge pairs * @param undirected -true, if undirected */ export declare const defAdjBitMatrix: (n: number, edges?: Iterable<Edge>, undirected?: boolean) => AdjacencyBitMatrix; //# sourceMappingURL=binary.d.ts.map