add hash function to CPU class
This commit is contained in:
parent
d0d6dbb5c7
commit
6bf9b6c9ee
34
CPU.h
34
CPU.h
@ -1,10 +1,10 @@
|
|||||||
#ifndef INC_08_TEAM_PROJECT_CPU_H
|
#ifndef INC_08_TEAM_PROJECT_CPU_H
|
||||||
#define INC_08_TEAM_PROJECT_CPU_H
|
#define INC_08_TEAM_PROJECT_CPU_H
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class CPU {
|
class CPU
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
std::string cpuId;
|
std::string cpuId;
|
||||||
int releaseYear;
|
int releaseYear;
|
||||||
@ -13,16 +13,15 @@ private:
|
|||||||
double baseClock;
|
double baseClock;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CPU() : cpuId(""), releaseYear(0), coreCount(0), architecture(""), baseClock(0.0) {};
|
CPU() : cpuId(""), releaseYear(0), coreCount(0), architecture(""), baseClock(0.0){};
|
||||||
|
|
||||||
CPU(std::string id, int year, int cores, std::string arch, double clock) :
|
CPU(std::string id, int year, int cores, std::string arch, double clock) : cpuId(std::move(id)),
|
||||||
cpuId(std::move(id)),
|
releaseYear(year),
|
||||||
releaseYear(year),
|
coreCount(cores),
|
||||||
coreCount(cores),
|
architecture(std::move(arch)),
|
||||||
architecture(std::move(arch)),
|
baseClock(clock){};
|
||||||
baseClock(clock) {};
|
|
||||||
|
|
||||||
std::string getCpuId() const { return cpuId; };
|
std::string getCpuId() const { return cpuId; };
|
||||||
|
|
||||||
int getReleaseYear() const;
|
int getReleaseYear() const;
|
||||||
|
|
||||||
@ -59,9 +58,16 @@ public:
|
|||||||
friend int key_to_index(const CPU &key, int size);
|
friend int key_to_index(const CPU &key, int size);
|
||||||
};
|
};
|
||||||
|
|
||||||
int key_to_index(const CPU &key, int size) {
|
/*~*~*~*
|
||||||
// TODO
|
Hash function: takes the key and returns the index in the hash table
|
||||||
return key.coreCount % size;
|
*~**/
|
||||||
|
int key_to_index(const CPU &key, int size)
|
||||||
|
{
|
||||||
|
std::string k = key.getCpuId();
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; k[i]; i++)
|
||||||
|
sum += k[i];
|
||||||
|
return sum % size;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //INC_08_TEAM_PROJECT_CPU_H
|
#endif // INC_08_TEAM_PROJECT_CPU_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user