New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

adict

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adict

Implementation of an OrderedDict data structure.

1.0.0
latest
npm
Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

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

Add a new key-value pair to an ordered dict.

Kind: instance method of OrderedDict

ParamType
keystring | number
valueany

orderedDict.delete(key) ⇒ boolean

Delete a key from an ordered dict.

Kind: instance method of OrderedDict

ParamType
keystring | number

orderedDict.clear() ⇒ undefined

Clear ordered dict.

Kind: instance method of OrderedDict

orderedDict.get(key) ⇒ any | undefined

Retrieve a key from an ordered dict.

Kind: instance method of OrderedDict

ParamType
keystring | number

orderedDict.has(key) ⇒ boolean

Check if key exists in an ordered dict.

Kind: instance method of OrderedDict

ParamType
keystring | number

orderedDict.pop() ⇒ undefined | any

Remove and return last element from an ordered dict.

Kind: instance method of OrderedDict

orderedDict.shift() ⇒ undefined | any

Remove and return first element from an ordered dict.

Kind: instance method of OrderedDict

orderedDict.toStart(key) ⇒ boolean

Move an existing element to the start of an ordered dict.

Kind: instance method of OrderedDict

ParamType
keystring | number

orderedDict.toEnd(key) ⇒ boolean

Move an existing element to the end of an ordered dict.

Kind: instance method of OrderedDict

ParamType
keystring | number

orderedDict.keys() ⇒ Iterator

Returns new Iterator object that contains all keys of an ordered dict.

Kind: instance method of OrderedDict

orderedDict.values() ⇒ Iterator

Returns new Iterator object that contains all values of an ordered dict.

Kind: instance method of OrderedDict

orderedDict.entries() ⇒ Iterator

Returns new Iterator object that contains all key-value pairs of an ordered dict.

Kind: instance method of OrderedDict

[private] LinkedListNode : Object

Kind: global typedef Properties

NameType
valueany
prevLinkedListNode | null
nextLinkedListNode | null

Keywords

ordered map

FAQs

Package last updated on 31 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts