concurrent / org.apache.tuweni.concurrent / AtomicSlotMap

AtomicSlotMap

class AtomicSlotMap<K : Comparable<Any?>, V : Any> (source)

An atomic map that locates available keys within a DiscreteDomain.

This is an atomic map that will allocate key slots based on availability. It will attempt to keep the range compact by filling slots as they become available.

This implementation should be used with small sets, as addition is an O(N) operation.

Parameters

- The type of the map keys.

- The type of values to store in the map.

Constructors

<init>

AtomicSlotMap(domain: DiscreteDomain<K>)

Create a slot map over the provided domain.

Functions

add

fun add(value: V): K

Add a value to the slot map, using the first available slot.

compute

fun compute(fn: Function<in K, out V>): K

Find a slot and compute a value for it.

computeAsync

fun computeAsync(fn: Function<in K, AsyncResult<out V>>): AsyncResult<K>

Find a slot and compute a value for it.

entries

fun entries(): Stream<MutableEntry<K, V>>

get

fun get(slot: K): V?

Get the value in a slot.

positiveIntegerSlots

static fun <V : Any> positiveIntegerSlots(): AtomicSlotMap<Int, V>

Create a slot map over the range of integers > 0.

put

fun put(slot: K, value: V): V?

Put a value into a specific slot.

remove

fun remove(slot: K): V?

Remove a value from a slot, making the slot available again.

size

fun size(): Int

values

fun values(): Stream<V>