UNPKG

node-darts

Version:

Node.js Native Addon for Darts (Double-ARray Trie System)

67 lines (66 loc) 2.14 kB
import { DartsNative, TraverseCallback } from './types'; /** * Wrapper class for native module * Adds error handling and provides a TypeScript-friendly interface */ export declare class DartsNativeWrapper implements DartsNative { /** * Creates a dictionary object * @returns dictionary handle */ createDictionary(): number; /** * Destroys a dictionary object * @param handle dictionary handle */ destroyDictionary(handle: number): void; /** * Loads a dictionary file * @param handle dictionary handle * @param filePath path to the dictionary file * @returns true if successful, false otherwise */ loadDictionary(handle: number, filePath: string): boolean; /** * Saves a dictionary file * @param handle dictionary handle * @param filePath destination file path * @returns true if successful, false otherwise */ saveDictionary(handle: number, filePath: string): boolean; /** * Performs an exact match search * @param handle dictionary handle * @param key search key * @returns the corresponding value if found, -1 otherwise */ exactMatchSearch(handle: number, key: string): number; /** * Performs a common prefix search * @param handle dictionary handle * @param key search key * @returns array of found values */ commonPrefixSearch(handle: number, key: string): number[]; /** * Traverses the trie * @param handle dictionary handle * @param key search key * @param callback callback function */ traverse(handle: number, key: string, callback: TraverseCallback): void; /** * Builds a Double-Array * @param keys array of keys * @param values array of values (indices are used if omitted) * @returns dictionary handle */ build(keys: string[], values?: number[]): number; /** * Gets the size of the dictionary * @param handle dictionary handle * @returns size of the dictionary */ size(handle: number): number; } export declare const dartsNative: DartsNativeWrapper;