UNPKG

@graphty/algorithms

Version:

Graph algorithms library for browser environments implemented in TypeScript

143 lines 3.15 kB
/** * Wrapper around TypedFastBitSet with graph-specific optimizations * * Provides efficient bit-packed set operations optimized for graph algorithms * with 8x memory reduction compared to standard JavaScript Set for boolean values. */ export declare class GraphBitSet { private bitset; private _cardinality; constructor(capacity?: number); /** * Add a single element */ add(index: number): void; /** * Remove a single element */ remove(index: number): void; /** * Check if element exists */ has(index: number): boolean; /** * Clear all elements */ clear(): void; /** * Check if empty */ isEmpty(): boolean; /** * Optimized for graph algorithms - add range of indices */ addRange(start: number, end: number): void; /** * Fast cardinality tracking */ size(): number; /** * Batch operations for frontier management - swap contents */ swap(other: GraphBitSet): void; /** * Efficient iteration */ [Symbol.iterator](): Generator<number>; /** * Set operations with cardinality tracking */ union(other: GraphBitSet): void; intersection(other: GraphBitSet): void; difference(other: GraphBitSet): void; /** * Clone the bitset */ clone(): GraphBitSet; } /** * Specialized bit array for visited tracking * * More memory efficient than GraphBitSet for simple boolean arrays * that don't need set operations. */ export declare class VisitedBitArray { private words; private wordCount; private _size; constructor(size: number); /** * Set bit at index */ set(index: number): void; /** * Get bit at index */ get(index: number): boolean; /** * Clear all bits */ clear(): void; /** * Toggle bit at index */ toggle(index: number): void; /** * Population count for statistics */ popcount(): number; /** * Efficient population count for a single word * Uses bit manipulation tricks for fast counting */ private popcountWord; /** * Get size of the bit array */ size(): number; /** * Check if all bits are zero */ isEmpty(): boolean; /** * Set multiple bits from array */ setMultiple(indices: number[]): void; /** * Get indices of all set bits */ getSetIndices(): number[]; } /** * Bit-packed distance array for BFS * * Optimized for storing distances using 16-bit integers (up to 65,535 levels) * Still provides 2x memory savings compared to standard 32-bit numbers */ export declare class CompactDistanceArray { private data; private _size; private static readonly INFINITY; constructor(size: number); /** * Set distance at index */ set(index: number, distance: number): void; /** * Get distance at index */ get(index: number): number; /** * Check if node has been visited */ isVisited(index: number): boolean; /** * Reset all distances */ clear(): void; /** * Get size */ size(): number; } //# sourceMappingURL=bit-packed.d.ts.map