Class 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.
    • 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 interface DisjointSetStruct
        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 interface DisjointSetStruct
        Parameters:
        id1 - a set item
        id2 - 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 interface DisjointSetStruct
        Parameters:
        id1 - an item of Sp
        id2 - 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 interface DisjointSetStruct
        Returns:
        element count