Constructor
new HashMap(initialCapacityopt)
- Implements:
Example
const map = new Collections.HashMap(37);
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
initialCapacity |
number |
<optional> |
13
|
Initial size of the hashmap IMPORTANT : It is not recommended that you choose a size that will be a close or approximate upper bound on your data, so that number of rehashes of the inner hashtable will be small. For example, if you know you only need 100,000 inserts, a good initial capacity would not be approximately 100,000 as the inner hastable will resize once 75,000 (75% of size) to 75,000 * 2 = 150,000. Next resize will be 0.75 * 150,000 which is 112,500 , greater than your space needed. So, try something around 150,000. Or you can just rehash a lot :) |
Methods
clear() → {undefined}
- Implements:
Clears the map of all k,v pairs
Returns:
- Type
- undefined
contains(key) → {boolean}
- Implements:
Reports whether the Map contains the given key
Example
map.contains("empty"); // return false
Parameters:
Name | Type | Description |
---|---|---|
key |
* | The key to lookup |
Returns:
True if @param key is found and false otherwise
- Type
- boolean
getVal(key) → {*}
- Implements:
Retrieves the value mapped to by the given key
Example
map.put(99, "problems");
map.getVal(99); // returns "problems"
Parameters:
Name | Type | Description |
---|---|---|
key |
* | The key to lookup |
Returns:
The value associated with @param key
- Type
- *
keys() → {Array}
- Implements:
Returns all of the keys in the Map
Example
map.put(1, "b");
map.put(2, "c");
map.put(3, "d");
map.keys() // returns [1, 2, 3] permutation (order may
or may not be guarenteed)
Returns:
An array of keys
- Type
- Array
put(key, value) → {Map}
- Implements:
Inserts the given key and value into the Map
Example
map.put("ed", "jones");
// ed maps to jones
map.put("ed", "james");
// now same ed maps to james and not jones
Parameters:
Name | Type | Description |
---|---|---|
key |
* | The key |
value |
* | The value mapped to by @param key |
Returns:
The instance that this method was called
- Type
- Map
remove(key) → {boolean}
- Implements:
Removes the given key and its associated value from the Map
Example
map.put(99, "problems");
map.remove(88); // returns false
map.remove(99); // returns true
Parameters:
Name | Type | Description |
---|---|---|
key |
* | The key to lookup |
Returns:
True if the key and it's value were removed and false otherwise
- Type
- boolean
size() → {number}
- Implements:
Returns number of elements in the Map
Example
map.put(99, "problems");
map.size() // 1
Returns:
The number of insertions
- Type
- number
values() → {Array}
- Implements:
Returns all of the values in the Map
Example
map.put(1, "b");
map.put(2, "c");
map.put(3, "d");
map.values() // returns ["c", "b", "d"] permutation
Returns:
An array of values
- Type
- Array