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

Support a TtlCacheSet #6

Open
mathstuf opened this issue Oct 25, 2017 · 5 comments
Open

Support a TtlCacheSet #6

mathstuf opened this issue Oct 25, 2017 · 5 comments

Comments

@mathstuf
Copy link
Contributor

Sometimes just existence is necessary, so a TtlCacheSet would be a nice addition.

@leoschwarz
Copy link

You can just set the value to ().

type TtlCacheSet<K> = TtlCache<K, ()>

Maybe this could be a pub type in this crate though since it's common functionality.

@mathstuf
Copy link
Contributor Author

Well, there are some additional methods that may make sense on TtlCacheSet that (might?) not make as much on TtlCacheMap: intersection, union, etc.

@leoschwarz
Copy link

I see two ways how this could be done:

  • Implement a new struct, wrapping TtlCache<K, ()> and implementing all relevant methods.
  • Or actually implement set operations on the TtlCache and document that when there is a duplicate value for a key, the value from the one on the left hand (or "self" or whatever it ends up being in the api) side is going to be used.

One advantage of the first one is that it's cleaner. Users don't have to bother inserting tuples with an empty tuple as the value like they would have if using TtlCache like I suggested before.

Main question obviously being if you really need set operations on this struct in the first place?

@mathstuf
Copy link
Contributor Author

Well, my need is less now (I actually needed to store a bool, not a singleton), but the request could still make sense for someone else.

@stusmall
Copy link
Owner

stusmall commented Apr 7, 2018

Next time I get a chance to sit down with the library I will implement TtlSet as TtlCache as @leoschwarz suggested. This is the same way HashSet in the StdLib is implemented

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

3 participants