-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBTreeNode.java
More file actions
75 lines (65 loc) · 1.36 KB
/
BTreeNode.java
File metadata and controls
75 lines (65 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.io.File;
import java.io.Serializable;
public class BTreeNode{
/*
* In the pseudocode in the slides, these values are accessed
* directly in the BTree so I made them public in order to do
* that
*/
public int numObjects;
public TreeObject key[]; //we might need to rename this
public boolean leaf;
public int children[];
public int parent;
public int offset;
public int numChildren; //experimental
BTreeNode(int order, boolean leaf, int parent){
this.numObjects = 0;
this.numChildren = 0;
this.key = new TreeObject[order];
this.leaf = leaf;
this.children = new int[order];
this.parent = parent;
}
public void setOffset(int i) {
this.offset = i;
}
//might not need this
public int getNumbObjects()
{
return this.numObjects;
}
//might not need this
public void setNumObjects(int x)
{
this.numObjects = x;
}
public boolean isLeaf() {
return leaf;
}
public void updateLeaf() {
for(int i:children) {
if(i != 0) {
leaf = false;
return;
}
}
leaf = true;
}
public void fillKeys() {
for(int i = 0; i < key.length; i++) {
if(key[i] == null) {
key[i] = new TreeObject(0,0);
}
}
}
//Returns keys of the node
@Override
public String toString(){
String result = "";
for (int i = 0; i < numObjects && key[i] != null; i++){
result += key[i].toString() + " ";
}
return result;
}
}