-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHashTable.java
54 lines (39 loc) · 1.08 KB
/
HashTable.java
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
package org.blueocean;
import java.io.Serializable;
public class HashTable implements Cloneable {
private int size;
private LinkedList[] buckets = new LinkedList[size];
private static class LinkedList {
final Object key;
Object data;
LinkedList next;
LinkedList(Object d, Object k, LinkedList n){
data = d; next = n; key = k;
}
LinkedList deepCopy(){
return new LinkedList(this.data, this.key, this.next!=null? this.next.deepCopy(): null);
}
LinkedList deepCopyI(){
LinkedList copy = new LinkedList(this.data, this.key, this.next);
while(copy.next!=null){
copy.next = new LinkedList(copy.next.data, this.key, copy.next.next);
copy = copy.next;
}
return copy;
}
}
@Override
public HashTable clone(){
try {
HashTable copy = (HashTable) super.clone();
copy.size = this.size;
copy.buckets = new LinkedList[this.size];
for(int i=0; i<copy.size; i++){
copy.buckets[i] = this.buckets[i].deepCopy();
}
return copy;
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
}
}