Top Description Inners Fields Constructors Methods
org.graalvm.collections

public Class LockFreePrefixTree

extends Object
Class Inheritance
Imports
java.util.concurrent.atomic.AtomicBoolean, .AtomicInteger, .AtomicIntegerArray, .AtomicLong, .AtomicReferenceArray, .AtomicReferenceFieldUpdater, java.util.function.BiConsumer, .BiFunction

Thread-safe and lock-free prefix-tree implementation in which keys are sequences of 64-bit values, and the values are 64-bit values. The LockFreePrefixTree supports the same operations as the PrefixTree as follows:

The LockFreePrefixTree supports a single operation root, which returns the root node. The nodes support the following operations: at to obtain a child node, value to obtain the value at the current node, setValue to atomically set the value, and incValue to atomically increment the value.

The LockFreePrefix tree represents a Tree of nodes of classNode, with each node having a key and an atomic reference array of children. The underlying children structure is represented as a LinearArray if the number of children is under a threshold, and represented by a hash table once the threshold is reached. Any additions or accesses to the datastructure are done using the at function. The at function takes a key value as a parameter and either returns an already existing node or inserts a new node and returns it. The function may cause the underlying AtomicReferenceArray to grow in size, either with tryResizeLinear or tryResizeHash. Insertion of new nodes is always done with the CAS operation, to ensure atomic updates and guarantee the progress of at least a single thread in the execution. Additionally, any growth operations occur atomically, as we perform a CAS with the reference to the Array to a new, freshly allocated array object.

Since
22.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
LockFreePrefixTree.Allocator

Policy for allocating objects of the lock-free prefix tree.

private static class
LockFreePrefixTree.FailedAllocationException

Exception denoting that an allocation failed.

public static class
LockFreePrefixTree.HeapAllocator

Allocator that allocates objects directly on the managed heap.

public static class
public static class
LockFreePrefixTree.ObjectPoolingAllocator

Allocator that internally maintains several pools of preallocated objects, and allocates objects from those pools.

Field Summary

Modifier and TypeField and Description
private final LockFreePrefixTree.Allocator
private volatile LockFreePrefixTree.Node

Constructor Summary

AccessConstructor and Description
public
LockFreePrefixTree(LockFreePrefixTree.Allocator allocator)

Create new LockFreePrefixTree with root being a Node with key 0.

Method Summary

Modifier and TypeMethod and Description
public LockFreePrefixTree.Allocator
public void
reset()

Resets the tree.

public LockFreePrefixTree.Node

Returns:

the root of the tree
root
()

The root node of the tree.

public <
The type of the context
C
>
void
topDown(C
The context for the root of the tree
initialContext
,
BiFunction<C, Long, C>
A function defining how the context for children is created
createContext
,
BiConsumer<C, Long>
A function that consumes the nodes value
consumeValue
)

Traverse the tree top-down while maintaining a context.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait