Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • K

  • V

Hierarchy

  • PersistentUnorderedMap

Index

Constructors

constructor

  • Creates or restores a persistent unordered map with a given storage prefix. Always use a unique storage prefix for different collections.

    Example

    let map = new PersistentUnorderedMap<string, string>("m") // note the prefix must be unique (per NEAR account)
    

    Parameters

    • prefix: string

      A prefix to use for every key of this map.

    Returns PersistentUnorderedMap

Accessors

length

  • get length(): i32

Methods

clear

  • clear(): void

contains

  • contains(key: K): bool
  • Checks whether the map contains a given key

    let map = new PersistentUnorderedMap<string, string>("m")
    
    map.contains("hello")      // false
    map.set("hello", "world")
    map.contains("hello")      // true
    

    Parameters

    • key: K

      Key to check.

    Returns bool

    True if the given key present in the map.

delete

  • delete(key: K): void
  • Removes the given key and related value from the map

    let map = new PersistentUnorderedMap<string, string>("m")
    
    map.set("hello", "world")
    map.delete("hello")
    

    Removes value and the key from the map.

    Parameters

    • key: K

      Key to remove.

    Returns void

entries

  • entries(start?: i32, end?: i32): MapEntry<K, V>[]

get

  • get(key: K, defaultValue?: V | null): V | null
  • Retrieves the related value for a given key, or uses the defaultValue if not key is found

    let map = new PersistentUnorderedMap<string, string>("m")
    
    map.set("hello", "world")
    let found = map.get("hello")
    let notFound = map.get("goodbye", "cruel world")
    
    assert(found == "world")
    assert(notFound == "cruel world")
    

    Parameters

    • key: K

      Key of the element.

    • Default value defaultValue: V | null = null

      The default value if the key is not present.

    Returns V | null

    Value for the given key or the default value.

getSome

  • getSome(key: K): V
  • Retrieves a related value for a given key or fails assertion with "key not found"

    let map = new PersistentUnorderedMap<string, string>("m")
    
    map.set("hello", "world")
    let result = map.getSome("hello")
    // map.getSome("goodbye")  // will throw with failed assertion
    
    assert(result == "world")
    

    Parameters

    • key: K

      Key of the element.

    Returns V

    Value for the given key or throws

keys

  • keys(start?: i32, end?: i32): K[]

last

  • last(count: i32): MapEntry<K, V>[]

pop

  • pop(): MapEntry<K, V>

set

  • set(key: K, value: V): void

values

  • values(start?: i32, end?: i32): V[]

Generated using TypeDoc