-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashTable.cpp
More file actions
24 lines (19 loc) · 1 KB
/
Copy pathHashTable.cpp
File metadata and controls
24 lines (19 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "HashTable.hpp"
HashTable::HashTable(int size) { //konstruktor
capacity = size; //definicja capacity
table = new AVLTree[capacity]; //tablica pustych drzew AVL w ilości capacity
}
HashTable::~HashTable() {
delete[] table; //usuwamy całą tablicę mieszającą
}
int HashTable::hash(int key) {
return key % capacity; //hashujemy klucze, biorąc ich reszte z dzielenia przez capacity
}
void HashTable::insert(int key, int value) { //wstawianie do tablicy
int index = hash(key); //najpierw hashujemy klucz
table[index].insert(key, value); //następnie na wyliczony z hasha index wstawiamy wartość
}
void HashTable::remove(int key) { //usuwanie z tablicy
int index = hash(key); //hashujemy klucz
table[index].remove(key); //usuwamy z wyliczonego hashem indexu wartość o danym kluczu
}