pt.unl.fct.di.novasys.babel.crdts.delta.implementations

Class DeltaLWWSet

  • All Implemented Interfaces:
    DeltaCRDT, GenericCRDT


    public class DeltaLWWSet
    extends DeltaBasedCRDT
    A delta-based set with a last-writer-wins policy (LWW). The set supports generic types implemented as SerializableTypes. It provides methods to add, remove and lookup for elements.
    • Field Detail

      • serializer

        public static pt.unl.fct.di.novasys.network.ISerializer<DeltaLWWSet> serializer
        A serializer that serializes the CRDT into (and from) a ByteBuf.
    • Method Detail

      • add

        public DeltaLWWSet add(SerializableType element)
        Adds an element to the set. If the element doesn't exist, it is added. Otherwise, the add is only successful if the current timestamp is greater or equal than the one associated with the element.
        Parameters:
        element - the element to insert
        Returns:
        a delta of the operation just performed
      • remove

        public DeltaLWWSet remove(SerializableType element)
        Removes an element of the set. If the element doesn't exist, it is added to the remove set. Otherwise, the remove is only successful if the current timestamp is greater or equal than the one associated with the element.
        Parameters:
        element - the element to insert
        Returns:
        a delta of the operation just performed
      • lookup

        public boolean lookup(SerializableType element)
        Searches for the element passed as argument. Returns true if the element is in the add set and not in the remove set.
        Parameters:
        element - element to search
        Returns:
        true if the element is in the add set and not in the remove set, or false otherwise.
      • iterator

        public Iterator<SerializableType> iterator()
        Returns an iterator of the elements in the set.
        Returns:
        an iterator of the elements in the set.
      • copy

        public GenericCRDT copy()
        Description copied from interface: GenericCRDT
        Creates a copy of the CRDT. Modifications on the copy don't modify the original.
        Returns:
        a copy of the CRDT
      • serialize

        public void serialize(io.netty.buffer.ByteBuf in)
                       throws IOException
        Description copied from interface: GenericCRDT
        Serializes the CRDT into a ByteBuf
        Parameters:
        in - ByteBuf to serialize the CRDT to
        Throws:
        IOException - if an error occurs while serializing

Copyright © 2024. All rights reserved.