/** * Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal * @author Alexander Rose */ import { SortedArray } from '../../mol-data/int.js'; import { AssignableArrayLike } from '../../mol-util/type-helpers.js'; /** * Represent a graph using vertex adjacency list. * * Edges of the i-th vertex are stored in the arrays a and b * for indices in the range [offset[i], offset[i+1]). * * Edge properties are indexed same as in the arrays a and b. */ export interface IntAdjacencyGraph { readonly offset: ArrayLike; readonly a: ArrayLike; readonly b: ArrayLike; readonly vertexCount: number; readonly edgeCount: number; readonly edgeProps: Readonly; readonly props?: Props; /** * Get the edge index between i-th and j-th vertex. * -1 if the edge does not exist. * * Because the a and b arrays contains each edge twice, * this always returns the smaller of the indices. * * `getEdgeIndex(i, j) === getEdgeIndex(j, i)` */ getEdgeIndex(i: VertexIndex, j: VertexIndex): number; /** * Get the edge index between i-th and j-th vertex. * -1 if the edge does not exist. * * `getEdgeIndex(i, j) !== getEdgeIndex(j, i)` */ getDirectedEdgeIndex(i: VertexIndex, j: VertexIndex): number; getVertexEdgeCount(i: VertexIndex): number; } export declare namespace IntAdjacencyGraph { type EdgePropsBase = { [name: string]: ArrayLike; }; function areEqual(a: IntAdjacencyGraph, b: IntAdjacencyGraph): boolean; function create(offset: ArrayLike, a: ArrayLike, b: ArrayLike, edgeCount: number, edgeProps?: EdgeProps, props?: Props): IntAdjacencyGraph; class EdgeBuilder { vertexCount: number; xs: ArrayLike; ys: ArrayLike; private bucketFill; private current; private curA; private curB; offsets: Int32Array; edgeCount: number; /** the size of the A and B arrays */ slotCount: number; a: AssignableArrayLike; b: AssignableArrayLike; createGraph(edgeProps: EdgeProps, props?: Props): IntAdjacencyGraph; /** * @example * const property = new Int32Array(builder.slotCount); * for (let i = 0; i < builder.edgeCount; i++) { * builder.addNextEdge(); * builder.assignProperty(property, srcProp[i]); * } * return builder.createGraph({ property }); */ addNextEdge(): void; /** Builds property-less graph */ addAllEdges(): void; assignProperty(prop: { [i: number]: T; }, value: T): void; assignDirectedProperty(propA: { [i: number]: T; }, valueA: T, propB: { [i: number]: T; }, valueB: T): void; constructor(vertexCount: number, xs: ArrayLike, ys: ArrayLike); } class DirectedEdgeBuilder { vertexCount: number; xs: ArrayLike; ys: ArrayLike; private bucketFill; private current; private curA; offsets: Int32Array; edgeCount: number; /** the size of the A and B arrays */ slotCount: number; a: AssignableArrayLike; b: AssignableArrayLike; createGraph(edgeProps: EdgeProps, props?: Props): IntAdjacencyGraph; /** * @example * const property = new Int32Array(builder.slotCount); * for (let i = 0; i < builder.edgeCount; i++) { * builder.addNextEdge(); * builder.assignProperty(property, srcProp[i]); * } * return builder.createGraph({ property }); */ addNextEdge(): void; /** Builds property-less graph */ addAllEdges(): void; assignProperty(prop: { [i: number]: T; }, value: T): void; constructor(vertexCount: number, xs: ArrayLike, ys: ArrayLike); } class UniqueEdgeBuilder { vertexCount: number; private xs; private ys; private included; addEdge(i: VertexIndex, j: VertexIndex): boolean; getGraph(): IntAdjacencyGraph; getEdgeBuiler(): EdgeBuilder; constructor(vertexCount: number); } function fromVertexPairs(vertexCount: number, xs: VertexIndex[], ys: VertexIndex[]): IntAdjacencyGraph; function induceByVertices(graph: IntAdjacencyGraph, vertexIndices: ArrayLike, props?: Props): IntAdjacencyGraph; function connectedComponents(graph: IntAdjacencyGraph): { componentCount: number; componentIndex: Int32Array; }; /** * Check if any vertex in `verticesA` is connected to any vertex in `verticesB` * via at most `maxDistance` edges. * * Returns true if verticesA and verticesB are intersecting. */ function areVertexSetsConnected(graph: IntAdjacencyGraph, verticesA: SortedArray, verticesB: SortedArray, maxDistance: number): boolean; }