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:
-
Field Summary
Fields inherited from class org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet
modCount, owner, root, size -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new empty set.MutableChampSet(@NonNull Iterable<? extends E> c) Constructs a set containing the elements in the specified iterable. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanAdds all specified elements that are not already in this set.voidclear()Removes all elements from this set.clone()Returns a shallow copy of this set.booleanReturnstrueif this collection contains the specified object.iterator()Returns an iterator over the elements in this collection.booleanbooleanRemoves all specified elements that are in this set.booleanremoveAll(@NonNull Collection<?> c) booleanRetains all specified elements that are in this set.booleanretainAll(@NonNull Collection<?> c) Returns an immutable copy of this set.Methods inherited from class org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet
addAll, equals, getModCount, makeOwner, size, streamMethods inherited from class java.util.AbstractSet
hashCodeMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, toArray, toArray, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, toArrayMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyCollection
asCollection, containsAll, isEmpty, toArray, toArrayMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySet
asSet, characteristics, hashCodeMethods inherited from interface java.util.Set
containsAll, isEmpty, toArray, toArray
-
Constructor Details
-
MutableChampSet
public MutableChampSet()Constructs a new empty set. -
MutableChampSet
Constructs a set containing the elements in the specified iterable.- Parameters:
c- an iterable
-
-
Method Details
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
addAll
Adds all specified elements that are not already in this set. -
removeAll
-
removeAll
Description copied from class:org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSetRemoves all specified elements that are in this set. -
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceSet<E>- Overrides:
retainAllin classAbstractCollection<E>
-
retainAll
Description copied from class:org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSetRetains all specified elements that are in this set. -
clear
public void clear()Removes all elements from this set.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
clone
Returns a shallow copy of this set. -
contains
Description copied from interface:ReadOnlyCollectionReturnstrueif this collection contains the specified object.- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceReadOnlyCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>- Parameters:
o- an object- Returns:
trueif this collection contains the specified object
-
iterator
Description copied from interface:ReadOnlyCollectionReturns an iterator over the elements in this collection.- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceReadOnlyCollection<E>- Specified by:
iteratorin interfaceSet<E>- Specified by:
iteratorin classorg.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,E> - Returns:
- an iterator
-
spliterator
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
toImmutable
Returns an immutable copy of this set.- Returns:
- an immutable copy
-