Class ChampAddOnlySet<E>

java.lang.Object
org.jhotdraw8.icollection.ChampAddOnlySet<E>
Type Parameters:
E - the element type
All Implemented Interfaces:
ImmutableAddOnlySet<E>

public abstract class ChampAddOnlySet<E> extends Object implements ImmutableAddOnlySet<E>
Implements the ImmutableAddOnlySet interface using a Compressed Hash-Array Mapped Prefix-tree (CHAMP).

Performance characteristics:

  • add: O(log₃₂ N)

References:

Michael J. Steindorfer (2017). Efficient Immutable Collections.
michael.steindorfer.name
The Capsule Hash Trie Collections Library.
Copyright (c) Michael Steindorfer. BSD-2-Clause License
github.com
  • Method Details

    • of

      public static <E> ChampAddOnlySet<E> of()
      Returns an empty set.
      Type Parameters:
      E - the element type.
      Returns:
      an empty set.
    • of

      @SafeVarargs public static <E> ChampAddOnlySet<E> of(E... elements)
      Returns a set that contains the specified elements.
      Type Parameters:
      E - the element type.
      Parameters:
      elements - the specified elements
      Returns:
      a set of the specified elements.
    • add

      public ChampAddOnlySet<E> add(E key)
      Description copied from interface: ImmutableAddOnlySet
      Returns a copy of this set that contains all elements of this set and also the specified element.
      Specified by:
      add in interface ImmutableAddOnlySet<E>
      Parameters:
      key - an element
      Returns:
      this set if it already contains the element, or a different set with the element added