FastCollections-FastHashMap/Src/ColHash/HashMap/Nor.mqh
2026-07-21 11:09:28 -05:00

74 lines
3 KiB
MQL5

//+------------------------------------------------------------------+
//| Nor.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_HASHMAP_NOR_MQH
#define FASTCOLLECTIONSBYLEO_COLHASH_HASHMAP_NOR_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "Main.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#define CHashMapFast(k, v) TSN::CHashMapFastNor<k, v, TSN::CGenericHash_##k>
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
template <typename TKey, typename TValue, typename TBase>
class CHashMapFastNor : public CHashMapFastBase<TKey, TValue, TBase>
{
public:
CHashMapFastNor(int initial_size = 128) : CHashMapFastBase<TKey, TValue, TBase>(initial_size) {}
~CHashMapFastNor(void) {}
//---
using CFastHashTableBase<CHashMapFastInternalPar<TKey, TValue>, TKey, TBase>::Add;
//---
__forceinline bool Add(const TKey& key, TValue v);
bool TrySet(const TKey& key, TValue value);
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
template <typename TKey, typename TValue, typename TBase>
bool CHashMapFastNor::TrySet(const TKey& key, TValue value)
{
//---
const int slot = Find(key);
if(slot == -1)
return false;
m_table[slot].value = value;
return true;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
template <typename TKey, typename TValue, typename TBase>
__forceinline bool CHashMapFastNor::Add(const TKey& key, TValue v)
{
if(Add(key))
{
m_table[m_last_created_pos].value = v;
return true;
}
return false;
}
}
#endif //FASTCOLLECTIONSBYLEO_COLHASH_HASHMAP_NOR_MQH