SimPHash/Src/Hash/Str/XXHash.mqh
2026-06-27 21:28:54 -05:00

67 lines
2.2 KiB
MQL5

//+------------------------------------------------------------------+
//| XXHash.mqh |
//| Copyright 2026, Niquel Mendoza. |
//| https://www.mql5.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza."
#property link "https://www.mql5.com/"
#property strict
#ifndef SIMPHASH_SRC_HASH_STR_XXHASH_MQH
#define SIMPHASH_SRC_HASH_STR_XXHASH_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "..\\Def.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CHashXXHash : public IHashGenerator
{
private:
ulong m_seed;
public:
CHashXXHash(void) {}
~CHashXXHash(void) {}
//---
bool Init(CYmlNode& node) override final
{
m_seed = ulong(node["seed"].ToInt(123123ULL));
return true;
}
//---
ulong Hash(const string& key) override final
{
return TSN::XSTR::XXH64(key, StringLen(key), m_seed);
}
//---
void AddIncludes(string& data) override final
{
data += "#include <TSN/Tables/AllHashes.mqh>\r\n";
}
//---
void BuildString(string& data) override final
{
data += "//---\r\n";
data += " const int len = StringLen(key);\r\n";
data += " ulong key_hash = TSN::XSTR::XXH64(key, len, " + string(m_seed) + "ULL);\r\n";
data += "\r\n";
}
};
//+------------------------------------------------------------------+
}
//+------------------------------------------------------------------+
#endif // SIMPHASH_SRC_HASH_STR_XXHASH_MQH