Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
search-trie
Advanced tools
A simple trie structure to perform prefix search on texts in O(n) time, where n - number of characters in searched word. > Trie is a basic Tree structure, also known as [prefix tree](https://en.wikipedia.org/wiki/Trie) Super simple, Super fast, super comp
Weekly downloads
Readme
A simple trie structure to perform prefix search on texts in O(n) time, where n - number of characters in searched word.
Trie is a basic Tree structure, also known as prefix tree Super simple, Super fast, super compact - less then 0.5kb.
The single purpose of this package is to find longest match between given strings and the search key. For example:
/src
, /src/a
, /src/b
, /src/b/c
)/src/b/c/index.tx
-> /src/b/c
)This package provides two functions to build two different tries:
buildCharacterTrie
- to create "per character" trie. Working great if you need to search something in the compressed json (short names)buildWordTrie
- to create trie where "word" is a key. Working great if there are many "long keys", for example directories you want to traverse fasterone has more smaller nodes, another one has fewer larger ones. It's all about memory locality and algorithm сonvergence.
They have almost identical API, and if performance matters - you need to benchmark your data to understand which one is more efficient
import {buildWordTrie} from 'search-trie';
// map package info into trie
// using word trie as we operate with directory names
const trie = buildWordTrie(
packages.map(pkg => ({key: pkg.dir.split(path.sep), value: pkg})
);
// it's always possible to insert new data. But `delete` operation is not defined
trie.put({key:'another/package', value: pkg})
// find longest (nearest to the search key) package. It will be a package containing this file
const getOwnerPackage = (fileName) => trie.findNearest(fileName).value;
buildCharacterTrie
to understand factual usage of an object.buildWordTrie
to trim long imports to the nearest allowedbuildWordTrie
to remove nested directories, ie creating trie containing shortest versionsMIT
FAQs
A simple trie structure to perform prefix search on texts in O(n) time, where n - number of characters in searched word. > Trie is a basic Tree structure, also known as [prefix tree](https://en.wikipedia.org/wiki/Trie) Super simple, Super fast, super comp
The npm package search-trie receives a total of 2,441 weekly downloads. As such, search-trie popularity was classified as popular.
We found that search-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
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.