Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 3.09 KB

README.md

File metadata and controls

44 lines (35 loc) · 3.09 KB

Trie data structures for JavaScript. See docs.

⚠️ Depending on your environment, the code may require regeneratorRuntime to be defined, for instance by importing regenerator-runtime/runtime.

import {Trie, ArrayNode} from '@trie-data-structure/uncompressed-trie';
import {range} from '@iterable-iterator/range';
import {map} from '@iterable-iterator/map';

const encode = (key) => map((i) => key.charCodeAt(i), range(key.length));
const degree = 256;
const trie = new Trie(new ArrayNode(degree));

const set = (key, value) => trie.set(encode(key), value);
const get = (key) => trie.get(encode(key));

set('abra', 1);
set('cadabra', 2);
set('abracadabra', 3);

get('abra'); // 1
get('cadabra'); // 2
get('abracadabra'); // 3

License Version Tests Dependencies GitHub issues Downloads

Code issues Code maintainability Code coverage (cov) Code technical debt Documentation Package size