@electric-sql/d2mini
Version:
D2Mini is a minimal implementation of Differential Dataflow for performing in-memory incremental view maintenance.
41 lines (40 loc) • 1.4 kB
TypeScript
/**
* A map that returns a default value for keys that are not present.
*/
export declare class DefaultMap<K, V> extends Map<K, V> {
private defaultValue;
constructor(defaultValue: () => V, entries?: Iterable<[K, V]>);
get(key: K): V;
/**
* Update the value for a key using a function.
*/
update(key: K, updater: (value: V) => V): V;
}
export declare function chunkedArrayPush(array: unknown[], other: unknown[]): void;
/**
* A hash method that caches the hash of a value in a week map
*/
export declare function hash(data: any): string;
export declare function binarySearch<T>(array: T[], value: T, comparator: (a: T, b: T) => number): number;
/**
* Utility for generating unique IDs for objects and values.
* Uses WeakMap for object reference tracking and consistent hashing for primitives.
*/
export declare class ObjectIdGenerator {
private objectIds;
private nextId;
/**
* Get a unique identifier for any value.
* - Objects: Uses WeakMap for reference-based identity
* - Primitives: Uses consistent string-based hashing
*/
getId(value: any): number;
/**
* Get a string representation of the ID for use in composite keys.
*/
getStringId(value: any): string;
}
/**
* Global instance for cases where a shared object ID space is needed.
*/
export declare const globalObjectIdGenerator: ObjectIdGenerator;