Skip to content

HashMap Reference

A HashMap allows you to associate arbitrary data as key/value pairs.

Constructs the HashMap.

var map = HashMap();

None

Clears all entries from the hash map.

var map = HashMap();
map.set("key", "value");
map.clear();
var size = map.size(); // 0

None

nil

Deletes an entry from the hash map.

var map = HashMap();
map.set("key", "value");
var exists = map.delete("key"); // true
var does_not_exist = map.delete("other_key"); // false

key: dyn? - The key of the entry to remove.

Boolean - true if the was in the hash map, false otherwise.

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"

None

Iterator - An iterator of Entries

Get’s the value associated with the key.

var map = HashMap();
map.set("key", "value");
map.get("key"); // "value"

key: `dyn?’ - The key associated with the value.

dyn? - The associated value.

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"

key: dyn?' - The key associated with the value.

default: dyn? - The default to use if the key is not present.

dyn? - The associated value or the default if the key is not in the hash map.

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"

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.

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"); // true

key: dyn?' - The key to search for.

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"

None

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() // 1

None

Number - The number of entries in the hash map.

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"

None

Iterator - An iterator of values.