@carlozancanaro You put an element into it, after a certain amount of time it will be removed, unless fetched, updated or "poked".

@shadowfacts @carlozancanaro I suppose so, the main thing I would need to use it for would be to make things purge themselves after a delay. So it would require a specific interface and callbacks for when the objects are purged. Plus some sort of iteration thing for expired tasks on the ticks.

@gudenau @carlozancanaro Callback is easy, just require that V extend some interface w/ a method that's called on expiry.

You could also keep a Set<V> expired; that's cleared every time step.

To purge expired objects automatically, you'd just have a method that iterates all objects and expires them if necessary, called every time step from a run loop or a worker thread.

@shadowfacts @carlozancanaro Yeah, I was thinking about this wrong. A LinkedList backed thing would probably be best for this, since it would be quick to iterate and once you run out of expired things you know you can stop.

@gudenau @carlozancanaro If you don't need to look things up by keys, yeah that'd work well. Just need to insert new and refreshed objects at the head.

@shadowfacts @gudenau If it's doubly-linked then I don't think it matters which end you insert.

If it's singly linked then you should insert at the tail so you can invalidate items by starting at the head and going forwards until you hit a valid one.

Although if you don't need to do any special processing to invalidate individual entries then you should insert at the head and just drop the entire tail when you read the first invalid item.

@carlozancanaro @shadowfacts You would still need to iterate over all the dropped items to notify them that they where dropped.


@carlozancanaro @shadowfacts Would be a per-use case thing if you did not need to do processing. Might be an interesting paper.

@gudenau @shadowfacts I don't think this is paper worthy. This is pretty basic data structure stuff.

@carlozancanaro @shadowfacts I meant the "drop the head or drop the tale", not a long one mind.

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either! We adhere to an adapted version of the TootCat Code of Conduct and follow the Toot Café list of blocked instances. Ash is the admin and is supported by Fuzzface, Brian!, and Daniel Glus as moderators. Hosting costs are largely covered by our generous supporters on Patreon – thanks for all the help!