Package com.fasterxml.aalto.out
Class WNameTable
java.lang.Object
com.fasterxml.aalto.util.NameTable
com.fasterxml.aalto.out.WNameTable
This is a symbol table implementation used for storing byte-based
WName
s.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int
(package private) static final int
Bucket index is 8 bits, and value 0 is reserved to represent 'empty' status.private int
Total number of WNames in collision buckets (included inmCount
along with primary entries)private int
Index of the first unused collision bucket entry (== size of the used portion of collision list): less than or equal to 0xFF (255), since max number of entries is 255 (8-bit, minus 0 used as 'empty' marker)private WNameTable.Bucket[]
Array of heads of collision bucket chains; size dynamicallyprivate boolean
Flag that indicates whether underlying data structures for the collision list are shared or not.private int
Total number of WNames in the symbol table(package private) static final int
private int[]
Array of 2^N size, which contains combination of 24-bits of hash (0 to indicate 'empty' slot), and 8-bit collision bucket index (0 to indicate empty collision bucket chain; otherwise subtract one from index)private int
Mask used to truncate 32-bit hash value to current hash array size; essentially, hash array size - 1 (since hash array sizes are 2^N).private boolean
Flag that indicates whether underlying data structures for the main hash area are shared or not.private WName[]
Array that containsWName
instances matching entries inmMainHash
.private boolean
(package private) final WNameFactory
private boolean
This flag is set if, after adding a new entry, it is deemed that a rehash is warranted if any more entries are to be added.(package private) final WNameTable
Parent reference is needed to be able to merge new symbols if and as necessary -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
WNameTable
(int hashSize) private
WNameTable
(WNameTable parent, WNameFactory f) Constructor used when creating a child instance -
Method Summary
Modifier and TypeMethodDescriptionprivate void
protected WNameTable
private void
private int
Method called to find the best bucket to spill a WName over to: usually the first bucket that has only one entry, but in general first one of the buckets with least number of entriesfindSymbol
(String localName) findSymbol
(String prefix, String localName) Finds and returns name matching the specified symbol, if such name already exists in the table; or if not, creates name object, adds to the table, and returns it.void
boolean
Method called to check to quickly see if a child symbol table may have gotten additional entries.private boolean
mergeFromChild
(WNameTable child) boolean
void
nuke()
Method used by test code, to reset state of the name table.private void
rehash()
int
size()
toString()
private void
private void
Method that needs to be called, if the main hash structure is (may be) shared.private void
-
Field Details
-
MIN_HASH_SIZE
static final int MIN_HASH_SIZE- See Also:
-
INITIAL_COLLISION_LEN
static final int INITIAL_COLLISION_LEN- See Also:
-
LAST_VALID_BUCKET
static final int LAST_VALID_BUCKETBucket index is 8 bits, and value 0 is reserved to represent 'empty' status.- See Also:
-
mNameFactory
-
mParent
Parent reference is needed to be able to merge new symbols if and as necessary -
mCount
private int mCountTotal number of WNames in the symbol table -
mMainHashMask
private int mMainHashMaskMask used to truncate 32-bit hash value to current hash array size; essentially, hash array size - 1 (since hash array sizes are 2^N). -
mMainHash
private int[] mMainHashArray of 2^N size, which contains combination of 24-bits of hash (0 to indicate 'empty' slot), and 8-bit collision bucket index (0 to indicate empty collision bucket chain; otherwise subtract one from index) -
mMainNames
Array that containsWName
instances matching entries inmMainHash
. Contains nulls for unused entries. -
mCollList
Array of heads of collision bucket chains; size dynamically -
mCollCount
private int mCollCountTotal number of WNames in collision buckets (included inmCount
along with primary entries) -
mCollEnd
private int mCollEndIndex of the first unused collision bucket entry (== size of the used portion of collision list): less than or equal to 0xFF (255), since max number of entries is 255 (8-bit, minus 0 used as 'empty' marker) -
mNeedRehash
private transient boolean mNeedRehashThis flag is set if, after adding a new entry, it is deemed that a rehash is warranted if any more entries are to be added.
-
-
Constructor Details
-
WNameTable
protected WNameTable(int hashSize) -
WNameTable
Constructor used when creating a child instance
-
-
Method Details
-
createChild
-
mergeToParent
public boolean mergeToParent() -
mergeFromChild
-
nuke
public void nuke()Method used by test code, to reset state of the name table. -
size
public int size() -
maybeDirty
public boolean maybeDirty()Method called to check to quickly see if a child symbol table may have gotten additional entries. Used for checking to see if a child table should be merged into shared table.- Specified by:
maybeDirty
in classNameTable
-
findSymbol
- Throws:
XMLStreamException
-
findSymbol
Finds and returns name matching the specified symbol, if such name already exists in the table; or if not, creates name object, adds to the table, and returns it.- Throws:
XMLStreamException
-
toString
-
toDebugString
-
addSymbol
-
rehash
private void rehash() -
findBestBucket
private int findBestBucket()Method called to find the best bucket to spill a WName over to: usually the first bucket that has only one entry, but in general first one of the buckets with least number of entries -
expandCollision
private void expandCollision()
-