|
| | MyHashMap () |
| |
| void | put (int key, int value) |
| | Retrieves valid list and set/appends new value with given key.
|
| |
| int | get (int key) |
| | Retrieves value of the key.
|
| |
| void | remove (int key) |
| | Retrieves valid list and removes entry for key-value pair.
|
| |
|
| int | hash (int key) |
| | Returns index of table used as hashtable with given key.
|
| |
|
| vector< list< pair< int, int > > > | table |
| |
Definition at line 7 of file main.cpp.
◆ MyHashMap()
Definition at line 23 of file main.cpp.
vector< list< pair< int, int > > > table
◆ get()
| int MyHashMap::get |
( |
int |
key | ) |
|
|
inline |
Retrieves value of the key.
- Parameters
-
- Returns
- Returns value of existent key, -1 in other case
Definition at line 46 of file main.cpp.
47 {
49 for (
const auto& p :
table[h])
50 if (p.first == key)
51 return p.second;
52 return -1;
53 }
int hash(int key)
Returns index of table used as hashtable with given key.
References hash(), and table.
Referenced by main().
◆ hash()
| int MyHashMap::hash |
( |
int |
key | ) |
|
|
inlineprivate |
Returns index of table used as hashtable with given key.
- Parameters
-
- Returns
- Index of table to store data.
Definition at line 19 of file main.cpp.
References SIZE.
Referenced by get(), put(), and remove().
◆ put()
| void MyHashMap::put |
( |
int |
key, |
|
|
int |
value |
|
) |
| |
|
inline |
Retrieves valid list and set/appends new value with given key.
Definition at line 28 of file main.cpp.
29 {
31 for (
auto& p :
table[h])
32 if (p.first == key)
33 {
34 p.second = value;
35 return;
36 }
37 table[h].emplace_back(key, value);
38 }
References hash(), and table.
Referenced by main().
◆ remove()
| void MyHashMap::remove |
( |
int |
key | ) |
|
|
inline |
Retrieves valid list and removes entry for key-value pair.
- Parameters
-
| key | Key for a key-value pair to remove. |
Definition at line 60 of file main.cpp.
61 {
63 table[h].remove_if([key](
const pair<int, int>& p) {
return p.first == key; });
64 }
References hash(), and table.
Referenced by main().
◆ table
| vector<list<pair<int, int> > > MyHashMap::table |
|
private |
The documentation for this class was generated from the following file: