Class: TreeMultiMap

TreeMultiMap

A Map supporting arbitrary multiple values with a single key. In addition the Map is sorted on keys dynamically. This Map is backed by an AVLTree Reference: MultiMap in Google Guava libraries

new TreeMultiMap(orderFn)

Example -

var TreeMultiMap = require("dsjslib").TreeMultiMap
var tmap=new TreeMultiMap(function(k1,k2){return k1-k2})
Parameters:
Name Type Description
orderFn userCompareFn

Function to provide custom ordering of keys

Source:

Extends

Methods

entries() → {Array}

Return a list of all key, value pairs. In addition, the returned list is sorted on keys The key value pairs are returned as objects {'key':,'value':} Note that for keys associated with multiple values there is one object per value returned in the entry for example for key1->val1,val2,val3 , the entries will be [{'key':key1,'value':val1},{'key':key1,'value':val2},{'key':key1,'value':val3}]

Source:
Returns:

Array of objects {'key':,'value':}

Type
Array

get(key) → {Array}(key) → {Array}

Search for key and return associated value array or empty array This method never returns null even if the key is not present Any changes made to the returned array modify the underlying array in the MultiMap as well

Parameters:
Name Type Description
key
Inherited From:
Source:
Returns:

associated value Array

Type
Array

hasKey(key) → {Boolean}(key) → {Boolean}

Test if a key is present in Map or not. This doesn't modify the Map to create empty array if the key was not present.

Parameters:
Name Type Description
key
Inherited From:
Source:
Returns:

true if key is present, false otherwise

Type
Boolean

put(key, value) → {MultiMap}(key, value) → {MultiMap}

Insert a key value pair into the Map. If the key is already present, the value will be added to the existing list, otherwise, an array is created and the value is added to the array

Parameters:
Name Type Description
key *
value *
Inherited From:
Source:
Returns:

this

Type
MultiMap

remove(key, value) → {Array}(key, value) → {Array}

If a value is provided, only that value is removed from the list If value is not provided, key and all values are deleted from the MultiMap

Parameters:
Name Type Description
key *
value *
Inherited From:
Source:
Returns:

last value associated with the key

Type
Array