Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/igrmk/treemap
Generic sorted map for Go with red-black tree under the hood
https://github.com/igrmk/treemap
container go golang golang-library golang-package gotemplate map red-black-tree sorted-map tree-structure treemap
Last synced: 7 days ago
JSON representation
Generic sorted map for Go with red-black tree under the hood
- Host: GitHub
- URL: https://github.com/igrmk/treemap
- Owner: igrmk
- License: unlicense
- Created: 2018-08-20T23:41:07.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-22T05:03:27.000Z (over 2 years ago)
- Last Synced: 2024-07-31T20:48:40.628Z (3 months ago)
- Topics: container, go, golang, golang-library, golang-package, gotemplate, map, red-black-tree, sorted-map, tree-structure, treemap
- Language: Go
- Homepage:
- Size: 69.3 KB
- Stars: 58
- Watchers: 2
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - treemap - Generic key-sorted map using a red-black tree under the hood. (Data Structures and Algorithms / Trees)
- awesome-go-extra - treemap - black tree under the hood|24|3|0|2018-08-20T23:41:07Z|2022-03-22T05:03:27Z| (Generators / Trees)
README
TreeMap v2
==========[![PkgGoDev](https://pkg.go.dev/badge/github.com/igrmk/treemap/v2)](https://pkg.go.dev/github.com/igrmk/treemap/v2)
[![Unlicense](https://img.shields.io/badge/license-Unlicense-brightgreen.svg)](http://unlicense.org/)
[![Build Status](https://api.travis-ci.com/igrmk/treemap.svg?branch=master)](https://app.travis-ci.com/github/igrmk/treemap)
[![Coverage Status](https://coveralls.io/repos/igrmk/treemap/badge.svg?branch=master)](https://coveralls.io/github/igrmk/treemap)
[![GoReportCard](https://goreportcard.com/badge/github.com/igrmk/treemap/v2)](https://goreportcard.com/report/github.com/igrmk/treemap/v2)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)`TreeMap` is a generic key-sorted map using a red-black tree under the hood.
It requires and relies on [Go 1.18](https://tip.golang.org/doc/go1.18) generics feature.
Iterators are designed after C++.### Usage
```go
package mainimport (
"fmt""github.com/igrmk/treemap/v2"
)func main() {
tr := treemap.New[int, string]()
tr.Set(1, "World")
tr.Set(0, "Hello")
for it := tr.Iterator(); it.Valid(); it.Next() {
fmt.Println(it.Key(), it.Value())
}
}// Output:
// 0 Hello
// 1 World
```### Install
```bash
go get github.com/igrmk/treemap/v2
```### Complexity
| Name | Time |
|:------------------------------:|:---------:|
| `Set` | O(log*N*) |
| `Del` | O(log*N*) |
| `Get` | O(log*N*) |
| `Contains` | O(log*N*) |
| `Len` | O(1) |
| `Clear` | O(1) |
| `Range` | O(log*N*) |
| `Iterator` | O(1) |
| `Reverse` | O(log*N*) |
| Iterate through the entire map | O(*N*) |### Memory usage
TreeMap uses O(*N*) memory.
### TreeMap v1
The previous version of this package used [gotemplate](https://github.com/ncw/gotemplate) library to generate a type specific file in your local directory.
Here is the link to this version [treemap v1](https://github.com/igrmk/treemap/tree/v1.0.0).### Licensing
Copyright © 2022 igrmk.
This work is free. You can redistribute it and/or modify it under the
terms of the Unlicense. See the LICENSE file for more details.### Thanks to
[![JetBrains](svg/jetbrains.svg)](https://www.jetbrains.com/?from=treemap)