Skip to content

Commit b4f8aec

Browse files
committed
rename
1 parent cc082f7 commit b4f8aec

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package HashTable.LinearProbing;
22

33
import HashTable.HashTableInterface;
4-
import java.util.Random;
54
import java.util.function.Function;
65

7-
public class HashTable<K, V> implements HashTableInterface<K, V> {
6+
public class HashTableLP<K, V> implements HashTableInterface<K, V> {
87

98
private Node[] array;
109
private Function<K, Integer> foh;
@@ -13,12 +12,12 @@ public class HashTable<K, V> implements HashTableInterface<K, V> {
1312
private static int numCollisions = 0;
1413
private static int numResizes = 0;
1514

16-
public HashTable() {
15+
public HashTableLP() {
1716
array = new Node[INITIAL_TABLE_SIZE];
1817
foh = getHashingFunction();
1918
}
2019

21-
public HashTable(Function<K, Integer> f) {
20+
public HashTableLP(Function<K, Integer> f) {
2221
array = new Node[INITIAL_TABLE_SIZE];
2322
foh = f;
2423
}
@@ -80,8 +79,7 @@ public void resize() {
8079
numResizes++;
8180
clear();
8281

83-
for (int i = 0; i < oldArray.length; i++) {
84-
Node<K, V> node = oldArray[i];
82+
for (Node<K, V> node : oldArray) {
8583
if (node != null) {
8684
put(node.getKey(), node.getValue());
8785
}
@@ -132,7 +130,7 @@ public void printGraph() {
132130

133131
public static void main(String[] args) {
134132

135-
HashTable<String, String> ht = new HashTable<>();
133+
HashTableLP<String, String> ht = new HashTableLP<>();
136134
ht.put("banana", "yellow");
137135
ht.put("apple", "green");
138136
ht.put("android", "green");
@@ -151,13 +149,13 @@ public static void main(String[] args) {
151149
String deletedKey = "apple";
152150
System.out.println(deletedKey + " : i -> " + ht.indexOf(deletedKey) + " -> " + ht.get(deletedKey));
153151

154-
System.out.println("----------- Delete -----------");
152+
System.out.println("----------- Delete " + deletedKey +" -----------");
155153
ht.delete(deletedKey);
156154
ht.printGraph();
157155
ht.printStatus();
158156

159157
// Testing
160-
HashTable<String, String> table = new HashTable<>();
158+
HashTableLP<String, String> table = new HashTableLP<>();
161159
for (int i = 0; i < 100000; i++) {
162160
table.put(HashTableInterface.randomString(), HashTableInterface.randomString());
163161
}

HashTable/SeparateChaining/HashTable.java renamed to HashTable/SeparateChaining/HashTableSC.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import HashTable.HashTableInterface;
44
import java.util.function.Function;
55

6-
public class HashTable<K, V> implements HashTableInterface<K, V> {
6+
public class HashTableSC<K, V> implements HashTableInterface<K, V> {
77

88
private Node[] array;
99
private Function<K, Integer> foh;
@@ -12,12 +12,12 @@ public class HashTable<K, V> implements HashTableInterface<K, V> {
1212
private int numCollisions = 0;
1313
private int numResizes = 0;
1414

15-
public HashTable() {
15+
public HashTableSC() {
1616
array = new Node[tableSize];
1717
foh = getHashingFunction();
1818
}
1919

20-
public HashTable(Function<K, Integer> f) {
20+
public HashTableSC(Function<K, Integer> f) {
2121
array = new Node[tableSize];
2222
foh = f;
2323
}
@@ -98,8 +98,7 @@ public void resize() {
9898
numResizes++;
9999
clear();
100100

101-
for (int i = 0; i < oldArray.length; i++) {
102-
Node<K, V> node = oldArray[i];
101+
for (Node<K, V> node : oldArray) {
103102
while (node != null) {
104103
put(node.getKey(), node.getValue());
105104
node = node.getNext();
@@ -160,7 +159,7 @@ public void printGraph() {
160159

161160
public static void main(String[] args) {
162161

163-
HashTable<String, String> ht = new HashTable<>();
162+
HashTableSC<String, String> ht = new HashTableSC<>();
164163
ht.put("banana", "yellow");
165164
ht.put("apple", "green");
166165
ht.put("android", "green");
@@ -186,7 +185,7 @@ public static void main(String[] args) {
186185
ht.printStatus();
187186

188187
// Testing
189-
HashTable<String, String> table = new HashTable<>();
188+
HashTableSC<String, String> table = new HashTableSC<>();
190189
for (int i = 0; i < 100000; i++) {
191190
table.put(HashTableInterface.randomString(), HashTableInterface.randomString());
192191
}

0 commit comments

Comments
 (0)