jdbm.htree
Class HTree<K,V>

java.lang.Object
  extended by jdbm.htree.HTree<K,V>
All Implemented Interfaces:
JdbmBase<K,V>

public class HTree<K,V>
extends java.lang.Object
implements JdbmBase<K,V>

Persistent hashtable implementation for PageManager. Implemented as an H*Tree structure. WARNING! If this instance is used in a transactional context, it *must* be discarded after a rollback.

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

Method Summary
 void addRecordListener(RecordListener<K,V> listener)
          add RecordListener which is notified about record changes
 HTreeMap<K,V> asMap()
           
static
<K,V> HTree<K,V>
createInstance(RecordManager recman)
          Create a persistent hashtable.
static
<K,V> HTree<K,V>
createInstance(RecordManager recman, Serializer<K> keySerializer, Serializer<V> valueSerializer)
          Create a persistent hashtable.
 V find(K key)
          Returns the value which is associated with the given key.
 Serializer<K> getKeySerializer()
           
 long getRecid()
          Get the record identifier used to load this hashtable.
 RecordManager getRecordManager()
           
 Serializer<V> getValueSerializer()
           
 java.util.Iterator<K> keys()
          Returns an enumeration of the keys contained in this
static
<K,V> HTree<K,V>
load(RecordManager recman, long root_recid)
          Load a persistent hashtable
static
<K,V> HTree<K,V>
load(RecordManager recman, long root_recid, Serializer<K> keySerializer, Serializer<V> valueSerializer)
          Load a persistent hashtable
 void put(K key, V value)
          Associates the specified value with the specified key.
 void remove(K key)
          Remove the value which is associated with the given key.
 void removeRecordListener(RecordListener<K,V> listener)
          remove RecordListener which is notified about record changes
 java.util.Iterator<V> values()
          Returns an enumeration of the values contained in this
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getKeySerializer

public Serializer<K> getKeySerializer()

getValueSerializer

public Serializer<V> getValueSerializer()

createInstance

public static <K,V> HTree<K,V> createInstance(RecordManager recman)
                                 throws java.io.IOException
Create a persistent hashtable.

Parameters:
recman - Record manager used for persistence.
Throws:
java.io.IOException

createInstance

public static <K,V> HTree<K,V> createInstance(RecordManager recman,
                                              Serializer<K> keySerializer,
                                              Serializer<V> valueSerializer)
                                 throws java.io.IOException
Create a persistent hashtable.

Parameters:
recman - Record manager used for persistence.
Throws:
java.io.IOException

load

public static <K,V> HTree<K,V> load(RecordManager recman,
                                    long root_recid)
                       throws java.io.IOException
Load a persistent hashtable

Parameters:
recman - RecordManager used to store the persistent hashtable
root_recid - Record id of the root directory of the HTree
Throws:
java.io.IOException

load

public static <K,V> HTree<K,V> load(RecordManager recman,
                                    long root_recid,
                                    Serializer<K> keySerializer,
                                    Serializer<V> valueSerializer)
                       throws java.io.IOException
Load a persistent hashtable

Parameters:
recman - RecordManager used to store the persistent hashtable
root_recid - Record id of the root directory of the HTree
Throws:
java.io.IOException

put

public void put(K key,
                V value)
         throws java.io.IOException
Associates the specified value with the specified key.

Parameters:
key - key with which the specified value is to be assocated.
value - value to be associated with the specified key.
Throws:
java.io.IOException

find

public V find(K key)
       throws java.io.IOException
Returns the value which is associated with the given key. Returns null if there is not association for this key.

Specified by:
find in interface JdbmBase<K,V>
Parameters:
key - key whose associated value is to be returned
Returns:
value or null if not found
Throws:
java.io.IOException

remove

public void remove(K key)
            throws java.io.IOException
Remove the value which is associated with the given key. If the key does not exist, this method simply ignores the operation.

Parameters:
key - key whose associated value is to be removed
Throws:
java.io.IOException

keys

public java.util.Iterator<K> keys()
                           throws java.io.IOException
Returns an enumeration of the keys contained in this

Throws:
java.io.IOException

values

public java.util.Iterator<V> values()
                             throws java.io.IOException
Returns an enumeration of the values contained in this

Throws:
java.io.IOException

getRecid

public long getRecid()
Get the record identifier used to load this hashtable.


asMap

public HTreeMap<K,V> asMap()

addRecordListener

public void addRecordListener(RecordListener<K,V> listener)
add RecordListener which is notified about record changes

Specified by:
addRecordListener in interface JdbmBase<K,V>
Parameters:
listener -

removeRecordListener

public void removeRecordListener(RecordListener<K,V> listener)
remove RecordListener which is notified about record changes

Specified by:
removeRecordListener in interface JdbmBase<K,V>
Parameters:
listener -

getRecordManager

public RecordManager getRecordManager()
Specified by:
getRecordManager in interface JdbmBase<K,V>
Returns:
underlying record manager


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