
Security News
New CNA Scorecard Tool Ranks CVE Data Quality Across the Ecosystem
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
github.com/EddisonKing/autocomplete
A simple implementation of a prefix based auto-completer that is thread safe using a trie data structure.
go get github.com/EddisonKing/autocomplete
import "github.com/EddisonKing/autocomplete"
ac := autocomplete.New()
This will create a new AutoComplete
that you can then load string
entries into for later use in auto-completion.
// Single string
ac.Load("apples")
// Or multiple
ac.Load([]string{"apples", "bananas", "ewwwww_fruit"}...)
This will load entries into the AutoComplete
allowing them to be returned as entries during auto-completion.
Duplicate values will not change the underlying state, but the algorithm can't know an entry is a duplicate without walking the trie, so effectively, you will be wasting compute on duplicates.
results := ac.Complete("a") // Would return []string{"apples"} if the above Load data was used
Call Complete
and pass in a prefix string to get a slice containing entries that satisfy the auto-completion.
Calling Complete
with an empty prefix, ""
, will return all entries that were stored. Note that this requires a traversal of the full trie so the effort to return all entries is the same effort as what it took to store all the entries originally.
chan string
insteadThe underlying data structure is known as a "trie" which is a portion of the word "retrieval", the reason why the structure was initially designed.
Loading entries into the tree requires a traversal of the tree at a depth of however long the input is. Consider the performance is likely:
O(k) where `k` is the length of the input
Complete takes a traversal of the prefix, then a full traversal of the remainder of the trie past the prefix. Likely:
O(p + c) where `p` is the length of the prefix and `c` is how many entries there remaining in that sub-trie
A trie is fairly space efficient since overlapping words in the data (ex. "apple" and "app") are also stored utilising this overlap.
FAQs
Unknown package
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
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.