Package org.snpsift.annotate.mem.arrays
Class StringArray
java.lang.Object
org.snpsift.annotate.mem.arrays.StringArrayBase
org.snpsift.annotate.mem.arrays.StringArray
- All Implemented Interfaces:
Serializable
,Iterable<String>
Implement a memory efficient array of strings
It only stores bytes (i.e. UTF-8 encoding) and uses a single byte to mark the end of a string ('\0')
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]
protected int[]
static final int
protected int
Fields inherited from class org.snpsift.annotate.mem.arrays.StringArrayBase
currentIndex
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionget
(int i) Get the string at array index 'i'int
static StringArray
Create a StringArray from an array of stringsstatic StringArray
of
(Collection<String> strings) Create a StringArray from a collection of stringsint
Add a string to the array WARNING: Typically you use either 'add' or 'set', but not bothint
size()
Size of the data array (capacity of number of bytes)long
Memory size of this object (approximate size in bytes)static int
Calculate the size of a string in memorystatic int
static int
sizeOf
(Collection<String> strings) toString()
Methods inherited from class org.snpsift.annotate.mem.arrays.StringArrayBase
add, iterator, length
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
MAX_NUM_STRING_TO_SHOW
public static final int MAX_NUM_STRING_TO_SHOW- See Also:
-
data
protected byte[] data -
index2offset
protected int[] index2offset -
offset
protected int offset
-
-
Constructor Details
-
StringArray
public StringArray(int numElements, int size) Constructor- Parameters:
numElements
- : Number of elements in the arraysize
- : Initial size of the array
-
-
Method Details
-
sizeOf
Calculate the size of a string in memory -
sizeOf
-
sizeOf
-
of
Create a StringArray from an array of strings -
of
Create a StringArray from a collection of strings -
get
Get the string at array index 'i'- Specified by:
get
in classStringArrayBase
-
getOffset
public int getOffset() -
set
Add a string to the array WARNING: Typically you use either 'add' or 'set', but not both- Specified by:
set
in classStringArrayBase
-
size
public int size()Size of the data array (capacity of number of bytes)- Specified by:
size
in classStringArrayBase
-
sizeBytes
public long sizeBytes()Memory size of this object (approximate size in bytes)- Specified by:
sizeBytes
in classStringArrayBase
-
toString
-