![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@thi.ng/trie
Advanced tools
[!NOTE] This is one of 199 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.
🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️
Trie-based map data structure with prefix search/query support.
This package contains functionality which was previously part of and has been extracted from the @thi.ng/associative package.
Tries (also called Prefix maps) are useful data structures for search based use cases, auto-complete, text indexing etc. and provide partial key matching (prefixes), suffix iteration for a common prefix, longest matching prefix queries etc.
The implementations here too feature ES6 Map-like API, similar to other types in this package, with some further trie-specific additions.
import { defTrieMap } from "@thi.ng/associative";
const trie = defTrieMap([
["hey", "en"],
["hello", "en"],
["hallo", "de"],
["hallo", "de-at"],
["hola", "es"],
["hold", "en"],
["hej", "se"],
]);
trie.knownPrefix("hole")
// "hol"
[...trie.suffixes("he")]
// [ "j", "llo", "y" ]
// w/ prefix included
[...trie.suffixes("he", true)]
// [ "hej", "hello", "hey" ]
The MultiTrie
is similar to TrieMap
, but supports array-like keys and
multiple values per key. Values are stored in sets whose implementation can be
configured via ctor options.
import { defMultiTrie } from "@thi.ng/associative";
// init w/ custom value set type (here only for illustration)
const t = defMultiTrie<string[], string>(null, { vals: () => new ArraySet() });
t.add("to be or not to be".split(" "), 1);
t.add("to be or not to be".split(" "), 2);
t.add("to be and to live".split(" "), 3);
t.get("to be or not to be".split(" "))
// Set(2) { 1, 2 }
t.knownPrefix(["to", "be", "not"]);
// [ "to", "be" ]
// auto-complete w/ custom separator between words
[...t.suffixes(["to", "be"], false, "/")]
// [ "and/to/live", "or/not/to/be" ]
STABLE - used in production
Search or submit any issues for this package
yarn add @thi.ng/trie
ESM import:
import * as trie from "@thi.ng/trie";
Browser ESM import:
<script type="module" src="https://esm.run/@thi.ng/trie"></script>
For Node.js REPL:
const trie = await import("@thi.ng/trie");
Package sizes (brotli'd, pre-treeshake): ESM: 1.01 KB
Note: @thi.ng/api is in most cases a type-only import (not used at runtime)
If this project contributes to an academic publication, please cite it as:
@misc{thing-trie,
title = "@thi.ng/trie",
author = "Karsten Schmidt",
note = "https://thi.ng/trie",
year = 2020
}
© 2020 - 2024 Karsten Schmidt // Apache License 2.0
FAQs
Trie-based map data structure with prefix search/query support
The npm package @thi.ng/trie receives a total of 13 weekly downloads. As such, @thi.ng/trie popularity was classified as not popular.
We found that @thi.ng/trie demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.