Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#ifndef CREATOR_FUNCTION_FAMILY_H
|
||||
#define CREATOR_FUNCTION_FAMILY_H
|
||||
|
||||
#include "../creatorAbstract.h"
|
||||
|
||||
BEGIN_NAMESPACE(BusinessLogic)
|
||||
BEGIN_NAMESPACE(Hash)
|
||||
BEGIN_NAMESPACE(Function)
|
||||
BEGIN_NAMESPACE(Family)
|
||||
|
||||
class Creator : public Abstract::Creator
|
||||
{
|
||||
protected:
|
||||
Creator()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual const Product &create() const = 0;
|
||||
};
|
||||
|
||||
END_NAMESPACE // Family
|
||||
END_NAMESPACE // Function
|
||||
END_NAMESPACE // Hash
|
||||
END_NAMESPACE // BusinessLogic
|
||||
|
||||
#endif // CREATOR_FUNCTION_FAMILY_H
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CREATOR_FUNCTION_FNV1a_H
|
||||
#define CREATOR_FUNCTION_FNV1a_H
|
||||
|
||||
#include "fnv1a.h"
|
||||
#include "creatorFamily.h"
|
||||
|
||||
BEGIN_NAMESPACE(BusinessLogic)
|
||||
BEGIN_NAMESPACE(Hash)
|
||||
BEGIN_NAMESPACE(Function)
|
||||
BEGIN_NAMESPACE(FNV1a)
|
||||
|
||||
class Creator : public Family::Creator
|
||||
{
|
||||
public:
|
||||
virtual const Product &create() const override {
|
||||
return Product::getInstance();
|
||||
}
|
||||
};
|
||||
|
||||
END_NAMESPACE // FNV1a
|
||||
END_NAMESPACE // Function
|
||||
END_NAMESPACE // Hash
|
||||
END_NAMESPACE // BusinessLogic
|
||||
|
||||
#endif // !CREATOR_FUNCTION_FNV1a_H
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef FUNCTION_FAMILY_H
|
||||
#define FUNCTION_FAMILY_H
|
||||
|
||||
#include "../abstract.h"
|
||||
|
||||
BEGIN_NAMESPACE(BusinessLogic)
|
||||
BEGIN_NAMESPACE(Hash)
|
||||
BEGIN_NAMESPACE(Function)
|
||||
BEGIN_NAMESPACE(Family)
|
||||
|
||||
using function_type = std::function<size_t(size_t, size_t)>;
|
||||
|
||||
class Product : public Abstract::Product
|
||||
{
|
||||
protected:
|
||||
const function_type m_function;
|
||||
|
||||
protected:
|
||||
Product(const function_type& function) : m_function(function)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
const function_type &to_std() const {
|
||||
return m_function;
|
||||
}
|
||||
size_t getHash(size_t first, size_t second) const {
|
||||
// First - the value that is hashed
|
||||
// Second - coefficient
|
||||
return m_function(first, second);
|
||||
}
|
||||
};
|
||||
|
||||
END_NAMESPACE // Family
|
||||
END_NAMESPACE // Function
|
||||
END_NAMESPACE // Hash
|
||||
END_NAMESPACE // BusinessLogic
|
||||
|
||||
#endif // FUNCTION_FAMILY_H
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef FUNCTION_FNV1a_H
|
||||
#define FUNCTION_FNV1a_H
|
||||
|
||||
#include "family.h"
|
||||
|
||||
BEGIN_NAMESPACE(BusinessLogic)
|
||||
BEGIN_NAMESPACE(Hash)
|
||||
BEGIN_NAMESPACE(Function)
|
||||
BEGIN_NAMESPACE(FNV1a)
|
||||
|
||||
using Singleton = BusinessLogic::Pattern::Singleton<Product>;
|
||||
|
||||
class Product final : public Family::Product, public Singleton
|
||||
{
|
||||
private:
|
||||
const int32_t m_p;
|
||||
|
||||
private:
|
||||
friend const Product &Singleton::getInstance();
|
||||
Product()
|
||||
: Family::Product(
|
||||
[this](size_t value, size_t i) -> size_t {
|
||||
size_t result = (0x811C9DC5 xor i) xor static_cast<int32_t>(value);
|
||||
return static_cast<int32_t>(result * m_p);
|
||||
}
|
||||
)
|
||||
, m_p(0x01000193)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
using Singleton::getInstance;
|
||||
};
|
||||
|
||||
END_NAMESPACE // FNV1a
|
||||
END_NAMESPACE // Function
|
||||
END_NAMESPACE // Hash
|
||||
END_NAMESPACE // BusinessLogic
|
||||
|
||||
#endif // !FUNCTION_FNV1a_H
|
||||
Reference in New Issue
Block a user