porfirion / trie Goto Github PK
View Code? Open in Web Editor NEWEfficient generic radix tree (trie) implementation in go
Home Page: https://pkg.go.dev/github.com/porfirion/trie
License: MIT License
Efficient generic radix tree (trie) implementation in go
Home Page: https://pkg.go.dev/github.com/porfirion/trie
License: MIT License
Hi @porfirion
I would like to submit a PR to make this library generic-able. By turning most part of the library into generic type/function and make a alias for backward-compatibility.
For example:
// Turn Trie into TrieGen with type parameter
type TrieGen[T any] struct {
Prefix []byte
Value *T // Here we use *T, not T, for optional value
Children *[256]*TrieGen[T]
}
// Other methods on TrieGen are modified too, with input/output type T, not *T
// Provide existing interface Trie as a type alias, ValueType will be removed directly
type Trie = TrieGen[interface{}]
This interface provide easier, less error-prone interface for most types, since user don't need to 1. type assert and 2. dereference pointer.
func SomeJob() {
var routes *TrieGen[string] = BuildFromMap[string](map[string]string{
"/user/info": "some-user-info",
})
content, _, ok := routes.SearchPrefixInString("/user")
if ok {
fmt.Println(content)
}
}
However, the Trie.Value
now has incompatible type chage, from interface{}
to *interface{}
.
Since Value
is a public field for Trie
, there may be some existing user who interact with the trie content,
not using public methods from the trie. For these users, the proposed change can broken their code when they upgrade this library.
Do you think this is a good change for this library? If so, I would like to submit a PR for this change. :D
(Actually I already complete the required modification and fix corresponding test cases in my local repo.)
Hope for your kind response.
And thanks for this great library, I learned a lot from it. :D
If we do not care about compatibility, we can just provide:
type Trie[T any] struct {
Prefix []byte
Value *T
Children *[256]*Trie[T]
}
There is already a fork doing similar change, but the public method of that fork return values in *T
, which I don't think a good design decision.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.