Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bserdar/slicemap
A Go map that uses slice of values as key
https://github.com/bserdar/slicemap
data-structures go golang map slice
Last synced: about 1 month ago
JSON representation
A Go map that uses slice of values as key
- Host: GitHub
- URL: https://github.com/bserdar/slicemap
- Owner: bserdar
- License: apache-2.0
- Created: 2023-01-10T02:17:17.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-10T02:24:40.000Z (almost 2 years ago)
- Last Synced: 2024-06-20T11:47:13.301Z (7 months ago)
- Topics: data-structures, go, golang, map, slice
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![GoDoc](https://godoc.org/github.com/bserdar/slicemap?status.svg)](https://godoc.org/github.com/bserdar/slicemap)
[![Go Report Card](https://goreportcard.com/badge/github.com/bserdar/slicemap)](https://goreportcard.com/report/github.com/bserdar/slicemap)# Slicemap
This package implements a map that uses a slice of values as key.
Go does not allow using slices as map keys. This especially becomes
cumbersome if you have a composite key with non-constant number of
elements. This package uses a nested map structure to associate values
with keys where the keys are a slice of a comparable object.```
sm:=SliceMap[string,int]{} // Create a map[[]string]int
sm.Put([]string{"a","b","c"},1)
sm.Put([]string{"d","e"},2)
fmt.Println(sm.Get([]string{"a","b","c"})) // Prints 1, true
fmt.Println(sm.Get([]string{"d","e"})) // Prints 2, true
fmt.Println(sm.Get([]string{"f","g"})) // Prints 0, false
```