Skip to content
FutureBlitz

    Install

    Import std.concurrent.concurrent_map

    std.concurrent.concurrent_map

    ConcurrentMap<K, V>: a hash map that any number of threads change and read at once. Its entries are in 16 parts, by the top bits of their keys' hashes once they're mixed, each part an ImmutableMap behind a Mutex of its own, so threads that change different parts don't wait for each other. A read copies its part's ImmutableMap, which shares its nodes, and looks in the copy, holding the lock only for that, and a For ... In goes over a copy of each part. A value is in a Shared cell of its own, so a change worked out from a copy can tell whether another thread changed the key meanwhile. A change keeps the entries it replaces in a Local until it holds no lock, so a Destroy that the letting go runs can use the map.

    std/concurrent/concurrent_map.fb

    Types

    ConcurrentMap class

    Public Shared Class ConcurrentMap<K, V> Implements Iterable<(K, V)>, Defaultable

    A Map that threads share, which each Get, Set, and Remove changes or reads whole, in parts, so threads that use different keys don't wait for each other.

    std/concurrent/concurrent_map.fb, line 39

    • Public New() constructor #

      A new, empty ConcurrentMap.

    • Public Property Count: Int property #

      How many entries there are, which other threads may change at any time.

    • @PanicsAtCaller Public Method Add(key: K, value: V) method #

      Adds an entry, or gives an existing key its new value. Panics when the ConcurrentMap has as many entries as an Int counts.

    • @PanicsAtCaller Public Method TryAdd(key: K, value: V): Bool method #

      Adds an entry when the key isn't there, and tells whether it wasn't. Panics when the ConcurrentMap has as many entries as an Int counts.

    • Public Method Get(key: K): V? method #

      The key's value, or Null when it isn't there.

    • Public Method Get(key: K, fallback: V): V method #

      The key's value, or fallback when it isn't there.

    • @PanicsAtCaller Public Method GetOrAdd(key: K, make: Func(): V): V method #

      The key's value, adding what make gives for it first when it isn't there. Threads that ask for a key at once may each run make, but the map keeps the first value added, which they all get. Panics, as Add does, when there's no room for the key.

    • Public Method Update(key: K, change: Func(V): V): Bool method #

      Gives the key's value what change gives for it, and tells whether the key was there. When another thread changes the key's value meanwhile, change runs again, on the value that thread gave it, so no change is lost.

    • @PanicsAtCaller Public Method AddOrUpdate(key: K, value: V, change: Func(V): V): V method #

      Adds value for the key when it isn't there, or gives its value what change gives for it, and gives the value the key has now. When another thread changes the key meanwhile, change runs again, as in Update. Panics, as Add does, when there's no room for the key.

    • @PanicsAtCaller Operator [](key: K): V operator #

      The key's value. Panics when the key isn't there.

    • @PanicsAtCaller Operator []=(key: K, value: V) operator #

      Gives the key a value, adding it when it isn't there, as Add does.

    • Public Method Contains(key: K): Bool method #

      Whether key has an entry.

    • Public Method Remove(key: K): Bool method #

      Removes the key's entry, and tells whether there was one.

    • Public Method Clear() method #

      Removes every entry.

    • Public Method Keys(): K[] method #

      The keys, in the order a For ... In gives them.

    • Public Method Values(): V[] method #

      The values, in their keys' order.

    • Public Method ToMap(): Map<K, V> method #

      A new Map with the entries, in the order a For ... In gives them.

    • Public Static Method DefaultValue(): ConcurrentMap<K, V> static method #

      A new, empty ConcurrentMap.

    • Public Method Iterate(): ConcurrentMapIterator<K, V> method #

      Each key and its value, part by part, by their keys' hashes in a part, and keys of one hash in the order they were added. It goes over a copy of each part, made as it comes to it, so what other threads do meanwhile never stops it.

    ConcurrentMapIterator struct

    Public Struct ConcurrentMapIterator<K, V> Implements Iterator<(K, V)>

    The entries of a ConcurrentMap as they were when the loop began, which For ... In goes over.

    std/concurrent/concurrent_map.fb, line 285

    Report an issue with this page or with FutureBlitz on GitHub.