Skip to content

Commit fc0bcf8

Browse files
author
jb
committed
Merge origin/master
2 parents bf81561 + 5e48ccf commit fc0bcf8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

SortingArray/src/searchingArray/LinearProbingHashST.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@
33
public class LinearProbingHashST<Key, Value> {
44

55
private int N; // number of key-value pairs in the table
6-
private int M = 16; // size of linear-probing table
6+
private int M = 16; // SIZE -- of linear-probing table
77
private Key[] keys; // the keys
88
private Value[] vals; // the values
99

1010
public LinearProbingHashST() {
11-
this.M = 16;
1211
keys = (Key[]) new Object[M];
1312
vals = (Value[]) new Object[M];
14-
}
13+
}
1514

15+
private LinearProbingHashST(int cap) {
16+
this.M = cap; // I made a constructor that sets the value of M (the initial size)
17+
keys = (Key[]) new Object[M]; // to the incomming value = cap, cap comes from the rezise method (M * 2)
18+
vals = (Value[]) new Object[M];
19+
}
20+
1621
// Hash function - Compound keys. If the key type has multiple integer fields, we can typically mix them
1722
// together in the way just described for String values.
1823
private int hash(Key key) {
1924
return (key.hashCode() & 0x7fffffff) % M;
2025
}
2126

22-
private void resize(int M) {
27+
private void resize(int cap) {
2328
LinearProbingHashST<Key, Value> t;
24-
t = new LinearProbingHashST<Key, Value>(M);
29+
t = new LinearProbingHashST<Key, Value>(cap);
2530
for (int i = 0; i < M; i++) {
2631
if (keys[i] != null) {
2732
t.put(keys[i], vals[i]);

0 commit comments

Comments
 (0)