//+------------------------------------------------------------------+ //| Main.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_MAIN_MQH #define FASTCOLLECTIONSBYLEO_COLHASH_HASHMAP_MAIN_MQH //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include "..\\HashBases\\Main.mqh" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #define CHashMapFastIterator(k, v) TSN::CHashMapFastIteratorInt //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ namespace TSN { //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ template struct CHashMapFastIteratorInt; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ template struct CHashMapFastInternalPar { TKey key; TValue value; ulong hash; }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ template class CHashMapFastBase : public CFastHashTableBase, TKey, TBase> { public: CHashMapFastBase(int initial_size = 128) { Init(initial_size); } ~CHashMapFastBase(void) {} //--- bool TryGet(const TKey& key, TValue& out) const; //--- int CopyTo(TKey& keys[], TValue& values[]) const; //--- CHashMapFastIteratorInt BeginIteration(); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ template int CHashMapFastBase::CopyTo(TKey& keys[], TValue& values[]) const { ArrayResize(keys, m_count); ArrayResize(values, m_count); int out_idx = 0; for(int group = 0; group < m_num_groups; group++) { ulong occupied_mask = (m_meta[group] & MQLARTICLES_HASHMAP_MASK_HIGH_BIT) ^ MQLARTICLES_HASHMAP_MASK_HIGH_BIT; while(occupied_mask != 0) { const ulong flag = TSNTABLES_SWAR_64_DEJAR_SOLO_MINUS_SIG_BYTE(occupied_mask); const int slot = (group << 3) + TSNTABLES_SWAR_64_GET_BYTE(flag); keys[out_idx] = m_table[slot].key; values[out_idx] = m_table[slot].value; out_idx++; occupied_mask &= (occupied_mask - 1); } } return out_idx; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ template bool CHashMapFastBase::TryGet(const TKey& key, TValue& out) const { //--- const int slot = Find(key); if(slot == -1) return false; out = m_table[slot].value; return true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ template CHashMapFastIteratorInt CHashMapFastBase::BeginIteration() { return CHashMapFastIteratorInt(&this); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ template struct CHashMapFastIteratorInt : public CFastHashTableIteratorBase, TKey> { CHashMapFastIteratorInt(CHashMapFastBase* ptr) : CFastHashTableIteratorBase, TKey>(ptr) { } CHashMapFastIteratorInt() {} //--- __forceinline TValue Val() const { return m_ctx.m_table[m_current_slot].value; } }; } //+------------------------------------------------------------------+ #endif // FASTCOLLECTIONSBYLEO_COLHASH_HASHMAP_MAIN_MQH