Skip to content
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

Merged
merged 3 commits into from
Sep 11, 2024

Conversation

tnako
Copy link
Contributor

@tnako tnako commented Sep 10, 2024

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

filter, err := xorfilter.NewBinaryFuse[uint16](keys)

// 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) {

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.

Copy link
Contributor Author

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.

binaryfusefilter_test.go Outdated Show resolved Hide resolved
@lemire
Copy link
Member

lemire commented Sep 10, 2024

@tnako This is good and I will merge, but please see my comment which requires a fix.

@lemire lemire merged commit 8725f24 into FastFilter:master Sep 11, 2024
4 checks passed
@lemire
Copy link
Member

lemire commented Sep 11, 2024

It has been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants