|
@@ -17,6 +17,10 @@ public class MyHashMap implements MyMap{
|
17
|
17
|
}
|
18
|
18
|
}
|
19
|
19
|
|
|
20
|
+ public List<Entry>[] getEntries() {
|
|
21
|
+ return entries;
|
|
22
|
+ }
|
|
23
|
+
|
20
|
24
|
@Override
|
21
|
25
|
public int size() {
|
22
|
26
|
int count = 0;
|
|
@@ -33,25 +37,47 @@ public class MyHashMap implements MyMap{
|
33
|
37
|
|
34
|
38
|
@Override
|
35
|
39
|
public Cart get(User key) {
|
36
|
|
- int bucket = bucketIndex(key);
|
37
|
|
- for (Entry e: entries[bucket]) {
|
38
|
|
- if (e.getKey().equals(key)) {
|
39
|
|
- return e.getValue();
|
|
40
|
+ int bucket = bucketIndex(key);
|
|
41
|
+
|
|
42
|
+ for (Entry e : getEntries()[bucket]) {
|
|
43
|
+ if (e.getKey().equals(key)) {
|
|
44
|
+ return e.getValue();
|
|
45
|
+ }
|
40
|
46
|
}
|
41
|
|
- }
|
42
|
47
|
return null;
|
43
|
48
|
}
|
44
|
49
|
|
45
|
50
|
@Override
|
46
|
51
|
public void put(User key, Cart value) {
|
47
|
|
- entries[bucketIndex(key)].add(new Entry(key, value));
|
|
52
|
+
|
|
53
|
+// if(get(key) != null) {
|
|
54
|
+// for (Entry e: getEntries()[bucketIndex(key)]) {
|
|
55
|
+// if (e.getKey().equals(key)) {
|
|
56
|
+// e.setValue(value);
|
|
57
|
+// }
|
|
58
|
+// }
|
|
59
|
+// } else {
|
|
60
|
+// getEntries()[bucketIndex(key)].add(new Entry(key, value));
|
|
61
|
+// }
|
|
62
|
+
|
|
63
|
+ if (!getKeys().contains(key)) {
|
|
64
|
+ entries[bucketIndex(key)].add(new Entry(key, value));
|
|
65
|
+ } else {
|
|
66
|
+ for (Entry e: entries[bucketIndex(key)]) {
|
|
67
|
+ if (e.getKey().equals(key)) {
|
|
68
|
+ e.setValue(value);
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+
|
48
|
74
|
}
|
49
|
75
|
|
50
|
76
|
@Override
|
51
|
77
|
public List<User> getKeys() {
|
52
|
78
|
List<User> keys = new ArrayList<>();
|
53
|
|
- for (List<Entry> list:entries) {
|
54
|
|
- for (Entry e: list )
|
|
79
|
+ for (List<Entry> list: getEntries()) {
|
|
80
|
+ for (Entry e: list)
|
55
|
81
|
keys.add(e.getKey());
|
56
|
82
|
}
|
57
|
83
|
return keys;
|
|
@@ -75,10 +101,10 @@ public class MyHashMap implements MyMap{
|
75
|
101
|
while (iterator.hasNext()) {
|
76
|
102
|
e = iterator.next();
|
77
|
103
|
if (e.getKey().equals(key)) {
|
78
|
|
- entries[bucket].remove(e);
|
|
104
|
+ getEntries()[bucket].remove(e);
|
|
105
|
+ break;
|
79
|
106
|
}
|
80
|
107
|
}
|
81
|
|
-
|
82
|
108
|
return e.getValue();
|
83
|
109
|
}
|
84
|
110
|
|