Package com.oss.asn1
Class DefaultIndex
java.lang.Object
com.oss.asn1.DefaultIndex
- All Implemented Interfaces:
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 ClassesModifier and TypeClassDescriptionstatic class
Helper class that implements theEnumeration
containing only one element. -
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor.DefaultIndex
(int capacity) Create the index with the given capacity and load factor of 3/4. -
Method Summary
Modifier and TypeMethodDescriptionadd
(AbstractData key, InfoObject value) Adds a new information object to the index.lookup
(AbstractData key) Looks up the unique information object with the index column matching thekey
.abstract int
mapKey
(AbstractData key) Map the key to the integer in the range0..N
, whereN≈M
andM
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.remove
(AbstractData key, InfoObject value) Removes the information object from the index.reset()
Resets the index by clearing the underlying hash table.int
size()
Return the number of key/value pairs in the index.
-
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
Map the key to the integer in the range0..N
, whereN≈M
andM
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
Looks up the unique information object with the index column matching thekey
. Implements theIndex
interface. TheEnumeration
returned is either empty or contains the only element. -
add
Adds a new information object to the index. Implements theIndex
interface. Returnnull
if the information object, identified bykey
already exists. -
remove
Removes the information object from the index. Implements theIndex
interface. -
reset
Resets the index by clearing the underlying hash table. Implements theIndex
interface. -
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 goodmapKey
function. The value should be at least 1 or higher. To get an even better indication look at this ratio in conjunction with theminBucket()
andmaxBucket()
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 yourmapKey()
.- 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 yourmapKey()
.- 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 goodmapKey
function. The value should be at least 1 or higher. To get an even better indication look at this ratio in conjunction with theminBucket()
andmaxBucket()
values.- Returns:
- the number of keys in the index.
-