Key
- the type of the keys stored in this B+ tree node. This type has
to implement the Comparable interface.public class BPNode<Key extends Comparable<Key>> extends Object
IMPORTANT: Do not modify this class. When you submit your code, all changes to this file are discarded automatically. Hence, it may happen that you program is not working on the submission system.
A simple implementation of a B+ tree node that has an identifier, a node degree, a list of keys (of a specified type), and a list of children to other B+ tree nodes.
Constructor and Description |
---|
BPNode(int degree)
Constructs an empty B+ tree node of a specified degree.
|
Modifier and Type | Method and Description |
---|---|
void |
addChild(BPNode<Key> child)
Appends the specified child to this B+ tree node.
|
void |
addChild(int index,
BPNode<Key> child)
Adds the specified child at a specified index (0-based) of this B+ tree
node.
|
void |
addKey(int index,
Key key)
Adds the specified key at a specified index (0-based) of this B+ tree node.
|
void |
addKey(Key key)
Appends the specified key to this B+ tree node.
|
BPNode<Key> |
child(int index)
Retrieves a reference to the child at a specified index (0-based) of this
B+ tree node.
|
List<BPNode<Key>> |
children()
Retrieves the list of children stored in this B+ tree node.
|
int |
degree()
Retrieves the degree of this B+ tree node.
|
BPNode<Key> |
firstChild()
Retrieves a reference to the first child aof this B+ tree node if it
exists.
|
int |
id()
Retrieves the unique identifier of this B+ tree node.
|
boolean |
isLeaf()
Retrieves the type of a B+ tree node, i.e., is it a leaf node or not.
|
Key |
key(int index)
Retrieves the key at a specified index (0-based) of this B+ tree node.
|
List<Key> |
keys()
Retrieves the list of keys stored in this B+ tree node.
|
BPNode<Key> |
removeChild(int index)
Removes the child at a specified index (0-based) of this B+ tree node.
|
Key |
removeKey(int index)
Removes the key at a specified index (0-based) of this B+ tree node.
|
BPNode<Key> |
removeLastChild()
Removes the last child of this B+ tree node.
|
Key |
removeLastKey()
Removes the last key of this B+ tree node.
|
String |
toString()
Overridden toString method to print this B+ tree node.
|
public BPNode(int degree)
degree
- the node degree of this B+ tree node (i.e., m)public int id()
public int degree()
public List<Key> keys()
public List<BPNode<Key>> children()
public boolean isLeaf()
public BPNode<Key> child(int index)
index
- the index of the child to retrieve (0-based)IndexOutOfBoundsException
public BPNode<Key> firstChild()
public Key key(int index)
index
- the index of the key to retrieve (0-based)IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size())public void addKey(int index, Key key)
index
- the index the specified key is added at (0-based)IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size())public void addKey(Key key)
IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size())public void addChild(int index, BPNode<Key> child)
index
- the index the specified child is added at (0-based)IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size())public void addChild(BPNode<Key> child)
IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size())public Key removeKey(int index)
index
- the index of the key to be removed (0-based)IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size())public Key removeLastKey()
IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size())public BPNode<Key> removeChild(int index)
index
- the index of the child to be removed (0-based)IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size())public BPNode<Key> removeLastChild()
IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size())