
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.