Class HugeAtomicDisjointSetStruct
- java.lang.Object
-
- org.neo4j.graphalgo.core.utils.paged.dss.HugeAtomicDisjointSetStruct
-
- All Implemented Interfaces:
DisjointSetStruct
public final class HugeAtomicDisjointSetStruct extends java.lang.Object implements DisjointSetStruct
Add adaption of the C++ implementation [1] for the "Wait-free Parallel Algorithms for the Union-Find Problem" [2] with some input from an atomic DSS implementation in Rust [3]. The major difference for our DSS is, that we don't supported the Union-by-Rank strategy [3], for technical and performance reasons. The reference implementation in C++ uses 32bit unsigned integers for both the id values and the rank values. Those two values have to be updated atomically, which [1] does by merging them into a single 64bit unsigned integer and doing atomic/cas operations on that value. We need 64bits for the id value alone and since there is no u128 data type in Java, the only way to update those values would be to use a class for the combination of id+rank and updated the references to that atomically. This is the approach that the Rust implementation is doing, except that Rust allows the struct values to be allocated on the stack and has no GC overhead, where that would not be true for Java (in the near future). We drop the by-Rank functionality and just support Union-by-Min for this DSS. The main difference in implementation compared to the regular DSS is that we use CAS operations to atomically set a set id for some value. We will retry union operations until a thread succeeds in changing the set id for a node. Other threads that might have wanted to write a different value will fail and the CAS operation and redo their union step. This allows for concurrent writes into a single DSS and does not longer necessitate an additional merge step.- [1]:
https://github.com/wjakob/dset/blob/7967ef0e6041cd9d73b9c7f614ab8ae92e9e587a/dset.h
- [2]:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.56.8354&rep=rep1&type=pdf
- [3]:
https://github.com/tov/disjoint-sets-rs/blob/88ab08df21f04fcf7c157b6e042efd561ee873ba/src/concurrent.rs
- [4]:
https://en.wikipedia.org/wiki/Disjoint-set_data_structure#by_rank
-
-
Constructor Summary
Constructors Constructor Description HugeAtomicDisjointSetStruct(long capacity, NodeProperties communityMapping, AllocationTracker tracker, int concurrency)
HugeAtomicDisjointSetStruct(long capacity, AllocationTracker tracker, int concurrency)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MemoryEstimation
memoryEstimation(boolean incremental)
boolean
sameSet(long id1, long id2)
Check if p and q belong to the same set.long
setIdOf(long nodeId)
Find set Id of element p.long
size()
Number of elements stored in the data structure.void
union(long id1, long id2)
Joins the set of p (Sp) with set of q (Sq).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.neo4j.graphalgo.core.utils.paged.dss.DisjointSetStruct
asNodeProperties
-
-
-
-
Constructor Detail
-
HugeAtomicDisjointSetStruct
public HugeAtomicDisjointSetStruct(long capacity, AllocationTracker tracker, int concurrency)
-
HugeAtomicDisjointSetStruct
public HugeAtomicDisjointSetStruct(long capacity, NodeProperties communityMapping, AllocationTracker tracker, int concurrency)
-
-
Method Detail
-
memoryEstimation
public static MemoryEstimation memoryEstimation(boolean incremental)
-
setIdOf
public long setIdOf(long nodeId)
Description copied from interface:DisjointSetStruct
Find set Id of element p.- Specified by:
setIdOf
in interfaceDisjointSetStruct
- Parameters:
nodeId
- the element in the set we are looking for- Returns:
- an id of the set it belongs to
-
sameSet
public boolean sameSet(long id1, long id2)
Description copied from interface:DisjointSetStruct
Check if p and q belong to the same set.- Specified by:
sameSet
in interfaceDisjointSetStruct
- Parameters:
id1
- a set itemid2
- a set item- Returns:
- true if both items belong to the same set, false otherwise
-
union
public void union(long id1, long id2)
Description copied from interface:DisjointSetStruct
Joins the set of p (Sp) with set of q (Sq).- Specified by:
union
in interfaceDisjointSetStruct
- Parameters:
id1
- an item of Spid2
- an item of Sq
-
size
public long size()
Description copied from interface:DisjointSetStruct
Number of elements stored in the data structure.- Specified by:
size
in interfaceDisjointSetStruct
- Returns:
- element count
-
-