@thi.ng/idgen
Version:
Generator of opaque numeric identifiers with optional support for ID versioning and efficient re-use
31 lines • 1.27 kB
TypeScript
import { type Event, type IIDGen, type INotify, type Listener } from "@thi.ng/api";
import { type IDGenEventType } from "./api.js";
/**
* Simple monotonically increasing numeric ID generator. Unbounded and depending
* on numeric range covered, inprecise (e.g. for values outside the JS safe
* integer range).
*
* Unlike {@link IDGen}, this class doesn't keep track of generated IDs and the
* {@link MonotonicID.free} implementation only checks if a given ID could
* possibly already have been generated.
*/
export declare class MonotonicID implements IIDGen<number>, INotify<IDGenEventType> {
start: number;
step: number;
nextID: number;
constructor(start?: number, step?: number);
next(): number;
free(id: number): boolean;
addListener(id: IDGenEventType, fn: Listener<IDGenEventType>, scope?: any): boolean;
removeListener(id: IDGenEventType, fn: Listener<IDGenEventType>, scope?: any): boolean;
notify(event: Event<IDGenEventType>): boolean;
}
/**
* Returns a new {@link MonotonicID} instance with given `start` offset
* (default: 0) and `step` size (default: 1).
*
* @param start
* @param step
*/
export declare const monotonic: (start?: number, step?: number) => MonotonicID;
//# sourceMappingURL=monotonic.d.ts.map