Class: Map

olympe.df. Map

A Map is an enumerable set of key-value pairs. A map cannot contain duplicate keys; each key can map to at most one value. The type of the values is specified in the constructor, while keys are always strings.

Entries are added with the set(key, value) method. Presence of an entry is tested with the has(key) method and retrieval is typically done using get(key).

Example:

const myMap = new olympe.df.Map(olympe.df.OString);
const bob = new olympe.df.OString("Bob");
myMap.set("name", bob);

new Map( [valueType])

Creates a new Map specifying the type of the value.

Parameters:
Name Type Argument Description
valueType function | Object <optional>

Item's value type constructor

Extends

Methods


clear()

Removes all entries from the map.


getFirst()

Gets the value of the first entry in the map.

Returns:

the value of the first entry.

Type
olympe.df.Proxy.<T> | T

getFirstKey()

Gets the key for the first entry in the collection.

Returns:

the number of key-value mappings in this map

Type
olympe.df.Proxy.<string> | string

remove(key)

Removes a specific entry from the map.

Parameters:
Name Type Description
key string

key whose mapping is to be removed from the map

Returns:

the previous value associated with key, or undefined if there was no mapping for key.

Type
T | undefined

set(key, value)

Adds a key-value pair to the map. If the key was already present, the new value replaces the existing one.

Parameters:
Name Type Description
key string

key with which the specified value is to be associated

value T

value to be associated with the specified key


setValueType(valueType)

Sets the type of the objects that can be stored in this map.

Parameters:
Name Type Description
valueType function

Value type constructor.