Skip to content
FutureBlitz

    Install

    Import std.concurrent.concurrent_map

    ConcurrentMap

    std.concurrent.concurrent_map

    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.

    Examples

    Const counts = ConcurrentMap<String, Int>()
    Parallel For i = 0 Until 100
        counts.AddOrUpdate(i % 2 == 0 ? "even" : "odd", 1, Function(n: Int) => n + 1)
    End For
    
    Expect(counts.Get("even") == 50 && counts.Get("odd") == 50)

    std/concurrent/concurrent_map.fb, line 52

    • 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 loop 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 loop 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.

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