https://github.com/lorenzosaino/go-orderedmap
Go implementation of an ordered map using generics
https://github.com/lorenzosaino/go-orderedmap
go golang orderedmap
Last synced: about 1 year ago
JSON representation
Go implementation of an ordered map using generics
- Host: GitHub
- URL: https://github.com/lorenzosaino/go-orderedmap
- Owner: lorenzosaino
- License: bsd-3-clause
- Created: 2022-01-31T08:50:37.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-08T20:50:26.000Z (about 3 years ago)
- Last Synced: 2025-02-02T13:28:19.594Z (over 1 year ago)
- Topics: go, golang, orderedmap
- Language: Go
- Homepage:
- Size: 1.26 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go ordered map
[](https://pkg.go.dev/github.com/lorenzosaino/go-orderedmap)
[](https://github.com/lorenzosaino/go-orderedmap/actions)
[](https://goreportcard.com/report/github.com/lorenzosaino/go-orderedmap)
[](https://github.com/lorenzosaino/go-orderedmap/blob/master/LICENSE)
Go implementation of an ordered map using generics.
## Implementation
An ordered map is a map that additionally maintains ordering among its entries.
This data structure can be used to solve a variety of problems: one very common use case is implementing LRU or LRU-like cache replacement policies.
This implementation supports O(1) lookup, update, removal, insertion to front/back, insertion before/after a specific key, move to front/back, move before/after a specific key.
Under the hood this is implemented as a combination of a map and doubly-linked list, whereby each value in the map is node of the list.
The list is implemented by forking the standard library [`container/list`](https://pkg.go.dev/container/list) package and adding support for generics.
This implementation is not safe for concurrent usage.
## Installation
You can get this module by invoking from your terminal
```
go get -u github.com/lorenzosaino/go-orderedmap
```
and then importing it in your code with
```go
import orderedmap "github.com/lorenzosaino/go-orderedmap"
```
Since it requires generics support, you will need Go 1.18 or above.
## Usage
For reference and examples, see [Go doc](https://pkg.go.dev/github.com/lorenzosaino/go-orderedmap?tab=doc).
## Development
You can invoke `make help` to see all make targets provided.
```
$ make help
all Run all checks and tests
mod-upgrade Upgrade all vendored dependencies
mod-update Ensure all used dependencies are tracked in go.{mod|sum} and vendored
fmt-check Validate that all source files pass "go fmt"
lint Run go lint
vet Run go vet
staticcheck Run staticcheck
test Run all tests
container-shell Open a shell on a Docker container
container-% Run any target of this Makefile in a Docker container
help Print help
```
## License
[BSD 3-clause](LICENSE)