Initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#ifndef CREATOR_ALGHORITHM_DOUBLE_HASHING_H
|
||||
#define CREATOR_ALGHORITHM_DOUBLE_HASHING_H
|
||||
|
||||
#include "doubleHashing.h"
|
||||
#include "creatorFamily.h"
|
||||
|
||||
BEGIN_NAMESPACE(BusinessLogic)
|
||||
BEGIN_NAMESPACE(Hash)
|
||||
BEGIN_NAMESPACE(Algorithm)
|
||||
BEGIN_NAMESPACE(DoubleHashing)
|
||||
|
||||
class Creator : public Family::Creator
|
||||
{
|
||||
private:
|
||||
size_t m_firstHashFunction;
|
||||
size_t m_secondHashFunction;
|
||||
|
||||
public:
|
||||
Creator(size_t first, size_t second) : m_firstHashFunction(first), m_secondHashFunction(second)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual std::unique_ptr<Abstract::Product> create() const override {
|
||||
return std::unique_ptr<Abstract::Product>(new Product(m_firstHashFunction, m_secondHashFunction));
|
||||
}
|
||||
};
|
||||
|
||||
END_NAMESPACE // DoubleHashing
|
||||
END_NAMESPACE // Algorithm
|
||||
END_NAMESPACE // Hash
|
||||
END_NAMESPACE // BusinessLogic
|
||||
|
||||
#endif // !CREATOR_ALGHORITHM_DOUBLE_HASHING_H
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef CREATOR_ALGHORITHM_FAMILY_H
|
||||
#define CREATOR_ALGHORITHM_FAMILY_H
|
||||
|
||||
#include "../creatorAbstract.h"
|
||||
|
||||
BEGIN_NAMESPACE(BusinessLogic)
|
||||
BEGIN_NAMESPACE(Hash)
|
||||
BEGIN_NAMESPACE(Algorithm)
|
||||
BEGIN_NAMESPACE(Family)
|
||||
|
||||
class Creator : public Abstract::Creator
|
||||
{
|
||||
protected:
|
||||
Creator()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
END_NAMESPACE // Family
|
||||
END_NAMESPACE // Algorithm
|
||||
END_NAMESPACE // Hash
|
||||
END_NAMESPACE // BusinessLogic
|
||||
|
||||
#endif // !CREATOR_ALGHORITHM_FAMILY_H
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef CREATOR_ALGHORITHM_PSEUDORANDOM_PROBING_H
|
||||
#define CREATOR_ALGHORITHM_PSEUDORANDOM_PROBING_H
|
||||
|
||||
#include "pseudorandomProbing.h"
|
||||
#include "creatorFamily.h"
|
||||
|
||||
BEGIN_NAMESPACE(BusinessLogic)
|
||||
BEGIN_NAMESPACE(Hash)
|
||||
BEGIN_NAMESPACE(Algorithm)
|
||||
BEGIN_NAMESPACE(PseudorandomProbing)
|
||||
|
||||
class Creator : public Family::Creator
|
||||
{
|
||||
private:
|
||||
size_t m_hashFunctionNumber;
|
||||
|
||||
public:
|
||||
Creator(size_t number) : m_hashFunctionNumber(number)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual std::unique_ptr<Abstract::Product> create() const override {
|
||||
return std::unique_ptr<Abstract::Product>(new Product(m_hashFunctionNumber));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
END_NAMESPACE // PseudorandomProbing
|
||||
END_NAMESPACE // Algorithm
|
||||
END_NAMESPACE // Hash
|
||||
END_NAMESPACE // BusinessLogic
|
||||
|
||||
#endif // !CREATOR_ALGHORITHM_PSEUDORANDOM_PROBING_H
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef ALGHORITHM_DOUBLE_HASHING_H
|
||||
#define ALGHORITHM_DOUBLE_HASHING_H
|
||||
|
||||
#include "family.h"
|
||||
|
||||
BEGIN_NAMESPACE(BusinessLogic)
|
||||
BEGIN_NAMESPACE(Hash)
|
||||
BEGIN_NAMESPACE(Algorithm)
|
||||
BEGIN_NAMESPACE(DoubleHashing)
|
||||
|
||||
class Product final : public Family::Product
|
||||
{
|
||||
private:
|
||||
size_t m_firstHashFunction;
|
||||
size_t m_secondHashFunction;
|
||||
size_t m_multiplier;
|
||||
private:
|
||||
friend Creator;
|
||||
Product(size_t first, size_t second) : m_firstHashFunction(first), m_secondHashFunction(second)
|
||||
{
|
||||
if (first == second) {
|
||||
throw std::invalid_argument("hash functions must be different");
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual size_t getFirstCoefficient() override {
|
||||
m_multiplier = m_hashFunction->getHash(m_convertValue, m_firstHashFunction);
|
||||
return m_hashFunction->getHash(m_convertValue, m_firstHashFunction);
|
||||
}
|
||||
virtual size_t getSecondCoefficient(size_t counter) override {
|
||||
return counter * m_multiplier;
|
||||
}
|
||||
};
|
||||
|
||||
END_NAMESPACE // DoubleHashing
|
||||
END_NAMESPACE // Algorithm
|
||||
END_NAMESPACE // Hash
|
||||
END_NAMESPACE // BusinessLogic
|
||||
|
||||
#endif // !ALGHORITHM_DOUBLE_HASHING_H
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef ALGHORITHM_FAMILY_H
|
||||
#define ALGHORITHM_FAMILY_H
|
||||
|
||||
#include "../../Function/Family/family.h"
|
||||
#include "../abstract.h"
|
||||
|
||||
BEGIN_NAMESPACE(BusinessLogic)
|
||||
BEGIN_NAMESPACE(Hash)
|
||||
BEGIN_NAMESPACE(Algorithm)
|
||||
BEGIN_NAMESPACE(Family)
|
||||
|
||||
class Product : public Abstract::Product
|
||||
{
|
||||
public:
|
||||
using function_type = Function::Family::Product;
|
||||
|
||||
protected:
|
||||
const function_type *m_hashFunction;
|
||||
|
||||
protected:
|
||||
Product() : m_hashFunction(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
void setHashFunction(const function_type &hashFunction) {
|
||||
m_hashFunction = &hashFunction;
|
||||
}
|
||||
};
|
||||
|
||||
END_NAMESPACE // Family
|
||||
END_NAMESPACE // Algorithm
|
||||
END_NAMESPACE // Hash
|
||||
END_NAMESPACE // BusinessLogic
|
||||
|
||||
#endif // !ALGHORITHM_FAMILY_H
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef ALGHORITHM_PSEUDORANDOM_PROBING_H
|
||||
#define ALGHORITHM_PSEUDORANDOM_PROBING_H
|
||||
|
||||
#include "family.h"
|
||||
|
||||
#include <random>
|
||||
|
||||
BEGIN_NAMESPACE(BusinessLogic)
|
||||
BEGIN_NAMESPACE(Hash)
|
||||
BEGIN_NAMESPACE(Algorithm)
|
||||
BEGIN_NAMESPACE(PseudorandomProbing)
|
||||
|
||||
class Product final : public Family::Product
|
||||
{
|
||||
private:
|
||||
size_t m_hashFunctionNumber;
|
||||
size_t m_multiplier;
|
||||
|
||||
private:
|
||||
friend Creator;
|
||||
Product(size_t number) : m_hashFunctionNumber(number)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
// virtual bool isValidInput() const override {
|
||||
// return isPrimeNumber(size());
|
||||
// }
|
||||
virtual size_t getFirstCoefficient() override {
|
||||
m_multiplier = m_hashFunction->getHash(m_convertValue, m_hashFunctionNumber);
|
||||
srand(m_multiplier);
|
||||
return m_hashFunction->getHash(m_convertValue, m_hashFunctionNumber);
|
||||
}
|
||||
virtual size_t getSecondCoefficient(size_t counter) override {
|
||||
return counter * rand();
|
||||
}
|
||||
};
|
||||
|
||||
END_NAMESPACE // PseudorandomProbing
|
||||
END_NAMESPACE // Algorithm
|
||||
END_NAMESPACE // Hash
|
||||
END_NAMESPACE // BusinessLogic
|
||||
|
||||
#endif // !ALGHORITHM_PSEUDORANDOM_PROBING_H
|
||||
Reference in New Issue
Block a user