UNPKG

ton3-core

Version:
65 lines (64 loc) 3.01 kB
import type { Bit } from '../types/bit'; import type { Slice } from './slice'; import type { Cell } from './cell'; export interface HashmapOptions<K, V> { keySize?: number | 'auto'; prefixed?: boolean | 'auto'; nonEmpty?: boolean; serializers?: { key: (key: K) => Bit[]; value: (value: V) => Cell; }; deserializers?: { key: (key: Bit[]) => K; value: (value: Cell) => V; }; } declare type HashmapNode = [key: Bit[], value: Cell]; declare class Hashmap<K = Bit[], V = Cell> { protected hashmap: Map<string, Cell>; protected keySize: number; protected serializeKey: (key: K) => Bit[]; protected serializeValue: (value: V) => Cell; protected deserializeKey: (key: Bit[]) => K; protected deserializeValue: (value: Cell) => V; constructor(keySize: number, options?: HashmapOptions<K, V>); [Symbol.iterator](): IterableIterator<[K, V]>; get(key: K): V; has(key: K): boolean; set(key: K, value: V): this; add(key: K, value: V): this; replace(key: K, value: V): this; getSet(key: K, value: V): V; getAdd(key: K, value: V): V; getReplace(key: K, value: V): V; delete(key: K): this; isEmpty(): boolean; forEach(callbackfn: (key: K, value: V) => void): void; protected getRaw(key: Bit[]): Cell; protected setRaw(key: Bit[], value: Cell): this; protected sortHashmap(): HashmapNode[]; protected serialize(): Cell; protected static serializeEdge(nodes: HashmapNode[]): Cell; protected static serializeFork(nodes: HashmapNode[]): [HashmapNode[], HashmapNode[]]; protected static serializeLeaf(node: HashmapNode): Cell; protected static serializeLabel(nodes: HashmapNode[]): Bit[]; protected static serializeLabelShort(bits: Bit[]): Bit[]; protected static serializeLabelLong(bits: Bit[], m: number): Bit[]; protected static serializeLabelSame(bits: Bit[], m: number): Bit[]; protected static deserialize<K, V>(keySize: number, slice: Slice, options?: HashmapOptions<K, V>): Hashmap<K, V>; protected static deserializeEdge(edge: Slice, keySize: number, key?: Bit[]): HashmapNode[]; protected static deserializeLabel(edge: Slice, m: number): Bit[]; protected static deserializeLabelShort(edge: Slice): Bit[]; protected static deserializeLabelLong(edge: Slice, m: number): Bit[]; protected static deserializeLabelSame(edge: Slice, m: number): Bit[]; cell(): Cell; static parse<K = Bit[], V = Cell>(keySize: number, slice: Slice, options?: HashmapOptions<K, V>): Hashmap<K, V>; } declare class HashmapE<K = Bit[], V = Cell> extends Hashmap<K, V> { constructor(keySize: number, options?: HashmapOptions<K, V>); protected serialize(): Cell; protected static deserialize<K, V>(keySize: number, slice: Slice, options?: HashmapOptions<K, V>): HashmapE<K, V>; static parse<K = Bit[], V = Cell>(keySize: number, slice: Slice, options?: HashmapOptions<K, V>): HashmapE<K, V>; } export { HashmapE, Hashmap };