-
- Type Parameters:
E- the type of elements in this list
- All Superinterfaces:
Collection<E>,Iterable<E>,List<E>
- All Known Implementing Classes:
SynchronizedChunkyList,UnsynchronizedChunkyList
public interface ChunkyList<E> extends List<E>
AListbacked by a chain of fixed-size arrays (Chunks), also known as an unrolled linked list.In addition to the standard
Listcontract, this interface exposes chunk-specific configuration: chunk size, growing and shrinking strategies, and areorganize()operation to compact sparsely filled chunks.Two implementations are provided:
UnsynchronizedChunkyList— not thread-safe, fail-fast iterators.SynchronizedChunkyList— thread-safe, backed by aReentrantReadWriteLock.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classChunkyList.GrowingStrategyStrategy used when inserting an element into a full chunk.static classChunkyList.ShrinkingStrategyStrategy used after removing an element from a chunk.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intgetChunkSize()Returns the chunk size of this list.ChunkyList.GrowingStrategygetCurrentGrowingStrategy()Returns the current growing strategy.ChunkyList.ShrinkingStrategygetCurrentShrinkingStrategy()Returns the current shrinking strategy.voidreorganize()Reorganizes the list by redistributing all elements into chunks of exactlychunkSizeelements (except possibly the last one).voidsetCurrentGrowingStrategy(ChunkyList.GrowingStrategy growingStrategy)Sets the growing strategy.voidsetCurrentShrinkingStrategy(ChunkyList.ShrinkingStrategy shrinkingStrategy)Sets the shrinking strategy.voidsetStrategies(ChunkyList.GrowingStrategy growingStrategy, ChunkyList.ShrinkingStrategy shrinkingStrategy)Sets both strategies atomically.-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
-
-
-
-
Method Detail
-
getChunkSize
int getChunkSize()
Returns the chunk size of this list.- Returns:
- the chunk size
-
getCurrentGrowingStrategy
ChunkyList.GrowingStrategy getCurrentGrowingStrategy()
Returns the current growing strategy.- Returns:
- the current growing strategy
- See Also:
ChunkyList.GrowingStrategy
-
setCurrentGrowingStrategy
void setCurrentGrowingStrategy(ChunkyList.GrowingStrategy growingStrategy)
Sets the growing strategy. The new strategy applies immediately to all subsequent insertions.- Parameters:
growingStrategy- the new growing strategy- See Also:
ChunkyList.GrowingStrategy
-
getCurrentShrinkingStrategy
ChunkyList.ShrinkingStrategy getCurrentShrinkingStrategy()
Returns the current shrinking strategy.- Returns:
- the current shrinking strategy
- See Also:
ChunkyList.ShrinkingStrategy
-
setCurrentShrinkingStrategy
void setCurrentShrinkingStrategy(ChunkyList.ShrinkingStrategy shrinkingStrategy)
Sets the shrinking strategy. The new strategy applies immediately to all subsequent removals.- Parameters:
shrinkingStrategy- the new shrinking strategy- See Also:
ChunkyList.ShrinkingStrategy
-
setStrategies
void setStrategies(ChunkyList.GrowingStrategy growingStrategy, ChunkyList.ShrinkingStrategy shrinkingStrategy)
Sets both strategies atomically. Prefer this method over callingsetCurrentGrowingStrategy(fr.dufrenoy.util.ChunkyList.GrowingStrategy)andsetCurrentShrinkingStrategy(fr.dufrenoy.util.ChunkyList.ShrinkingStrategy)separately when both need to change together, as it guarantees no operation can observe an inconsistent intermediate state.- Parameters:
growingStrategy- the new growing strategyshrinkingStrategy- the new shrinking strategy
-
reorganize
void reorganize()
Reorganizes the list by redistributing all elements into chunks of exactlychunkSizeelements (except possibly the last one). The order of elements is preserved.This is useful after many removals have left chunks sparsely filled.
-
-