Package com.oss.asn1

Class DefaultIndex

java.lang.Object
com.oss.asn1.DefaultIndex
All Implemented Interfaces:
Index

public abstract class DefaultIndex extends Object implements Index
This abstract class provides default implementations for most of the methods in the Index interface. To create a concrete Index as a subclass of DefaultIndex you need only provide the implementation for the following method:
int mapKey(AbstractData key);
The default implementation is based on a hash table with direct chaining to resolve collisions. It can be used to index an information object set when the index column does not contain duplicate values. The implementation relies on a concrete subclass to define the mapKey method, that maps a key to an integer in the range 0..N, where N≈M and M is the total number of keys. For example, having:
 ProcedureID ::= SEQUENCE {
     procedureCode INTEGER (0..255),
     ddMode ENUMERATED {tdd, fdd, common}
 }

 NBAP-ELEMENTARY-PROCEDURE ::= CLASS {
     &InitiatingMessage,
     &SuccessfulOutcome OPTIONAL,
     &UnsuccessfulOutcome OPTIONAL,
     &Outcome OPTIONAL,
     &messageDiscriminator MessageDiscriminator,
     &procedureID ProcedureID UNIQUE,
     &criticality Criticality DEFAULT ignore
 }

 NBAP-ELEMENTARY-PROCEDURES NBAP-ELEMENTARY-PROCEDURE ::= {
     <list of information objects>
 }
 
you utilize the DefaultIndex class as follows:
 Mod.nBAP_ELEMENTARY_PROCEDURES.indexByProcedureID(
     new DefaultIndex() {
         public int mapKey(AbstractData key) {
             ProcedureID id = (ProcedureID)key;
             return (int)(id.getProcedureCode() +
                 id.getDdMode().longValue() << 8);
         }
     }
 );
 
Note that this mapKey function utilizes the fact that the value of the index column contains two components: a whole number in the range 0..255 and an ENUMERATED with few enumerators.
Since:
ASN.1/Java 1.4-beta C
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Helper class that implements the Enumeration containing only one element.
  • Constructor Summary

    Constructors
    Constructor
    Description
    The default constructor.
    DefaultIndex(int capacity)
    Create the index with the given capacity and load factor of 3/4.
  • Method Summary

    Modifier and Type
    Method
    Description
    Adds a new information object to the index.
    Looks up the unique information object with the index column matching the key.
    abstract int
    Map the key to the integer in the range 0..N, where N≈M and M is the total number of possible keys.
    int
    Return the size of the longest collision list in the hash table.
    int
    Return the size of the shortest collision list in the hash table.
    int
    Return the number of buckets in the index.
    Removes the information object from the index.
    Resets the index by clearing the underlying hash table.
    int
    Return the number of key/value pairs in the index.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultIndex

      public DefaultIndex()
      The default constructor. Creates index with default capacity of 32 entries and load factor of 3/4.
    • DefaultIndex

      public DefaultIndex(int capacity)
      Create the index with the given capacity and load factor of 3/4. The capacity provided is rounded to the nearest power of two.
      Parameters:
      capacity - the capacity of the index.
  • Method Details

    • mapKey

      public abstract int mapKey(AbstractData key)
      Map the key to the integer in the range 0..N, where N≈M and M is the total number of possible keys. Specific subclasses must implement this method.
      Parameters:
      key - the key to map to the integer code.
      Returns:
      hash code for the key.
    • lookup

      public Enumeration lookup(AbstractData key)
      Looks up the unique information object with the index column matching the key. Implements the Index interface. The Enumeration returned is either empty or contains the only element.
      Specified by:
      lookup in interface Index
      Parameters:
      key - the value of the index column to lookup.
      Returns:
      information objects with index column matching the key.
    • add

      public Index add(AbstractData key, InfoObject value)
      Adds a new information object to the index. Implements the Index interface. Return null if the information object, identified by key already exists.
      Specified by:
      add in interface Index
      Parameters:
      key - the value of the index column of the information object.
      value - the information object to add.
      Returns:
      this on success or null if the information object already exists.
    • remove

      public Index remove(AbstractData key, InfoObject value)
      Removes the information object from the index. Implements the Index interface.
      Specified by:
      remove in interface Index
      Parameters:
      key - the value of the index column of the information object.
      value - the information object to delete.
      Returns:
      this index.
    • reset

      public Index reset()
      Resets the index by clearing the underlying hash table. Implements the Index interface.
      Specified by:
      reset in interface Index
      Returns:
      this index.
    • numberOfBuckets

      public int numberOfBuckets()
      Return the number of buckets in the index. Each bucket represents a collision list. If Nb is the number of buckets and the Nk is the number of keys in the index then a large value of Nb/Nk indicates a good mapKey function. The value should be at least 1 or higher. To get an even better indication look at this ratio in conjunction with the minBucket() and maxBucket() values.
      Returns:
      the number of buckets in the index.
    • minBucket

      public int minBucket()
      Return the size of the shortest collision list in the hash table. This is the minimal number of comparisons the hash table will have to do in order to locate the entry with the given key. You can use this helper method to test the quality of your mapKey() .
      Returns:
      the size of the smallest bucket where each bucket represents a collision list.
    • maxBucket

      public int maxBucket()
      Return the size of the longest collision list in the hash table. This is the maximum number of comparisons the hash table will do in order to locate the entry with the given key. This helper method provides the means to test the quality of your mapKey() .
      Returns:
      the size of the biggest bucket where each bucket represents a collision list.
    • size

      public int size()
      Return the number of key/value pairs in the index. If Nb is the number of buckets and the Nk is the number of keys in the index then a large value of Nb/Nk indicates a good mapKey function. The value should be at least 1 or higher. To get an even better indication look at this ratio in conjunction with the minBucket() and maxBucket() values.
      Returns:
      the number of keys in the index.