All Projects → elliotchance → Orderedmap

elliotchance / Orderedmap

Licence: mit
🔃 An ordered map in Go with amortized O(1) for Set, Get, Delete and Len.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Orderedmap

Codejam
Set of handy reusable .NET components that can simplify your daily work and save your time when you copy and paste your favorite helper methods and classes from one project to another
Stars: ✭ 217 (-12.15%)
Mutual labels:  data-structures
Libdict
C library of key-value data structures.
Stars: ✭ 234 (-5.26%)
Mutual labels:  data-structures
Jctools
jctools.github.io/jctools
Stars: ✭ 2,833 (+1046.96%)
Mutual labels:  data-structures
Polyline
Polyline encoder / decoder in swift
Stars: ✭ 224 (-9.31%)
Mutual labels:  maps
Collectable
High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
Stars: ✭ 233 (-5.67%)
Mutual labels:  data-structures
Staticvec
Implements a fixed-capacity stack-allocated Vec alternative backed by an array, using const generics.
Stars: ✭ 236 (-4.45%)
Mutual labels:  data-structures
Play With Data Structures
慕课 liuyubobobo「玩转数据结构」课程的 Go 语言实现版本
Stars: ✭ 217 (-12.15%)
Mutual labels:  data-structures
Datamodelr
Data model diagrams in R
Stars: ✭ 248 (+0.4%)
Mutual labels:  data-structures
Gmapsfx
Java API for using Google Maps within a JavaFX application.
Stars: ✭ 233 (-5.67%)
Mutual labels:  maps
Argo
使用go语言实现数据结构与算法,涵盖字符串、数组、链表、队列、栈、树、图等数据结构。在实现算法的基础上,进行go语言实战。此外也包含经典算法在go实战项目中的应用,以及开源项目算法方面源码分析。
Stars: ✭ 243 (-1.62%)
Mutual labels:  data-structures
Program Blog
Practice, thinking and reading
Stars: ✭ 228 (-7.69%)
Mutual labels:  data-structures
Deepgraph
Analyze Data with Pandas-based Networks. Documentation:
Stars: ✭ 232 (-6.07%)
Mutual labels:  data-structures
Ctci 6th Edition Cn
《Cracking the Coding Interview, 6th Edition》CtCI中文翻译
Stars: ✭ 237 (-4.05%)
Mutual labels:  data-structures
C Algorithms
A library of common data structures and algorithms written in C.
Stars: ✭ 2,654 (+974.49%)
Mutual labels:  data-structures
Rust Algorithms
Common data structures and algorithms in Rust
Stars: ✭ 2,918 (+1081.38%)
Mutual labels:  data-structures
Static Frame
Immutable and grow-only Pandas-like DataFrames with a more explicit and consistent interface.
Stars: ✭ 217 (-12.15%)
Mutual labels:  data-structures
Computer Science In Javascript
Computer science reimplemented in JavaScript
Stars: ✭ 2,590 (+948.58%)
Mutual labels:  data-structures
Write A Hash Table
✏️ Learn how to write a hash table in C
Stars: ✭ 2,822 (+1042.51%)
Mutual labels:  data-structures
Go Staticmaps
A go (golang) library and command line tool to render static map images using OpenStreetMap tiles.
Stars: ✭ 246 (-0.4%)
Mutual labels:  maps
Rethink C
A reuseable codebase for C Programming Language.
Stars: ✭ 241 (-2.43%)
Mutual labels:  data-structures

🔃 github.com/elliotchance/orderedmap GoDoc Build Status

Installation

go get -u github.com/elliotchance/orderedmap

Basic Usage

An *OrderedMap is a high performance ordered map that maintains amortized O(1) for Set, Get, Delete and Len:

m := orderedmap.NewOrderedMap()

m.Set("foo", "bar")
m.Set("qux", 1.23)
m.Set(123, true)

m.Delete("qux")

Internally an *OrderedMap uses a combination of a map and linked list.

Iterating

Be careful using Keys() as it will create a copy of all of the keys so it's only suitable for a small number of items:

for _, key := range m.Keys() {
	value, _:= m.Get(key)
	fmt.Println(key, value)
}

For larger maps you should use Front() or Back() to iterate per element:

// Iterate through all elements from oldest to newest:
for el := m.Front(); el != nil; el = el.Next() {
    fmt.Println(el.Key, el.Value)
}

// You can also use Back and Prev to iterate in reverse:
for el := m.Back(); el != nil; el = el.Prev() {
    fmt.Println(el.Key, el.Value)
}

The iterator is safe to use bidirectionally, and will return nil once it goes beyond the first or last item.

If the map is changing while the iteration is in-flight it may produce unexpected behavior.

Performance

CPU: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz

RAM: 8GB

System: Windows 10

$go test -benchmem -run=^$ github.com/elliotchance/orderedmap -bench BenchmarkAll

map[int]bool

map orderedmap
set 198 ns/op, 44 B/op 722 ns/op, 211 B/op
get 18 ns/op, 0 B/op 37.3 ns/op, 0 B/op
delete 888 ns/op, 211 B/op 280 ns/op, 44 B/op
Iterate 206 ns/op, 44 B/op 693 ns/op, 259 B/op

map[string]bool(PS : Use strconv.Itoa())

map orderedmap
set 421 ns/op, 86 B/op 1048 ns/op, 243 B/op
get 81.1 ns/op, 2 B/op 97.8 ns/op, 2 B/op
delete 737 ns/op, 122 B/op 1188 ns/op, 251 B/op
Iterate all 14706 ns/op, 1 B/op 52671 ns/op, 16391 B/op

Big map[int]bool (10000000 keys)

map orderedmap
set all 1.834559 s/op, 423.9470291 MB/op 7.5564667 s/op, 1784.1483 MB/op
get all 2.6367878 s/op, 423.9698 MB/op 9.0232475 s/op, 1784.1086 MB/op
Iterate all 1.9526784 s/op, 423.9042 MB/op 8.2495265 s/op, 1936.7619 MB/op

Big map[string]bool (10000000 keys)

map orderedmap
set all 4.8893923 s/op, 921.33435 MB/op 10.4405527 s/op, 2089.0144 MB/op
get all 7.122791 s/op, 997.3802643 MB/op 13.2613692 s/op, 2165.09521 MB/op
Iterate all 5.1688922 s/op, 921.4619293 MB/op 12.6623711 s/op, 2241.5272064 MB/op
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].