jdbm.htree
Class HashBucket

java.lang.Object
  extended by jdbm.htree.HashNode
      extended by jdbm.htree.HashBucket
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable

final class HashBucket
extends HashNode
implements java.io.Externalizable

A bucket is a placeholder for multiple (key, value) pairs. Buckets are used to store collisions (same hash value) at all levels of an H*tree. There are two types of buckets: leaf and non-leaf. Non-leaf buckets are buckets which hold collisions which happen when the H*tree is not fully expanded. Keys in a non-leaf buckets can have different hash codes. Non-leaf buckets are limited to an arbitrary size. When this limit is reached, the H*tree should create a new Directory page and distribute keys of the non-leaf buckets into the newly created Directory. A leaf bucket is a bucket which contains keys which all have the same hashCode(). Leaf buckets stand at the bottom of an H*tree because the hashing algorithm cannot further discriminate between different keys based on their hash code.

Version:
$Id: HashBucket.java,v 1.2 2005/06/25 23:12:32 doomdark Exp $
Author:
Alex Boisvert

Field Summary
static int OVERFLOW_SIZE
          The maximum number of elements (key, value) a non-leaf bucket can contain.
(package private) static long serialVersionUID
           
 
Constructor Summary
HashBucket()
          Public constructor for serialization.
HashBucket(int level)
          Construct a bucket with a given depth level.
 
Method Summary
 java.lang.Object addElement(java.lang.Object key, java.lang.Object value)
          Add an element (key, value) to this bucket.
 int getElementCount()
          Returns the number of elements contained in this bucket.
(package private)  java.util.ArrayList getKeys()
          Obtain keys contained in this buckets.
 java.lang.Object getValue(java.lang.Object key)
          Returns the value associated with a given key.
(package private)  java.util.ArrayList getValues()
          Obtain values contained in this buckets.
 boolean hasRoom()
          Returns true if bucket can accept at least one more element.
 boolean isLeaf()
          Returns whether or not this bucket is a "leaf bucket".
 void readExternal(java.io.ObjectInput in)
          Implement Externalizable interface.
 java.lang.Object removeElement(java.lang.Object key)
          Remove an element, given a specific key.
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
          Implement Externalizable interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

OVERFLOW_SIZE

public static final int OVERFLOW_SIZE
The maximum number of elements (key, value) a non-leaf bucket can contain.

See Also:
Constant Field Values
Constructor Detail

HashBucket

public HashBucket()
Public constructor for serialization.


HashBucket

public HashBucket(int level)
Construct a bucket with a given depth level. Depth level is the number of HashDirectory above this bucket.

Method Detail

getElementCount

public int getElementCount()
Returns the number of elements contained in this bucket.


isLeaf

public boolean isLeaf()
Returns whether or not this bucket is a "leaf bucket".


hasRoom

public boolean hasRoom()
Returns true if bucket can accept at least one more element.


addElement

public java.lang.Object addElement(java.lang.Object key,
                                   java.lang.Object value)
Add an element (key, value) to this bucket. If an existing element has the same key, it is replaced silently.

Returns:
Object which was previously associated with the given key or null if no association existed.

removeElement

public java.lang.Object removeElement(java.lang.Object key)
Remove an element, given a specific key.

Parameters:
key - Key of the element to remove
Returns:
Removed element value, or null if not found

getValue

public java.lang.Object getValue(java.lang.Object key)
Returns the value associated with a given key. If the given key is not found in this bucket, returns null.


getKeys

java.util.ArrayList getKeys()
Obtain keys contained in this buckets. Keys are ordered to match their values, which be be obtained by calling getValues(). As an optimization, the Vector returned is the instance member of this class. Please don't modify outside the scope of this class.


getValues

java.util.ArrayList getValues()
Obtain values contained in this buckets. Values are ordered to match their keys, which be be obtained by calling getKeys(). As an optimization, the Vector returned is the instance member of this class. Please don't modify outside the scope of this class.


writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Implement Externalizable interface.

Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Implement Externalizable interface.

Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Cees de Groot (C) 2000-2001. All rights reserved http://jdbm.sourceforge.net