On Wed, 19 Jul 2017 19:32:32 -0000 Jan Mercl <0xj...@gmail.com> wrote: > > On Wed, Jul 19, 2017 at 9:22 PM Rajanikanth Jammalamadaka < > rajanika...@gmail.com> wrote: > > > Does somebody have a recommendation for an expiring dict? If I have to > > write my own, is there a way to avoid iterating over all the keys to delete > > the expired entries? > > Common approach is to tag the entries with insertion or expiration time and > remove invalid items only on retrieval. If there are not enough retrievals > that keep the ratio of useful/expired map entries sane, a "cleaner" > goroutine can be run concurrently.
Somewhat analogous to garbage collection via reference counting (paying incremental cost) and occasional mark-and-sweep (for things not caught by RC). To avoid iterating over keys, on creation you can store key+expiration time in a separate scheduling data structure (which can be a ring buffer if all entries have the same life time) but this will usually be less efficient and more complicated. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.