-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add generics into binary fuse #39
Conversation
// the caller should avoid having too many duplicated keys. | ||
// The function may return an error if the set is empty. | ||
func PopulateBinaryFuse8(keys []uint64) (*BinaryFuse8, error) { | ||
func NewBinaryFuse[T Unsigned](keys []uint64) (*BinaryFuse[T], error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be hide generic interface and expose only PopulateBinaryFuse8(), PopulateBinaryFuse16(), PopulateBinaryFuse32()
publicly to keep API consistent with what we already have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was a trick with configurable types
type MyFuse uint32
...
func main() {
filter := xorfilter.NewBinaryFuse[MyFuse](keys)
second(filter)
}
func second(filter *xorfilter.BinaryFuse[MyFuse]) {
...
}
to change only one line when trying to find best binary fuse for use case. Deprecating PopulateBinaryFuse8
.
To be honest I'm tired of switch value := value.(type)
usage in established projects. Generics allow to avoid "default" cases as they mostly error, simplify to compiler error.
@tnako This is good and I will merge, but please see my comment which requires a fix. |
It has been released. |
We upgraded our minimum Go version in PR #39, so we can use the `math/rand/v2` package too. Reference: https://go.dev/blog/randv2 Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This allow to use uin8, uint16 and uint32 base with binary fuse.
Should be backward compatible with current BinaryFuse8 struct. Only not sure about best go version inside go.mod
What about changing Readme to use new style? Like