@jawis/shared-algs
Version:
Data structures for building concurrent programs.
145 lines (144 loc) • 2.96 kB
TypeScript
import { DoublyLinkedListProv, HeapFactory, DataNode, Allocation } from "./internal";
export type SharedDoublyLinkedListDeps<N extends {
ref: number;
}> = {
ref?: number;
heapFactory: HeapFactory;
dataSize: number;
makeNode: (node: DataNode) => N;
verifyAfterOperations: boolean;
};
/**
*
* invariant
* - The node is allocated iff the node is in the list.
*
* impl
* - Data is on the same page as the header data
*
* header/meta data
* 4 bytes count
* 4 bytes headRef
*
* page layout
* x bytes data
* 4 bytes ref to prev node
* 4 bytes ref to next node
*
*/
export declare class SharedDoublyLinkedList<N extends {
ref: number;
}> implements DoublyLinkedListProv<N> {
deps: SharedDoublyLinkedListDeps<N>;
private PREVIOUS_OFFSET;
private NEXT_OFFSET;
private DATA_BYTE_OFFSET;
static HEADER_BYTES: number;
private pageSize;
private heap;
private nodeMap;
private decl;
/**
*
*/
constructor(deps: SharedDoublyLinkedListDeps<N>);
/**
*
*/
static getDataAvailable: (pageSize: number) => number;
/**
*
*/
pack: () => Omit<SharedDoublyLinkedListDeps<N>, "heapFactory" | "makeNode" | "verifyAfterOperations">;
/**
*
*/
get count(): number;
/**
*
*/
get headRef(): number;
/**
*
*/
set headRef(ref: number);
/**
*
*/
getHead: () => N | undefined;
/**
*
*/
get: (ref: number) => N;
/**
*
*/
prevRef: (node: N) => number | undefined;
/**
*
*/
nextRef: (node: N) => number | undefined;
/**
*
*/
appendNew: () => N;
/**
* Creates a new node after the given node.
*/
insertNew: (_pos: N) => N;
/**
*
*/
move: (_node: N, _pos: N, before?: boolean) => void;
/**
*
* - Also deallocates the node.
* - It's not allowed to delete twice.
*
* impl
* - Make user's object as "deleted", so we can emit warning if the user tries to do further
* operations the the object.
*
*/
delete: (_node: N) => void;
/**
* - Set root node correctly if needed.
*/
private _insert;
/**
* Remove the node from the list without deallocating the node.
*
* impl
* - Sets root node correctly if needed.
*/
private _delete_from_list;
/**
* Allocate a new node, but not attached to the list, yet.
*/
_allocate: () => Allocation<Uint32Array>;
/**
*
*/
private makeNode;
/**
*
*/
private mapToInternal;
/**
* todo: it's this implicitly calls: `this.makeNode`
*/
private _invariant;
/**
*
*/
[Symbol.iterator](): Generator<N>;
/**
*
*/
dispose: () => void;
/**
*
* - Excludes ref, because it's not important
*/
toString: () => string;
}