README
Adict – Ordered Dictionary
OrderedDict is a data structure that preservers order of inserted keys. And is a sub-class of a regular object/dictionary. In addition it provides couple of convenient methods to push elements to start or end of a dict.
As an example: this data structure can be used to implement LRU-cache.
let OrderedDict = require("adict");
let dict = new OrderedDict();
dict.set(1, 2);
- Small 538b min and gzip
- Zero dependencies
- O(1) runtime complexity for all operations
API
OrderedDict
OrderedDict is a data structure that preservers order of inserted keys. And is a sub-class of a regular object/dictionary. Implementation is inspired by python's OrderedDict and this particular gist: https://gist.github.com/joequery/12332f410a05e6c7c949
Kind: class
let dict = new OrderedDict();
- OrderedDict()
- .set(key, value) ⇒
OrderedDict
- .delete(key) ⇒
boolean
- .clear() ⇒
undefined
- .get(key) ⇒
any
|undefined
- .has(key) ⇒
boolean
- .pop() ⇒
undefined
|any
- .shift() ⇒
undefined
|any
- .toStart(key) ⇒
boolean
- .toEnd(key) ⇒
boolean
- .keys() ⇒
Iterator
- .values() ⇒
Iterator
- .entries() ⇒
Iterator
- .set(key, value) ⇒
OrderedDict
orderedDict.set(key, value) ⇒ Add a new key-value pair to an ordered dict.
Kind: instance method of OrderedDict
Param | Type |
---|---|
key | string | number |
value | any |
boolean
orderedDict.delete(key) ⇒ Delete a key from an ordered dict.
Kind: instance method of OrderedDict
Param | Type |
---|---|
key | string | number |
undefined
orderedDict.clear() ⇒ Clear ordered dict.
Kind: instance method of OrderedDict
any
| undefined
orderedDict.get(key) ⇒ Retrieve a key from an ordered dict.
Kind: instance method of OrderedDict
Param | Type |
---|---|
key | string | number |
boolean
orderedDict.has(key) ⇒ Check if key exists in an ordered dict.
Kind: instance method of OrderedDict
Param | Type |
---|---|
key | string | number |
undefined
| any
orderedDict.pop() ⇒ Remove and return last element from an ordered dict.
Kind: instance method of OrderedDict
undefined
| any
orderedDict.shift() ⇒ Remove and return first element from an ordered dict.
Kind: instance method of OrderedDict
boolean
orderedDict.toStart(key) ⇒ Move an existing element to the start of an ordered dict.
Kind: instance method of OrderedDict
Param | Type |
---|---|
key | string | number |
boolean
orderedDict.toEnd(key) ⇒ Move an existing element to the end of an ordered dict.
Kind: instance method of OrderedDict
Param | Type |
---|---|
key | string | number |
Iterator
orderedDict.keys() ⇒ Returns new Iterator object that contains all keys of an ordered dict.
Kind: instance method of OrderedDict
Iterator
orderedDict.values() ⇒ Returns new Iterator object that contains all values of an ordered dict.
Kind: instance method of OrderedDict
Iterator
orderedDict.entries() ⇒ Returns new Iterator object that contains all key-value pairs of an ordered dict.
Kind: instance method of OrderedDict
Object
[private] LinkedListNode : Kind: global typedef Properties
Name | Type |
---|---|
value | any |
prev | LinkedListNode | null |
next | LinkedListNode | null |