//+------------------------------------------------------------------+ //| Test.mq5 | //| Copyright 2026, Niquel Mendoza. | //| https://www.mql5.com/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2026, Niquel Mendoza." #property link "https://www.mql5.com/" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include "..\\Src\\Main.mqh" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CHasherFnv164 : public TSN::CPerfectHashHasher { public: CHasherFnv164(void) {} ~CHasherFnv164(void) {} //--- ulong Hash(const string& v) override final { ulong h = 0xcbf29ce484222325; for(uint i = 0; i < v.Length(); i++) { h ^= (uchar)v[i]; h *= 0x100000001b3; } return h; } }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CHasherFinal : public TSN::CPerfectHashHasherWSeed { public: CHasherFinal(void) {} ~CHasherFinal(void) {} //--- __forceinline ulong Hash(const string& v, const ulong seed) override final { ulong h = 0xcbf29ce484222325; for(uint i = 0; i < v.Length(); i++) { h ^= (uchar)v[i]; h *= 0x100000001b3; } return h ^ seed; } }; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- const string keys[5] = { "hola", "valor", "si", "como", "no" }; const double val[5] = { 10.0, 20.0, 30.0, 40.0, 50.0 }; //--- TSN::CPerfectHashByLeo pf; pf.Hasher0(new CHasherFnv164()); pf.Hasher1(new CHasherFinal()); pf.DeleteHashers(true); pf.InitAlg(4, 12); //--- Inicio ulong seed[]; double value[]; ArrayResize(value, pf.m_final_table_size); // Ajustamos // ArrayInitialize(value, 0.00); // Valor por defecto invalido pf.RunWValue(keys, val, seed, value); // Check ArrayPrint(value); //--- const string key = "no"; int bucket = int(pf.Hasher0().Hash(key) % pf.m_buckets_size); ulong d = seed[bucket]; int final_index = int(pf.Hasher1().Hash(key, d) % pf.m_final_table_size); Print(value[final_index]); } //+------------------------------------------------------------------+