Before running the project, install the following libraries:
sudo yum install openssl
sudo yum install openssl-develBoost: to store and operate with256 bit integers
sudo yum install boost-devel
sudo yum install boostTo link the libraries with the project, add the following lines to CMakeList.txt
find_package(OpenSSL REQUIRED)
find_package(Boost REQUIRED)
target_link_libraries(
${PROJECT_NAME}
OpenSSL::SSL
Boost::boost
)git clone https://github.com/ByJuanDiego/hash-table.git
cd hash-table
chmod +x run.zsh
./run.zshrecords in the hash table
entries in a bucket
values on an entry
| Member Function | Big |
Big |
Notes |
|---|---|---|---|
bucket_count() |
Same as |
- | |
bucket_size(int i) |
Same as |
- | |
key_count() |
Same as |
- | |
size() |
Same as |
- | |
empty() |
Same as |
- | |
clear() |
Same as |
if V is a pointer, records will not be freed |
|
find(K key) |
keeps the array length | ||
insert(V value) |
- | ||
remove(K key) |
- | ||
search(K key) |
- | ||
print(std::ostream &os, Print<V> print_value, Print<K> print_key) |
Same as |
print_value and print_key has default functions for fundamental types
|
using std::string;
using sha = sha2::sha256<string>;
using index_t = std::function<string(transaction *)>;
using equal_t = std::function<bool(string, string)>;
sha hash;
index_t index = [&](const transaction *tx) -> string {
return tx->emisor;
};
equal_t equal = [&](const string &a, const string &b) -> bool {
return (a == b);
};
hash_table<string, transaction *, sha, index_t, equal_t> hashTable(index, hash, equal);Instantiates a hashTable that contains transaction * indexed by emisor
equalis an optional parameter. By default, it receives an instance ofstd::equal_to, which works properly for built-in types. Using a non-built-in type askeymakes necessaryequalparameter or anstd::equal_tospecializationhashis an instance ofsha2::sha256, which is well-defined forstd::to_stringconvertable key-types and specialized forstd::stringusage. To use other key-types asha2::sha256specialization is required- usage of other hash functions such as
std::hashis allowed by passing the desire hash function as template type parameter
std::string key = "juan-diego";
for (const transaction *t: hashTable.search(key)) {
std::cout << t->to_string() << std::endl;
}This query returns all the transactions made by juan-diego
If the value-type is a pointer, the pointed values will not be freed when hash_table::~hash_table is called. This is manual process.
for (transaction *tx: destructor) {
delete tx;
}iteratorclass for the hash tableshrink_to_fitprivate member function to be used to resize the hash table when deleting a certain number of keys
