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

Generic key type #82

Open
dnaka91 opened this issue May 1, 2023 · 2 comments
Open

Generic key type #82

dnaka91 opened this issue May 1, 2023 · 2 comments

Comments

@dnaka91
Copy link

dnaka91 commented May 1, 2023

I was wondering why the value was made generic with the introduction of Go generics, but the key not. A quick check in the code revealed that there are some parts of the API that rely on a string as key, but overall it seems possible to support other types.

The motivation behind this is, that we try to avoid unneeded GC overhead at work, and often we have an integer as key. By making the key generic, we could avoid the extra conversion to a string just to be able to lookup values in the cache.

@karlseguin
Copy link
Owner

Never came up. The value change is pretty straightforward.

I think the biggest issue with the key is the bucketing and getting a hash key out of any value. Off the top of my head, don't know how to do that without requiring a hash function (or the key type to implement a HashCode function).

Some advanced functionality wouldn't work, like DeletePrefix - but I think it would be fine to fail in those cases.

@dnaka91
Copy link
Author

dnaka91 commented May 1, 2023

Great to hear (I mean, you seem very open to introducing this).

But true, there's probably no easy way of supporting the hashing logic, other than defining a new interface that all key types would need to implement.

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

No branches or pull requests

2 participants