RingDict, a map over a ring

Hi everyone,
First time I write here! I had this utility library in mind since long. I already tried to do something like this some time ago, without success. Today, something finally clicked and this came to light:

https://git.sr.ht/~blallo/go-ringdict

ringdict

It’s a small library that exposes two data structures, *RDict and its corresponding goroutine-safe *SafeRDict. These are map-like data structures (that have Get(), Set() and Del()) over a container/ring (peek into the code if you are curious of the implementation). So basically, you can fill in as many key-value pairs you want. When the capacity is reached, the new pairs overwrite the oldest ones.

I did it because:

  • more than once I have wanted a map with limited size (or at least limited slots)
  • I wasn’t able to find anything that fit the above.

Any comment is more than welcome.

P.S.: The default interface branch holds the code for go<=1.17. I also did a parallel implementation with generics for go>=1.18 in the generics branch.