-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBucket.java
More file actions
105 lines (93 loc) · 2.78 KB
/
Bucket.java
File metadata and controls
105 lines (93 loc) · 2.78 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//This class depicts the bucket structure of hashing scheme
public class Bucket {
private int localDepth;
//Each bucket has an array of element objects
public Elem[] elements;
//bfr determines the length of the elements array
public static int bfr;
//cluster detemines which bucket this bucket belongs to
private int cluster;
public Bucket()
{
localDepth = 1;
this.bfr = bfr;
elements = new Elem[bfr];
cluster = 0;
for(int i=0;i<bfr;i++)
elements[i] = new Elem();
}
public Bucket(int localDepth, int bfr){
this.localDepth = localDepth;
this.bfr = bfr;
elements = new Elem[bfr];
cluster = 0;
for(int i=0;i<bfr;i++)
elements[i] = new Elem();
}
//Function to check whether the bucket is full or not
public boolean isFull()
{
for(int i=0;i<bfr;i++){
if(!elements[i].getIsFull())
return false;
}
return true;
}
//Function to check whether the bucket is empty or not
public boolean isEmpty()
{
for(int i=0;i<bfr;i++){
if(elements[i].getIsFull())
return false;
}
return true;
}
//Function to add element to bucket
public void addElementToBucket(int val, boolean f){
if(this.isFull())
System.out.println("Full Bucket");
else{
for(int i=0;i<bfr;i++){
if(!elements[i].getIsFull()){
elements[i].setValue(val);
elements[i].setIsFull(f);
System.out.println(val + " added to location " + i + " of bucket.");
break;
}
}
}
}
//Function to view the elements of bucket
public void showBucket(){
if(this.isEmpty())
System.out.print("Empty Bucket");
else{
for(int i=0;i<bfr;i++){
if(elements[i].getIsFull()){
System.out.print(elements[i].getValue() + " ");
}
}
}
}
//Function to manually set the local depth of bucket
public void setLocalDepth(int val)
{
localDepth = val;
}
//Function to get the local depth of bucket
public int getLocalDepth(){
return localDepth;
}
//Function to get the bfr of bucket
public int getBfr(){
return bfr;
}
//Function to set the cluster of bucket
public void setCluster(int cluster){
this.cluster = cluster;
}
//Function to get the cluster of bucket
public int getCluster(){
return cluster;
}
}