Package com.fasterxml.jackson.core.sym
Class ByteQuadsCanonicalizer
- java.lang.Object
-
- com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer
-
public final class ByteQuadsCanonicalizer extends java.lang.ObjectReplacement forBytesToNameCanonicalizerwhich aims at more localized memory access due to flattening of name quad data. Performance improvement modest for simple JSON document data binding (maybe 3%), but should help more for larger symbol tables, or for binary formats like Smile.Hash area is divided into 4 sections:
- Primary area (1/2 of total size), direct match from hash (LSB)
- Secondary area (1/4 of total size), match from
hash (LSB) >> 1 - Tertiary area (1/8 of total size), match from
hash (LSB) >> 2 - Spill-over area (remaining 1/8) with linear scan, insertion order
ints, where 1 - 3 ints contain 1 - 12 UTF-8 encoded bytes of name (null-padded), and last int is offset in_namesthat contains actual name Strings.- Since:
- 2.6
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringaddName(java.lang.String name, int q1)java.lang.StringaddName(java.lang.String name, int[] q, int qlen)java.lang.StringaddName(java.lang.String name, int q1, int q2)java.lang.StringaddName(java.lang.String name, int q1, int q2, int q3)intbucketCount()intcalcHash(int q1)intcalcHash(int[] q, int qlen)intcalcHash(int q1, int q2)intcalcHash(int q1, int q2, int q3)static ByteQuadsCanonicalizercreateRoot()Factory method to call to create a symbol table instance with a randomized seed value.java.lang.StringfindName(int q1)java.lang.StringfindName(int[] q, int qlen)java.lang.StringfindName(int q1, int q2)java.lang.StringfindName(int q1, int q2, int q3)inthashSeed()booleanisCanonicalizing()ByteQuadsCanonicalizermakeChild(int flags)Factory method used to create actual symbol table instance to use for parsing.ByteQuadsCanonicalizermakeChildOrPlaceholder(int flags)Method similar tomakeChild(int)but one that only creates real instance ofJsonFactory.Feature.CANONICALIZE_FIELD_NAMESis enabled: otherwise a "bogus" instance is created.booleanmaybeDirty()Method called to check to quickly see if a child symbol table may have gotten additional entries.intprimaryCount()Method mostly needed by unit tests; calculates number of entries that are in the primary slot set.voidrelease()Method called by the using code to indicate it is done with this instance.intsecondaryCount()Method mostly needed by unit tests; calculates number of entries in secondary bucketsintsize()intspilloverCount()Method mostly needed by unit tests; calculates number of entries in shared spill-over areainttertiaryCount()Method mostly needed by unit tests; calculates number of entries in tertiary bucketsjava.lang.StringtoString()inttotalCount()
-
-
-
Method Detail
-
createRoot
public static ByteQuadsCanonicalizer createRoot()
Factory method to call to create a symbol table instance with a randomized seed value.- Returns:
- Root instance to use for constructing new child instances
-
makeChild
public ByteQuadsCanonicalizer makeChild(int flags)
Factory method used to create actual symbol table instance to use for parsing.- Parameters:
flags- Bit flags of activeJsonFactory.Features enabled.- Returns:
- Actual canonicalizer instance that can be used by a parser
-
makeChildOrPlaceholder
public ByteQuadsCanonicalizer makeChildOrPlaceholder(int flags)
Method similar tomakeChild(int)but one that only creates real instance ofJsonFactory.Feature.CANONICALIZE_FIELD_NAMESis enabled: otherwise a "bogus" instance is created.- Parameters:
flags- Bit flags of activeJsonFactory.Features enabled.- Returns:
- Actual canonicalizer instance that can be used by a parser if (and only if) canonicalization is enabled; otherwise a non-null "placeholder" instance.
- Since:
- 2.13
-
release
public void release()
Method called by the using code to indicate it is done with this instance. This lets instance merge accumulated changes into parent (if need be), safely and efficiently, and without calling code having to know about parent information.
-
size
public int size()
- Returns:
- Number of symbol entries contained by this canonicalizer instance
-
bucketCount
public int bucketCount()
- Returns:
- number of primary slots table has currently
-
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.- Returns:
- Whether main hash area has been modified
-
hashSeed
public int hashSeed()
-
isCanonicalizing
public boolean isCanonicalizing()
- Returns:
- True for "real", canonicalizing child tables; false for root table as well as placeholder "child" tables.
- Since:
- 2.13
-
primaryCount
public int primaryCount()
Method mostly needed by unit tests; calculates number of entries that are in the primary slot set. These are "perfect" entries, accessible with a single lookup- Returns:
- Number of entries in the primary hash area
-
secondaryCount
public int secondaryCount()
Method mostly needed by unit tests; calculates number of entries in secondary buckets- Returns:
- Number of entries in the secondary hash area
-
tertiaryCount
public int tertiaryCount()
Method mostly needed by unit tests; calculates number of entries in tertiary buckets- Returns:
- Number of entries in the tertiary hash area
-
spilloverCount
public int spilloverCount()
Method mostly needed by unit tests; calculates number of entries in shared spill-over area- Returns:
- Number of entries in the linear spill-over areay
-
totalCount
public int totalCount()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
findName
public java.lang.String findName(int q1)
-
findName
public java.lang.String findName(int q1, int q2)
-
findName
public java.lang.String findName(int q1, int q2, int q3)
-
findName
public java.lang.String findName(int[] q, int qlen)
-
addName
public java.lang.String addName(java.lang.String name, int q1) throws StreamConstraintsException- Parameters:
name- Name to addq1- Quad representation of the name- Returns:
- name (possibly interned)
- Throws:
StreamConstraintsException- if the constraint exceptions
-
addName
public java.lang.String addName(java.lang.String name, int q1, int q2) throws StreamConstraintsException- Parameters:
name- Name to addq1- First quad of name representationq2- Second quad of name representation- Returns:
- name (possibly interned)
- Throws:
StreamConstraintsException- if the constraint exceptions
-
addName
public java.lang.String addName(java.lang.String name, int q1, int q2, int q3) throws StreamConstraintsException- Parameters:
name- Name to addq1- First quad of name representationq2- Second quad of name representationq3- Third quad of name representation- Returns:
- name (possibly interned)
- Throws:
StreamConstraintsException- if the constraint exceptions
-
addName
public java.lang.String addName(java.lang.String name, int[] q, int qlen) throws StreamConstraintsException- Parameters:
name- Name to addq- Quads of name representationqlen- Number of quads inq- Returns:
- name (possibly interned)
- Throws:
StreamConstraintsException- if the constraint exceptions
-
calcHash
public int calcHash(int q1)
-
calcHash
public int calcHash(int q1, int q2)
-
calcHash
public int calcHash(int q1, int q2, int q3)
-
calcHash
public int calcHash(int[] q, int qlen)- Parameters:
q- int arrayqlen- length- Returns:
- hash
- Throws:
java.lang.IllegalArgumentException- ifqlenis less than 4
-
-