|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.mhhe.clrs2e.BTree
Implementation of a B-tree from Chapter 18 of Introduction to
Algorithms, Second edition. Objects inserted into a B-Tree
must implement the DynamicSetElement
interface.
Nested Class Summary | |
private static class |
BTree.BTreeHandle
Class to define a handle returned by searches. |
private class |
BTree.Node
Private inner class for a B-tree node. |
Field Summary | |
private int |
maxKeys
The maximum number of keys in any node, = 2 t -1. |
private BTree.Node |
root
The root of the B-tree. |
private int |
t
The minimum degree, i.e., the minimum number of keys in any node other than the root. |
Constructor Summary | |
BTree(int t)
Creates an empty B-tree. |
Method Summary | |
void |
delete(java.lang.Object key)
Removes an element. |
java.lang.Object |
insert(java.lang.Comparable o)
Inserts an element. |
java.lang.Object |
search(java.lang.Comparable k)
Searches for an element with a given key. |
java.lang.String |
toString()
Returns the String representation of this B-tree
by walking it. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private final int t
private final int maxKeys
t
-1.
private BTree.Node root
Constructor Detail |
public BTree(int t)
t
- The minimum degree of this B-tree.Method Detail |
public java.lang.Object search(java.lang.Comparable k)
search
in interface Dictionary
k
- The key being searched for.
null
if
there is no match.public java.lang.Object insert(java.lang.Comparable o)
insert
in interface Dictionary
o
- The element to insert.
java.lang.ClassCastException
- if o
does not reference
a DynamicSetElement
.public void delete(java.lang.Object key)
The element to remove is specified by its key, rather than by a handle giving its location in the B-tree. We need to specify the object by its key because deletion from a B-tree works top-down, emulating a search. We need to use the path from the root down to the node containing the element to be deleted, and if we were given the element's node and index instead of its key, we would not be able to determine this path efficiently.
delete
in interface Dictionary
key
- The key of the element to remove.
java.lang.ClassCastException
- if key
does not
implement Comparable
.public java.lang.String toString()
String
representation of this B-tree
by walking it.
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |