Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
github.com/viant/ptrie
This library is compatible with Go 1.11+
Please refer to CHANGELOG.md
if you encounter breaking changes.
The goal of this project is to provide serverless prefix tree friendly implementation. where one function can easily building tree and publishing to some cloud storge. Then the second load trie to perform various operations.
A trie (prefix tree) is a space-optimized tree data structure in which each node that is merged with its parent. Unlike regular trees (where whole keys are from their beginning up to the point of inequality), the key at each node is compared chunk by chunk,
Prefix tree has the following application:
text document searching
rule based matching
constructing associative arrays for string keys
Character comparision complexity:
Where
trie := ptrie.New()
for key, value := range pairs {
if err = trie.Put(key, value); err != nil {
log.Fatal(err)
}
}
//...
has := trie.Has(key)
value, has := trie.Get(key)
//...
matched := trie.MatchAll(input, func(key []byte, value interface{}) bool {
fmt.Printf("matched: key: %s, value %v\n", key, value)
return true
})
trie := ptrie.New()
for key, value := range pairs {
if err = trie.Put(key, value); err != nil {
log.Fatal(err)
}
}
writer := new(bytes.Buffer)
if err := trie.Encode(writer); err != nil {
log.Fatal(err)
}
encoded := write.Bytes()
//write encode data
//V type can be any type
var v *V
trie := ptrie.New()
trie.UseType(reflect.TypeOf(v))
if err := trie.Decode(reader); err != nil {
log.Fatal(err)
}
trie.Walk(func(key []byte, value interface{}) bool {
fmt.Printf("key: %s, value %v\n", key, value)
return true
})
has := trie.Has(key)
value, has := trie.Get(key)
var input []byte
...
matched := trie.MatchPrefix(input, func(key []byte, value interface{}) bool {
fmt.Printf("matched: key: %s, value %v\n", key, value)
return true
})
var input []byte
...
matched := trie.MatchAll(input, func(key []byte, value interface{}) bool {
fmt.Printf("matched: key: %s, value %v\n", key, value)
return true
})
The benchmark count all words that are part of the following extracts:
Benchmark_LoremBruteForceShort-8 500000 3646 ns/op
Benchmark_LoremTrieShort-8 500000 2376 ns/op
Benchmark_LoremBruteForceLong-8 1000 1612877 ns/op
Benchmark_LoremTrieLong-8 10000 119990 ns/op
Benchmark_HamletBruteForceShort-8 30000 44306 ns/op
Benchmark_HamletTrieShort-8 100000 18530 ns/op
Benchmark_HamletBruteForceLong-8 10000 226836 ns/op
Benchmark_HamletTrieLong-8 50000 39329 ns/op
The source code is made available under the terms of the Apache License, Version 2, as stated in the file LICENSE
.
Individual files may be made available under their own specific license, all compatible with Apache License, Version 2. Please see individual files for details.
Library Author: Adrian Witas
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
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.