Package io.protostuff

Class GraphProtostuffOutput.IdentityMap

java.lang.Object
io.protostuff.GraphProtostuffOutput.IdentityMap
Enclosing class:
GraphProtostuffOutput

private static final class GraphProtostuffOutput.IdentityMap extends Object
A trimed-down version of IdentityHashMap w/c caters to the specific needs of
invalid reference
GraphOutput
.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    The initial capacity used by the no-args constructor.
    private static final int
    The maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments.
    private static final int
    The minimum capacity, used if a lower value is implicitly specified by either of the constructors with arguments.
    private int
    The number of key-value mappings contained in this identity hash map.
    private Object[]
    The table, resized as necessary.
    private int
    The next size value at which to resize (capacity * load factor).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new, empty identity hash map with a default expected maximum size (21).
    IdentityMap(int expectedMaxSize)
    Constructs a new, empty map with the specified expected maximum size.
  • Method Summary

    Modifier and Type
    Method
    Description
    private int
    capacity(int expectedMaxSize)
    Returns the appropriate capacity for the specified expected maximum size.
    private static int
    hash(Object x, int length)
    Returns index for Object x.
    private void
    init(int initCapacity)
    Initializes object to be an empty map with the specified initial capacity, which is assumed to be a power of two between MINIMUM_CAPACITY and MAXIMUM_CAPACITY inclusive.
    private static int
    nextKeyIndex(int i, int len)
    Circularly traverses table of size len.
    private void
    resize(int newCapacity)
    Resize the table to hold given capacity.
    boolean
    shouldIncrement(int value, Object k, WriteSession output, int fieldNumber)
    Returns true if the provided int should increment(unique index id).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_CAPACITY

      private static final int DEFAULT_CAPACITY
      The initial capacity used by the no-args constructor. MUST be a power of two. The value 32 corresponds to the (specified) expected maximum size of 21, given a load factor of 2/3.
      See Also:
    • MINIMUM_CAPACITY

      private static final int MINIMUM_CAPACITY
      The minimum capacity, used if a lower value is implicitly specified by either of the constructors with arguments. The value 4 corresponds to an expected maximum size of 2, given a load factor of 2/3. MUST be a power of two.
      See Also:
    • MAXIMUM_CAPACITY

      private static final int MAXIMUM_CAPACITY
      The maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments. MUST be a power of two invalid input: '<'= 1invalid input: '<'invalid input: '<'29.
      See Also:
    • table

      private transient Object[] table
      The table, resized as necessary. Length MUST always be a power of two.
    • size

      private int size
      The number of key-value mappings contained in this identity hash map.
    • threshold

      private transient int threshold
      The next size value at which to resize (capacity * load factor).
  • Constructor Details

    • IdentityMap

      public IdentityMap()
      Constructs a new, empty identity hash map with a default expected maximum size (21).
    • IdentityMap

      public IdentityMap(int expectedMaxSize)
      Constructs a new, empty map with the specified expected maximum size. Putting more than the expected number of key-value mappings into the map may cause the internal data structure to grow, which may be somewhat time-consuming.
      Parameters:
      expectedMaxSize - the expected maximum size of the map
      Throws:
      IllegalArgumentException - if expectedMaxSize is negative
  • Method Details

    • capacity

      private int capacity(int expectedMaxSize)
      Returns the appropriate capacity for the specified expected maximum size. Returns the smallest power of two between MINIMUM_CAPACITY and MAXIMUM_CAPACITY, inclusive, that is greater than (3 * expectedMaxSize)/2, if such a number exists. Otherwise returns MAXIMUM_CAPACITY. If (3 * expectedMaxSize)/2 is negative, it is assumed that overflow has occurred, and MAXIMUM_CAPACITY is returned.
    • init

      private void init(int initCapacity)
      Initializes object to be an empty map with the specified initial capacity, which is assumed to be a power of two between MINIMUM_CAPACITY and MAXIMUM_CAPACITY inclusive.
    • hash

      private static int hash(Object x, int length)
      Returns index for Object x.
    • nextKeyIndex

      private static int nextKeyIndex(int i, int len)
      Circularly traverses table of size len.
    • shouldIncrement

      public boolean shouldIncrement(int value, Object k, WriteSession output, int fieldNumber) throws IOException
      Returns true if the provided int should increment(unique index id).
      Throws:
      IOException
    • resize

      private void resize(int newCapacity)
      Resize the table to hold given capacity.
      Parameters:
      newCapacity - the new capacity, must be a power of two.