Отслеживать
1
0
Ответвление
У вас уже есть ответвление TsnTables
0
ответвлён от nique_372/TsnTables
TsnTables/Src/PHash/XXHash/XUL.mqh
2026-09-03 16:56:18 -05:00

121 строка
3,3 КиБ
MQL5

//+------------------------------------------------------------------+
//| XUL.mqh |
//| Copyright 2026, Niquel Mendoza |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza"
#property link "https://www.mql5.com"
#property strict
#ifndef TSNTABES_SRC_PHASH_XXHASH_XUL_MQH
#define TSNTABES_SRC_PHASH_XXHASH_XUL_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "Def.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace XUL
{
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
ulong XXHash_Final(const ulong& raw[], int i, int len, ulong hash)
{
//---
len &= 3; // % 32 -> % 4
//---
while(len > 0)
{
ulong acc = 0;
XXH64_round(acc, raw[i], k1)
i++;
hash ^= k1;
hash = XXH_rotl64(hash, 27) * XXH_PRIME64_1 + XXH_PRIME64_4;
len--;
}
//--- Avalanche (inline)
hash ^= hash >> 33;
hash *= XXH_PRIME64_2;
hash ^= hash >> 29;
hash *= XXH_PRIME64_3;
hash ^= hash >> 32;
return hash;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
ulong XXH64(const ulong& raw[], int len, ulong seed)
{
//---
ulong h64;
int i = 0;
//---
if(len >= 4) /* Process a large block of data */
{
ulong acc[4];
//---
acc[0] = seed + XXH_PRIME64_1 + XXH_PRIME64_2;
acc[1] = seed + XXH_PRIME64_2;
acc[2] = seed;
acc[3] = seed - XXH_PRIME64_1;
//--- Consume long inline
const int bEnd = i + len;
const int limit = bEnd - 31;
// It
do
{
XXH64_round_i(acc[0], raw[i], acc[0]);
i++;
XXH64_round_i(acc[1], raw[i], acc[1]);
i++;
XXH64_round_i(acc[2], raw[i], acc[2]);
i++;
XXH64_round_i(acc[3], raw[i], acc[3]);
i++;
}
while(i < limit);
//--- parte de XXH64_mergeAccs
//h64 = XXH64_mergeAccs(acc);
//---
h64 = XXH_rotl64(acc[0], 1) + XXH_rotl64(acc[1], 7)
+ XXH_rotl64(acc[2], 12) + XXH_rotl64(acc[3], 18);
//---
h64 = XXH64_MergeRound(h64, acc[0]);
h64 = XXH64_MergeRound(h64, acc[1]);
h64 = XXH64_MergeRound(h64, acc[2]);
h64 = XXH64_MergeRound(h64, acc[3]);
}
else
{
h64 = seed + XXH_PRIME64_5;
}
//---
h64 += (len << 3);
//---
return XXHash_Final(raw, i, len, h64);
}
}
}
#endif // TSNTABES_SRC_PHASH_XXHASH_XUL_MQH