OxL Справочник OxL
РусскийEnglish

data Map

Hash map with insertion-ordered iteration (§3.3). {k: v} literals have this type.

Example:

oxl✓ проверяется в CI
fn main() io {
  var ages = {"ann": 31, "bob": 27}
  ages.insert("cy", 40)
  for k in ages.keys() {
    print("{k} {ages.get(k)!}")
  }
}
Вывод
ann 31
bob 27
cy 40
@builtin("Map") pub(api) data Map<K, V>

Сложность. `get`, `insert`, `remove` and `contains` are O(1) on average.

Потокобезопасность. not shared between tasks; send a copy (or a `frozen` map) to another task.

С версии. 1.0.0-beta

Методы

new() -> Self
True when the map has no entries.
len() -> usize
The number of entries.
isEmpty() -> bool
Whether the map has no entries.
get(k: K) -> V?
Value for k or none.
insert(k: K, v: V)
Stores v under k, replacing the value that was there.
remove(k: K) -> V?
Removes the entry for k and returns its value, or none when there was none.
contains(k: K) -> bool
Whether the map has an entry for k.
clear()
Removes all entries.
keys() -> List<K>
The keys, in insertion order.
values() -> List<V>
The values, in the order of their keys.
iter() -> iter<(K, V)>
Lazy iterator over a snapshot of the (key, value) entries (insertion order).

Определено в: std/core/types.oxl:46

См. также