85 lines
No EOL
2.8 KiB
MQL5
85 lines
No EOL
2.8 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Str.mqh |
|
|
//| Copyright 2026, Niquel Mendoza |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2026, Niquel Mendoza"
|
|
#property link "https://www.mql5.com"
|
|
#property strict
|
|
|
|
#ifndef FASTCOLLECTIONSBYLEO_COLHASH_HASH_GENERIC_STR_STR_MQH
|
|
#define FASTCOLLECTIONSBYLEO_COLHASH_HASH_GENERIC_STR_STR_MQH
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
#include <TSN/Tables/H/XXH64/XSTR.mqh>
|
|
#include "..\\Def.mqh"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
namespace TSN
|
|
{
|
|
//+------------------------------------------------------------------+
|
|
//| String FNV1A64 |
|
|
//+------------------------------------------------------------------+
|
|
class CGenericHash_string : public CGenericHash_eq_simple<string>
|
|
{
|
|
public:
|
|
CGenericHash_string(void) {}
|
|
~CGenericHash_string(void) {}
|
|
|
|
//---
|
|
static ulong Hash(const string& key)
|
|
{
|
|
ulong hash = 14695981039346656037ULL;
|
|
const int len = StringLen(key);
|
|
for(int i = 0; i < len; i++)
|
|
{
|
|
hash ^= (ulong)key[i];
|
|
hash *= 1099511628211ULL;
|
|
}
|
|
return hash;
|
|
}
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
// djb2
|
|
class CGenericHash_string_djb2 : public CGenericHash_eq_simple<string>
|
|
{
|
|
public:
|
|
CGenericHash_string_djb2(void) {}
|
|
~CGenericHash_string_djb2(void) {}
|
|
|
|
//---
|
|
static ulong Hash(const string& key)
|
|
{
|
|
ulong hash = 5381;
|
|
const int len = StringLen(key);
|
|
for(int i = 0; i < len; i++)
|
|
hash = ((hash << 5) + hash) + (ulong)key[i]; // hash * 33 + c
|
|
return hash;
|
|
|
|
}
|
|
};
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
// XXHash
|
|
class CGenericHash_string_xxhash64 : public CGenericHash_eq_simple<string>
|
|
{
|
|
public:
|
|
CGenericHash_string_xxhash64(void) {}
|
|
~CGenericHash_string_xxhash64(void) {}
|
|
|
|
//---
|
|
static ulong Hash(const string& key)
|
|
{
|
|
return TSN::XSTR::XXH64(key, StringLen(key), 0);
|
|
}
|
|
};
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
#endif // FASTCOLLECTIONSBYLEO_COLHASH_HASH_GENERIC_STR_STR_MQH |