Skip to content

Map

Module: std.collections.map
Source: std/collections/map.zn

Usage Example

use std.collections.map;
fn main() {
let map = HashMap#[String, i32].new();
map.insert(String.from("a"), 1);
switch (
map.get(&String.from("a"))
) {
.Some(value) => @println("{}", *value),
.None => @println("Nothing"),
};
}

HashMap[K: Hash + Eq, V]

Separate-chaining hash map over List[List[Entry]], load factor 0.75


Fields:

buckets: List[List[Entry[K, V]]],
_len: usize,
_capacity: usize,

Constructors:

pub fn new() Self;
pub fn with_capacity(cap: usize) Self;

Getters:

pub fn len(*const self) usize;
pub fn capacity(*const self) usize;
pub fn is_empty(*const self) bool;
pub fn contains_key(*const self, key: *const K) bool;
pub fn get(*const self, key: *const K) Option[*const V];
pub fn get_mut(*self, key: *const K) Option[*V];

Mutations:

pub fn insert(*self, key: K, value: V) Option[V];
pub fn remove(*self, key: *const K) Option[V];
pub fn remove_entry(*self, key: *const K) Option[Entry[K, V]];
pub fn clear(*self);

Interfaces:

  • core.ops : Drop, Clone (when K: Clone, V: Clone)

Entry[K, V]

Single map entry


Fields:

pub hash: u64,
pub value: V,
pub key: K,

Methods:

pub fn value_ptr(*self) *V;
pub fn value_const_ptr(*const self) *const V;