HashMap Reference
A HashMap allows you to associate arbitrary data as key/value pairs.
Constructor
Section titled “Constructor”Constructs the HashMap.
var map = HashMap();Parameters
Section titled “Parameters”None
Methods
Section titled “Methods”Clears all entries from the hash map.
var map = HashMap();map.set("key", "value");map.clear();var size = map.size(); // 0Parameters
Section titled “Parameters”None
Returns
Section titled “Returns”nil
delete
Section titled “delete”Deletes an entry from the hash map.
var map = HashMap();map.set("key", "value");var exists = map.delete("key"); // truevar does_not_exist = map.delete("other_key"); // falseParameters
Section titled “Parameters”key: dyn? - The key of the entry to remove.
Returns
Section titled “Returns”Boolean - true if the was in the hash map, false otherwise.
entries
Section titled “entries”Returns an iterator of the entries in the hash map.
var map = HashMap();map.set("key", "value");map.entries().for_each((entry) -> { println("key: " + entry.key ", value: " + entry.value);});// "key: key, value: value"Parameters
Section titled “Parameters”None
Returns
Section titled “Returns”Iterator - An iterator of Entries
Get’s the value associated with the key.
var map = HashMap();map.set("key", "value");map.get("key"); // "value"Parameters
Section titled “Parameters”key: `dyn?’ - The key associated with the value.
Returns
Section titled “Returns”dyn? - The associated value.
get_or_default
Section titled “get_or_default”Gets the value associated with the key or a provided default.
var map = HashMap();map.set("key", "value");map.get_or_default("key", "default"); // "value"map.get_or_default("other_key", "default"); // "default"Parameters
Section titled “Parameters”key: dyn?' - The key associated with the value.
default: dyn? - The default to use if the key is not present.
Returns
Section titled “Returns”dyn? - The associated value or the default if the key is not in the hash map.
get_or_insert
Section titled “get_or_insert”Gets the value associated with the key, or if the key is not found, calls the factory function and inserts its return value.
var map = HashMap();map.set("key", "value");map.get_or_insert("key", "default"); // "value"map.get_or_insert("other_key", () -> "default"); // "default"Parameters
Section titled “Parameters”key: dyn?' - The key associated with the value.
factory: () -> dyn? - If the key is not present, the factory function will be called and the return will be inserted into the hash map.
Returns
Section titled “Returns”dyn? - The associated value or the return of the factory function if the key is not in the hash map.
Returns true if the value is in the hash map, otherwise false.
var map = HashMap();map.set("key", "value");map.has("key"); // trueParameters
Section titled “Parameters”key: dyn?' - The key to search for.
Returns
Section titled “Returns”Boolean - true if the key is in the hash map, otherwise false.
Returns an iterator of the keys in the hash map.
var map = HashMap();map.set("key", "value");map.keys().for_each((key) -> { println(key);});// "key"Parameters
Section titled “Parameters”None
Returns
Section titled “Returns”Iterator - An iterator of keys.
Returns the number of entries in the hash map.
var map = HashMap();map.set("key", "value");var size = map.size() // 1Parameters
Section titled “Parameters”None
Returns
Section titled “Returns”Number - The number of entries in the hash map.
values
Section titled “values”Returns an iterator of the values in the hash map.
var map = HashMap();map.set("key", "value");map.values().for_each((value) -> { println(value);});// "value"Parameters
Section titled “Parameters”None
Returns
Section titled “Returns”Iterator - An iterator of values.