Class BitList<E>
- Type Parameters:
E-
- All Implemented Interfaces:
Cloneable,Iterable<E>,Collection<E>,List<E>,SequencedCollection<E>
originList: Initial elements of the list. This list will not be changed in modification actions (expect clear all). rootSet: A bitMap to store the indexes of originList are still exist. Most of the modification actions are operated on this bitMap. tailList: An additional list for BitList. Worked when adding totally new elements to list. These elements will be appended to the last of the BitList.
An example of BitList: originList: A B C D E (5 elements) rootSet: x v x v v 0 1 0 1 1 (5 elements) tailList: F G H (3 elements) resultList: B D E F G H (6 elements)
- Since:
- 3.0
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanIf the element to added is appeared in originList even if it is not in rootSet, directly set its index in rootSet to true.booleanaddAll(Collection<? extends E> c) voidaddIndex(int index) voidaddToTailList(E e) And operation between two bitList.voidclear()Caution: This operation will clear originList for removing references purpose.clone()booleanstatic <T> BitList<T> get(int index) getByIndex(int index) booleanbooleanindexExist(int index) intbooleanisEmpty()iterator()intlistIterator(int index) remove(int index) booleanIf the element to added is appeared in originList, directly set its index in rootSet to false.intsize()subList(int fromIndex, int toIndex) intMethods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toArray, toArray, toStringMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, containsAll, getFirst, getLast, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Constructor Details
-
BitList
-
BitList
-
BitList
-
BitList
-
-
Method Details
-
getOriginList
-
addIndex
public void addIndex(int index) -
totalSetSize
public int totalSetSize() -
indexExist
public boolean indexExist(int index) -
getByIndex
-
and
And operation between two bitList. Return a new cloned list. TailList in source bitList will be totally saved even if it is not appeared in the target bitList.- Parameters:
target- target bitList- Returns:
- this bitList only contains those elements contain in both two list and source bitList's tailList
-
or
-
hasMoreElementInTailList
public boolean hasMoreElementInTailList() -
getTailList
-
addToTailList
-
randomSelectOne
-
emptyList
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classAbstractCollection<E>
-
iterator
-
add
If the element to added is appeared in originList even if it is not in rootSet, directly set its index in rootSet to true. (This may change the order of elements.)If the element is not contained in originList, allocate tailList and add to tailList.
Notice: It is not recommended adding duplicated element.
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>
-
remove
If the element to added is appeared in originList, directly set its index in rootSet to false. (This may change the order of elements.)If the element is not contained in originList, try to remove from tailList.
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceList<E>- Overrides:
removein classAbstractCollection<E>
-
clear
public void clear()Caution: This operation will clear originList for removing references purpose. This may change the default behaviour when adding new element later.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Overrides:
clearin classAbstractList<E>
-
get
-
remove
-
indexOf
-
addAll
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceList<E>- Overrides:
addAllin classAbstractCollection<E>
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>- Overrides:
lastIndexOfin classAbstractList<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>
-
subList
-
cloneToArrayList
-
clone
-