PerfectHashByLeo/Src/Defines.mqh

73 lines
2.7 KiB
MQL5
Raw Permalink Normal View History

2026-06-27 16:59:23 -05:00
//+------------------------------------------------------------------+
//| Defines.mqh |
//| Copyright 2026, Niquel Mendoza. |
//| https://www.mql5.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza."
#property link "https://www.mql5.com/"
#property strict
#ifndef PERFECTHASHBYLEO_SRC_DEFINES_MQH
#define PERFECTHASHBYLEO_SRC_DEFINES_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
// LAYOUT [12bit=NumElByBuckets][20bit=StarIndexBucket][32bit=Pos]
//---
#define TSN_PHBL_BIT_START_POS_I (32)
#define TSN_PHBL_BIT_START_I_BUCKET (12)
#define TSN_PHBL_MASK_COUNT (0xFFF)
2026-06-28 12:19:40 -05:00
#define TSN_PHBL_MASK_INDEX_BUCKET (0xFFFFF)
2026-06-27 16:59:23 -05:00
//---
#define TSN_PHBL_GET_COUNT(v) int(v & TSN_PHBL_MASK_COUNT)
2026-06-27 17:51:10 -05:00
#define TSN_PHBL_GET_INDEX(v) int((v >> TSN_PHBL_BIT_START_I_BUCKET) & TSN_PHBL_MASK_INDEX_BUCKET)
#define TSN_PHBL_GET_POS(v) int(v >> TSN_PHBL_BIT_START_POS_I)
2026-06-28 12:19:40 -05:00
//---
2026-06-27 16:59:23 -05:00
#define TSN_PHBL_EMPAQUETAR(c, sib, p) (long(c) | long(sib) << TSN_PHBL_BIT_START_I_BUCKET | long(p) << TSN_PHBL_BIT_START_POS_I)
//---
#ifndef TSN_PHBL_MAX_SIZE_BUCKETS
2026-06-28 19:10:47 -05:00
#define TSN_PHBL_MAX_SIZE_BUCKETS 256
2026-06-27 16:59:23 -05:00
#endif // TSN_PHBL_MAX_SIZE_BUCKETS
2026-06-27 17:52:52 -05:00
//---
2026-06-27 16:59:23 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
template <typename TKey>
interface CPerfectHashHasher
{
2026-06-27 17:52:52 -05:00
#ifdef TSN_PHBL_DESACTIVE_REF
ulong Hash(const TKey v); // key a hash ulong
#else
2026-06-27 16:59:23 -05:00
ulong Hash(const TKey& v); // key a hash ulong
2026-06-27 17:52:52 -05:00
#endif // TSN_PHBL_DESACTIVE_REF
2026-06-27 16:59:23 -05:00
};
//+------------------------------------------------------------------+
template <typename TKey>
interface CPerfectHashHasherWSeed
{
// key a hash ulong con seed
2026-06-27 17:52:52 -05:00
#ifdef TSN_PHBL_DESACTIVE_REF
ulong Hash(const TKey v, const ulong seed);
2026-06-27 19:17:07 -05:00
#else
ulong Hash(const TKey& v, const ulong seed);
2026-06-27 17:52:52 -05:00
#endif // TSN_PHBL_DESACTIVE_REF
2026-06-27 16:59:23 -05:00
};
}
//+------------------------------------------------------------------+
2026-06-27 17:52:52 -05:00
#endif // PERFECTHASHBYLEO_SRC_DEFINES_MQH
//+------------------------------------------------------------------+