WeakConcurrentBag

class WeakConcurrentBag[A](tableSize: Int)

A WeakConcurrentBag stores a collection of values, each wrapped in a WeakReference. The structure is optimized for addition, and will achieve zero allocations in the happy path (aside from the allocation of the WeakReference, which is unavoidable). To remove a value from the bag, it is sufficient to clear the corresponding weak reference, at which point the weak reference will be removed from the bag during the next garbage collection.

Garbage collection happens regularly during the add operation. Assuming uniform distribution of hash codes of values added to the bag, the chance of garbage collection occurring during an add operation is 1/n, where n is the capacity of the table backing the bag.

Companion:
object
class Object
trait Matchable
class Any

Value members

Concrete methods

final def add(value: A): WeakReference[A]

Adds the specified value to the concurrent bag, returning a WeakReference that wraps the value.

Adds the specified value to the concurrent bag, returning a WeakReference that wraps the value.

final def gc(): Unit

Performs garbage collection, removing any empty weak references.

Performs garbage collection, removing any empty weak references.

final def iterator: Iterator[A]

Returns a weakly consistent iterator over the bag. This iterator will never throw exceptions even in the presence of concurrent modifications.

Returns a weakly consistent iterator over the bag. This iterator will never throw exceptions even in the presence of concurrent modifications.

final def size: Int

Returns the size of the bag. Due to concurrent modification, this is only an estimate. Note this operation is O(n.max(m)), where n is the number of elements in the collection, and m is the table size.

Returns the size of the bag. Due to concurrent modification, this is only an estimate. Note this operation is O(n.max(m)), where n is the number of elements in the collection, and m is the table size.

final override def toString(): String
Definition Classes
Any