public class CompactHeapStringList extends Object implements List<String>
List<String>
that stores all contents in a single char[], to avoid the GC load for a large number of String
objects.
Some restrictions to be aware of with the current implementation:
- The list is intended to be write-once (append only), except for clear() operations. That is: new Strings can be added
at the end, but they cannot be replaced or removed.
- There is a limit of a maximum of Integer.MAX_VALUE
/2 = 1073741823 Strings
- There is a limit of the maximum total characters of Integer.MAX_VALUE
(i.e., 2147483647 chars). This corresponds
to a maximum of approximately 4GB of Strings.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_INTEGER_REALLOCATION_BLOCK_SIZE_BYTES |
static int |
DEFAULT_REALLOCATION_BLOCK_SIZE_BYTES |
Constructor and Description |
---|
CompactHeapStringList() |
CompactHeapStringList(int reallocationBlockSizeBytes,
int intReallocationBlockSizeBytes) |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
String element) |
boolean |
add(String s) |
boolean |
addAll(Collection<? extends String> c) |
boolean |
addAll(int index,
Collection<? extends String> c) |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(Object o) |
String |
get(int index) |
int |
indexOf(Object o) |
boolean |
isEmpty() |
Iterator<String> |
iterator() |
int |
lastIndexOf(Object o) |
ListIterator<String> |
listIterator() |
ListIterator<String> |
listIterator(int index) |
String |
remove(int index) |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
String |
set(int index,
String element) |
int |
size() |
List<String> |
subList(int fromIndex,
int toIndex) |
String[] |
toArray() |
<T> T[] |
toArray(T[] a) |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
hashCode, replaceAll, sort, spliterator
parallelStream, removeIf, stream
public static final int DEFAULT_REALLOCATION_BLOCK_SIZE_BYTES
public static final int DEFAULT_INTEGER_REALLOCATION_BLOCK_SIZE_BYTES
public CompactHeapStringList()
public CompactHeapStringList(int reallocationBlockSizeBytes, int intReallocationBlockSizeBytes)
reallocationBlockSizeBytes
- Number of bytes by which to increase the char[], when allocating a new storage arrayintReallocationBlockSizeBytes
- Number of bytes by which to increase the int[], when allocating a new storage arraypublic int size()
public boolean isEmpty()
public boolean contains(Object o)
public String[] toArray()
public <T> T[] toArray(T[] a)
public boolean add(String s)
public boolean remove(Object o)
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<String>
containsAll
in interface List<String>
public boolean addAll(Collection<? extends String> c)
public boolean addAll(int index, Collection<? extends String> c)
public boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public void clear()
public int lastIndexOf(Object o)
lastIndexOf
in interface List<String>
public ListIterator<String> listIterator()
listIterator
in interface List<String>
public ListIterator<String> listIterator(int index)
listIterator
in interface List<String>
Copyright © 2017. All rights reserved.