Class ExpandedNameTable

java.lang.Object
org.htmlunit.xpath.xml.dtm.ref.ExpandedNameTable

public class ExpandedNameTable extends Object
This is a default implementation of a table that manages mappings from expanded names to expandedNameIDs.

%OPT% The performance of the getExpandedTypeID() method is very important to DTM building. To get the best performance out of this class, we implement a simple hash algorithm directly into this class, instead of using the inefficient java.util.Hashtable. The code for the get and put operations are combined in getExpandedTypeID() method to share the same hash calculation code. We only need to implement the rehash() interface which is used to expand the hash table.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
    Inner class which represents a hash table entry.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    (package private) final ExtendedType
    Workspace for lookup.
    private int
    The capacity of the hash table, i.e.
    private static final ExtendedType[]
    The array to store the default extended types.
    private ExtendedType[]
    Array of extended types for this document
    private static final int
    The initial capacity of the hash table.
    private static final int
    The initial size of the m_extendedTypes array
    private static final float
    The default load factor of the Hashtable.
    private int
    Next available extended type
    The internal array to store the hash entries.
    private int
    The threshold of the hash table, which is equal to capacity * loadFactor.
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an expanded name table.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    getExpandedTypeID(String namespace, String localName, int type)
    Given an expanded name represented by namespace, local name and node type, return an ID.
    final int
    getLocalNameID(int expandedNameID)
    Given an expanded-name ID, return the local name ID.
    final int
    getNamespaceID(int expandedNameID)
    Given an expanded-name ID, return the namespace URI ID.
    final short
    getType(int expandedNameID)
    Given an expanded-name ID, return the local name ID.
    private void
    Initialize the vector of extended types with the basic DOM node types.
    private void
    Increases the capacity of and internally reorganizes the hashtable, in order to accommodate and access its entries more efficiently.

    Methods inherited from class java.lang.Object

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

    • m_extendedTypes

      private ExtendedType[] m_extendedTypes
      Array of extended types for this document
    • m_initialSize

      private static final int m_initialSize
      The initial size of the m_extendedTypes array
      See Also:
    • m_nextType

      private int m_nextType
      Next available extended type
    • ELEMENT

      public static final int ELEMENT
      See Also:
    • ATTRIBUTE

      public static final int ATTRIBUTE
      See Also:
    • NAMESPACE

      public static final int NAMESPACE
      See Also:
    • hashET

      final ExtendedType hashET
      Workspace for lookup. NOT THREAD SAFE!
    • m_defaultExtendedTypes

      private static final ExtendedType[] m_defaultExtendedTypes
      The array to store the default extended types.
    • m_loadFactor

      private static final float m_loadFactor
      The default load factor of the Hashtable. This is used to calcualte the threshold.
      See Also:
    • m_initialCapacity

      private static final int m_initialCapacity
      The initial capacity of the hash table. Use a bigger number to avoid the cost of expanding the table.
      See Also:
    • m_capacity

      private int m_capacity
      The capacity of the hash table, i.e. the size of the internal HashEntry array.
    • m_threshold

      private int m_threshold
      The threshold of the hash table, which is equal to capacity * loadFactor. If the number of entries in the hash table is bigger than the threshold, the hash table needs to be expanded.
    • m_table

      private ExpandedNameTable.HashEntry[] m_table
      The internal array to store the hash entries. Each array member is a slot for a hash bucket.
  • Constructor Details

    • ExpandedNameTable

      public ExpandedNameTable()
      Create an expanded name table.
  • Method Details

    • initExtendedTypes

      private void initExtendedTypes()
      Initialize the vector of extended types with the basic DOM node types.
    • getExpandedTypeID

      public int getExpandedTypeID(String namespace, String localName, int type)
      Given an expanded name represented by namespace, local name and node type, return an ID. If the expanded-name does not exist in the internal tables, the entry will be created, and the ID will be returned. Any additional nodes that are created that have this expanded name will use this ID.
      Parameters:
      namespace - The namespace
      localName - The local name
      type - The node type
      Returns:
      the expanded-name id of the node.
    • rehash

      private void rehash()
      Increases the capacity of and internally reorganizes the hashtable, in order to accommodate and access its entries more efficiently. This method is called when the number of keys in the hashtable exceeds this hashtable's capacity and load factor.
    • getLocalNameID

      public final int getLocalNameID(int expandedNameID)
      Given an expanded-name ID, return the local name ID.
      Parameters:
      expandedNameID - an ID that represents an expanded-name.
      Returns:
      The id of this local name.
    • getNamespaceID

      public final int getNamespaceID(int expandedNameID)
      Given an expanded-name ID, return the namespace URI ID.
      Parameters:
      expandedNameID - an ID that represents an expanded-name.
      Returns:
      The id of this namespace.
    • getType

      public final short getType(int expandedNameID)
      Given an expanded-name ID, return the local name ID.
      Parameters:
      expandedNameID - an ID that represents an expanded-name.
      Returns:
      The id of this local name.