Class MutableChampSet<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,E>
org.jhotdraw8.icollection.MutableChampSet<E>
Type Parameters:
E - the element type
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>, ReadOnlyCollection<E>, ReadOnlySet<E>

public class MutableChampSet<E> extends org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,E>
Implements the Set interface using a Compressed Hash-Array Mapped Prefix-tree (CHAMP).

Features:

  • supports up to 231 - 1 elements
  • allows null elements
  • is mutable
  • is not thread-safe
  • does not guarantee a specific iteration order

Performance characteristics:

  • add: O(log₃₂ N)
  • remove: O(log₃₂ N)
  • contains: O(log₃₂ N)
  • toImmutable: O(1) + O(log₃₂ N) distributed across subsequent updates in this set
  • clone: O(1) + O(log₃₂ N) distributed across subsequent updates in this set and in the clone
  • iterator.next: O(1)

Implementation details:

See description at ChampSet.

References:

Portions of the code in this class has been derived from 'The Capsule Hash Trie Collections Library'.

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
See Also:
  • Constructor Details

    • MutableChampSet

      public MutableChampSet()
      Constructs a new empty set.
    • MutableChampSet

      public MutableChampSet(Iterable<? extends E> c)
      Constructs a set containing the elements in the specified iterable.
      Parameters:
      c - an iterable
  • Method Details

    • add

      public boolean add(@Nullable E e)
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface Set<E>
      Overrides:
      add in class AbstractCollection<E>
    • addAll

      public boolean addAll(Iterable<? extends E> c)
      Adds all specified elements that are not already in this set.
      Overrides:
      addAll in class org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,E>
      Parameters:
      c - an iterable of elements
      Returns:
      true if this set changed
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface Set<E>
      Overrides:
      removeAll in class org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,E>
    • removeAll

      public boolean removeAll(Iterable<?> c)
      Description copied from class: org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet
      Removes all specified elements that are in this set.
      Overrides:
      removeAll in class org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,E>
      Parameters:
      c - an iterable of elements
      Returns:
      true if this set changed
    • retainAll

      public boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<E>
      Specified by:
      retainAll in interface Set<E>
      Overrides:
      retainAll in class AbstractCollection<E>
    • retainAll

      public boolean retainAll(Iterable<?> c)
      Description copied from class: org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet
      Retains all specified elements that are in this set.
      Overrides:
      retainAll in class org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,E>
      Parameters:
      c - an iterable of elements
      Returns:
      true if this set changed
    • clear

      public void clear()
      Removes all elements from this set.
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface Set<E>
      Overrides:
      clear in class AbstractCollection<E>
    • clone

      public MutableChampSet<E> clone()
      Returns a shallow copy of this set.
      Overrides:
      clone in class org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,E>
    • contains

      public boolean contains(@Nullable Object o)
      Description copied from interface: ReadOnlyCollection
      Returns true if this collection contains the specified object.
      Specified by:
      contains in interface Collection<E>
      Specified by:
      contains in interface ReadOnlyCollection<E>
      Specified by:
      contains in interface Set<E>
      Overrides:
      contains in class AbstractCollection<E>
      Parameters:
      o - an object
      Returns:
      true if this collection contains the specified object
    • iterator

      public Iterator<E> iterator()
      Description copied from interface: ReadOnlyCollection
      Returns an iterator over the elements in this collection.
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface ReadOnlyCollection<E>
      Specified by:
      iterator in interface Set<E>
      Specified by:
      iterator in class org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,E>
      Returns:
      an iterator
    • spliterator

      public Spliterator<E> spliterator()
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface Set<E>
      Overrides:
      remove in class AbstractCollection<E>
    • toImmutable

      public ChampSet<E> toImmutable()
      Returns an immutable copy of this set.
      Returns:
      an immutable copy