@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.
Follow

@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

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!