metosin/linked

Name: linked

Owner: Metosin

Description: Clojure(Script) efficient map and set structures that preserve insertion order

Created: 2018-03-27 12:00:24.0

Updated: 2018-03-27 12:37:45.0

Pushed: 2018-03-27 12:37:44.0

Homepage: http://frankiesardo.github.io/linked

Size: 126

Language: Clojure

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Linked

Build status

Map and Set structures that rememeber the insertion order of its elements, even after multiple assoc and dissoc. For Clojure and ClojureScript.

Download

Clojars Project

Map
uire '[linked.core :as linked])

ked/map :b 2 :a 1 :d 4)
#linked/map [[:b 2] [:a 1] [:d 4]]

oc (linked/map :b 2 :a 1 :d 4) :c 3)
#linked/map [[:b 2] [:a 1] [:d 4] [:c 3]]

o (linked/map) [[:c 3] [:a 1] [:d 4]])
#linked/map [[:c 3] [:a 1] [:d 4]]

soc (linked/map :c 3 :a 1 :d 4) :a)
#linked/map [[:c 3] [:d 4]]
Set
uire '[linked.core :as linked])

ked/set 4 3 1 8 2)
#linked/set [4 3 1 8 2]

j (linked/set 9 10) 1 2 3)
#linked/set [9 10 1 2 3]

o (linked/set) [7 6 1 5 6])
#linked/set [7 6 1 5]

j (linked/set 8 1 7 2 6) 7)
#linked/set [8 1 2 6]
Performance

These data structures wrap a normal hash-map but instead of feeding it a normal [key value] pair their remeber a [key value left-key right-key] record. When an item is removed from the data structure it is sufficient to update the left and right node to reference each others keys while removing the chosen node. This implementation yields the same Big O time and space complexity of a standard hash-map (altought effective performance will be slower by a constant factor).

Comparison with ordered
License

Copyright © 2014 Frankie Sardo

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.