Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/i-redbyte/ring-map
The simplest ring map
https://github.com/i-redbyte/ring-map
Last synced: 20 days ago
JSON representation
The simplest ring map
- Host: GitHub
- URL: https://github.com/i-redbyte/ring-map
- Owner: i-redbyte
- Created: 2020-03-19T22:50:51.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-26T21:55:15.000Z (over 2 years ago)
- Last Synced: 2024-10-16T06:35:28.431Z (2 months ago)
- Language: Go
- Size: 8.79 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**An example of a solution to a problem:**
```go
package mainimport (
"fmt"
)// Vault structure stores limited number of key-value elements.
// It stores most recently addressed elements, so if it already stores maximum elements allowed,
// when we add next one, it should delete least recently used one (either by Get or Put).
// type Vault struct {
// ...
// }func main() {
v := NewVault(3) // Create vault to store 3 key-value elements (string: string)v.Put("key1", "value1") // Add "key1": "value1"
fmt.Println(v.Len()) // 1v.Put("key2", "value2") // Add "key2": "value2"
fmt.Println(v.Len()) // 2v.Put("key3", "value3") // Add "key3": "value3"
fmt.Println(v.Len()) // 3fmt.Println(v.Get("key1")) // value1
v.Put("key4", "value4") // Add "key4": "value4" and remove "key2" as least recently used one
fmt.Println(v.Len()) // 3fmt.Println(v.Keys()) // [key1 key4 key3] // keys order doesn't matter here
}```