public class PackedSymbolList extends AbstractSymbolList implements Serializable
A SymbolList that stores symbols as bit-patterns in an array of longs.
Bit-packed symbol lists are space efficient compared to the usual pointer storage model employed by implementations like SimpleSymbolList. This comes at the cost of encoding/decoding symbols from the storage. In practice, the decrease in memory when storing large sequences makes applications go quicker because of issues like page swapping.
Symbols can be mapped to and from bit-patterns. The Pattern interface encapsulates this. A SymbolList can then be stored by writing these bit-patterns into memory. This implementation stores the bits in the long elements of an array. The first symbol will be packed into bits 0 through packing.wordLength()-1 of the long at index 0.
SymbolList symL = ...; SymbolList packed = new PackedSymbolList( PackingFactory.getPacking(symL.getAlphabet(), true), symL );
AbstractSymbolList.EditScreener, AbstractSymbolList.EditTranslater
EDIT, EMPTY_LIST
Constructor and Description |
---|
PackedSymbolList(Packing packing,
long[] syms,
int length)
Create a new PackedSymbolList directly from a bit pattern.
|
PackedSymbolList(Packing packing,
Symbol[] symbols,
int length,
Alphabet alfa)
Create a new PackedSymbolList from an array of Symbols.
|
PackedSymbolList(Packing packing,
SymbolList symList)
Create a new PackedSymbolList as a packed copy of another symbol list.
|
Modifier and Type | Method and Description |
---|---|
Alphabet |
getAlphabet()
The alphabet that this SymbolList is over.
|
long[] |
getSyms()
Return the long array within which the symbols are bit-packed.
|
int |
length()
The number of symbols in this SymbolList.
|
Symbol |
symbolAt(int indx)
Return the symbol at index, counting from 1.
|
edit, equals, hashCode, iterator, seqString, subList, subStr, toList, toString
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
public PackedSymbolList(Packing packing, long[] syms, int length)
Create a new PackedSymbolList directly from a bit pattern.
Warning: This is a risky developer method. You must be sure that the syms array is packed in a way that is consistent with the packing. Also, it is your responsibility to ensure that the length is sensible.
packing
- the Packing usedsyms
- a long array containing already packed symbolslength
- the length of the sequence packed in symbolspublic PackedSymbolList(Packing packing, SymbolList symList) throws IllegalAlphabetException
Create a new PackedSymbolList as a packed copy of another symbol list.
This will create a new and independent symbol list that is a copy of the symbols in symList. Both lists can be modified independently.
packing
- the way to bit-pack symbolssymList
- the SymbolList to copyIllegalAlphabetException
public PackedSymbolList(Packing packing, Symbol[] symbols, int length, Alphabet alfa) throws IllegalAlphabetException, IllegalArgumentException
Create a new PackedSymbolList from an array of Symbols.
This will create a new and independent SymbolList formed from the the symbol array.
packing
- the way to bit-pack symbolssymbols
- an array of Symbolslength
- the number of Symbols to process from symbolsalfa
- the alphabet from which the Symbols are drawnIllegalAlphabetException
IllegalArgumentException
public Alphabet getAlphabet()
SymbolList
Every symbol within this SymbolList is a member of this alphabet.
alphabet.contains(symbol) == true
for each symbol that is within this sequence.
getAlphabet
in interface SymbolList
public int length()
SymbolList
length
in interface SymbolList
public Symbol symbolAt(int indx)
SymbolList
symbolAt
in interface SymbolList
indx
- the offset into this SymbolListpublic long[] getSyms()
Return the long array within which the symbols are bit-packed.
Warning: This is a risky developer method. This is the actual array that this object uses to store the bits representing symbols. You should not modify this in any way. If you do, you will modify the symbols returned by symbolAt(). This methd is provided primarily as an easy way for developers to extract the bit pattern for storage in such a way as it could be fetched later and fed into the appropriate constructor.
Copyright © 2014 BioJava. All rights reserved.