Skip to content

Commit 9be3f03

Browse files
committed
rename
1 parent 6f54a58 commit 9be3f03

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

HashTable/Cuckoo/CuckooHashTable.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public int indexOf(K key) {
6666
return -1;
6767
}
6868

69+
@Override
70+
public boolean contains(K key) {
71+
return indexOf(key) != -1;
72+
}
73+
74+
@Override
6975
public void put(K key, V val) {
7076
if (contains(key)) {
7177
return;
@@ -151,10 +157,6 @@ public void printStatus() {
151157
System.out.println("Numbre of rehashes : " + numRehashes);
152158
}
153159

154-
public boolean contains(K key) {
155-
return indexOf(key) != -1;
156-
}
157-
158160
private void rehache(int newLength) {
159161
Node[][] oldArray = array;
160162
this.tableSize = HashTableInterface.nextPrime(newLength);
@@ -189,7 +191,6 @@ public static void main(String[] args) {
189191
ht.put("dexter", "red");
190192

191193
ht.print();
192-
ht.printStatus();
193194

194195
System.out.println("----------- Get -----------");
195196
String deletedKey = "apple";

HashTable/HashTableInterface.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,20 @@ public interface HashTableInterface<K, V> {
1111
public static final Random r = new Random();
1212
public static final String BLACK_CIRCLE = "\u25CF";
1313

14-
/* get the current load factor */
15-
default float loadFactor() {
16-
return getSize() / (float) getTableSize();
17-
}
18-
1914
/* get the position of key */
2015
int indexOf(K key);
16+
17+
/* check whether the specified key exist in the hashtable */
18+
boolean contains(K key);
2119

2220
/* update or insert a new item to the hashtable */
2321
void put(K key, V val);
2422

2523
/* get the value of the key*/
2624
V get(K key);
2725

28-
/* remove key */
26+
/* remove the specified item */
2927
void delete(K key);
30-
31-
/* check whether the specified key exist in the hashtable */
32-
boolean contains(K key);
3328

3429
/* remove all data from the hashtable */
3530
void clear();
@@ -48,6 +43,11 @@ default float loadFactor() {
4843

4944
/* get the number of resizes */
5045
int getNumResizes();
46+
47+
/* get the current load factor */
48+
default float loadFactor() {
49+
return getSize() / (float) getTableSize();
50+
}
5151

5252
/* print the table */
5353
void print();
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public int indexOf(K key) {
2929

3030
@Override
3131
public boolean contains(K key) {
32-
return indexOf(key) != -1;
32+
return array[indexOf(key)] != null;
3333
}
3434

3535
@Override
@@ -147,7 +147,6 @@ public static void main(String[] args) {
147147
ht.put("arya", "startk");
148148
ht.put("dexter", "red");
149149

150-
System.out.println("----------- Print -----------");
151150
ht.print();
152151

153152
System.out.println("----------- Get -----------");

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public int indexOf(K key) {
2929

3030
@Override
3131
public boolean contains(K key) {
32-
return indexOf(key) != -1;
32+
return array[indexOf(key)] != null;
3333
}
3434

3535
@Override
@@ -176,14 +176,13 @@ public static void main(String[] args) {
176176
ht.put("arys", "startk");
177177
ht.put("dextr", "red");
178178

179-
System.out.println("----------- Print -----------");
180179
ht.print();
181180

182181
System.out.println("----------- Get -----------");
183182
String deletedKey = "apple";
184183
System.out.println(deletedKey + " : i -> " + ht.indexOf(deletedKey) + " -> " + ht.get(deletedKey));
185184

186-
System.out.println("----------- Delete " + deletedKey +" -----------");
185+
System.out.println("----------- Delete " + deletedKey + " -----------");
187186
ht.delete(deletedKey);
188187

189188
ht.printGraph();

0 commit comments

Comments
 (0)