DynuIPRefresher/inc/api/Hashmap.h

65 lines
1.3 KiB
C
Raw Normal View History

2019-05-01 09:14:52 +00:00
//
// Created by lukas on 07.04.19.
//
#pragma once
2019-05-01 09:14:52 +00:00
#include <iostream>
#include <vector>
2019-05-08 17:31:49 +00:00
template<class keytype, class valuetype>
class Hashmap {
2019-05-01 09:14:52 +00:00
public:
/**
* add key-value pair to hashmap
* @param key keyvalue
* @param value valuevalue
*/
2019-05-08 17:31:49 +00:00
void add(keytype key, keytype value);
/**
* get key of specific position
* @param position int position
* @return responding key object
*/
2019-05-01 09:14:52 +00:00
keytype getKey(int position);
2019-05-08 17:31:49 +00:00
/**
* get value of specific position
* @param position int position
* @return responding value object
*/
2019-05-01 09:14:52 +00:00
valuetype getValue(int position);
/**
* get size of Hashmap
* @return size of Hashmap
*/
2019-05-01 09:14:52 +00:00
int size();
private:
std::vector<keytype> keys;
std::vector<valuetype> values;
};
template<class keytype, class valuetype>
void Hashmap<keytype, valuetype>::add(keytype key, keytype value) {
keys.push_back(key);
values.push_back(value);
}
template<class keytype, class valuetype>
keytype Hashmap<keytype, valuetype>::getKey(int position) {
return keys.at(position);
}
template<class keytype, class valuetype>
valuetype Hashmap<keytype, valuetype>::getValue(int position) {
return values.at(position);
}
template<class keytype, class valuetype>
int Hashmap<keytype, valuetype>::size() {
return (int) (keys.size());
2019-05-01 09:14:52 +00:00
}