java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,org.jhotdraw8.icollection.impl.champ.SequencedElement<E>>
org.jhotdraw8.icollection.MutableChampVectorSet<E>
- Type Parameters:
E- the element type
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,SequencedCollection<E>,SequencedSet<E>,Set<E>,ReadOnlyCollection<E>,ReadOnlySequencedCollection<E>,ReadOnlySequencedSet<E>,ReadOnlySet<E>
public class MutableChampVectorSet<E>
extends org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet<E,org.jhotdraw8.icollection.impl.champ.SequencedElement<E>>
implements ReadOnlySequencedSet<E>, SequencedSet<E>
Implements the
SequencedSet interface using a Compressed
Hash-Array Mapped Prefix-tree (CHAMP) and a bit-mapped trie (Vector).
Features:
- supports up to 230 elements
- allows null elements
- is mutable
- is not thread-safe
- iterates in the order, in which elements were inserted
Performance characteristics:
- add: O(1) amortized
- remove: O(1)
- contains: O(1)
- 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 creation: O(1)
- iterator.next: O(1)
- getFirst, getLast: O(1)
Implementation details:
See description at ChampVectorSet.
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
- 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.MutableChampVectorSet(Iterable<? extends E> c) Constructs a set containing the elements in the specifiedIterable. -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidvoidvoidclear()Removes all elements from this set.clone()Returns a shallow copy of this set.booleanReturnstrueif this collection contains the specified object.getFirst()Gets the first element.getLast()Gets the last element.iterator()Returns an iterator over the elements in this collection.Returns a reversed-order view of this set.booleanreversed()Returns an immutable copy of this set.Methods inherited from class org.jhotdraw8.icollection.impl.champ.AbstractMutableChampSet
addAll, addAll, equals, getModCount, makeOwner, removeAll, removeAll, retainAll, size, streamMethods inherited from class java.util.AbstractSet
hashCodeMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyCollection
containsAll, isEmpty, size, stream, toArray, toArrayMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection
asCollectionMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedSet
asSetMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySet
characteristics, equals, hashCode
-
Constructor Details
-
MutableChampVectorSet
public MutableChampVectorSet()Constructs a new empty set. -
MutableChampVectorSet
Constructs a set containing the elements in the specifiedIterable.- Parameters:
c- an iterable
-
-
Method Details
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
addFirst
- Specified by:
addFirstin interfaceSequencedCollection<E>
-
addLast
- Specified by:
addLastin interfaceSequencedCollection<E>
-
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
-
getFirst
Description copied from interface:ReadOnlySequencedCollectionGets the first element.- Specified by:
getFirstin interfaceReadOnlySequencedCollection<E>- Specified by:
getFirstin interfaceSequencedCollection<E>- Returns:
- an element
-
getLast
Description copied from interface:ReadOnlySequencedCollectionGets the last element.- Specified by:
getLastin interfaceReadOnlySequencedCollection<E>- Specified by:
getLastin interfaceSequencedCollection<E>- Returns:
- an element
-
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,org.jhotdraw8.icollection.impl.champ.SequencedElement<E>> - Returns:
- an iterator
-
spliterator
- Specified by:
spliteratorin interfaceCollection<E>- Specified by:
spliteratorin interfaceIterable<E>- Specified by:
spliteratorin interfaceSet<E>
-
readOnlyReversed
Description copied from interface:ReadOnlySequencedSetReturns a reversed-order view of this set. Changes to the underlying set are visible in the reversed view.- Specified by:
readOnlyReversedin interfaceReadOnlySequencedCollection<E>- Specified by:
readOnlyReversedin interfaceReadOnlySequencedSet<E>- Returns:
- a reversed-order view of this set
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
removeFirst
- Specified by:
removeFirstin interfaceSequencedCollection<E>
-
removeLast
- Specified by:
removeLastin interfaceSequencedCollection<E>
-
reversed
- Specified by:
reversedin interfaceSequencedCollection<E>- Specified by:
reversedin interfaceSequencedSet<E>
-
toImmutable
Returns an immutable copy of this set.- Returns:
- an immutable copy
-