No description
- MQL5 98.4%
- MQL4 1.6%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| Src/ColHash | ||
| Test | ||
| dependencies.json | ||
| FastCollectionsByLeo.mqproj | ||
| LICENSE | ||
| README.md | ||
Fast generic collections for MQL5 (HashMap, HashSet), based on a Swiss-table-style design.
Groups of 8 slots with a metadata byte array, scanned via SWAR bit-tricks instead of comparing keys one by one.
Main Features
- Swiss-table hash engine (
CFastHashTableBase): shared base for both HashMap and HashSet. Slots are grouped 8 at a time; each group has one metadataulong(one control byte per slot: empty, deleted, or 7 bits of the key's hash). Lookups scan a whole group in one SWAR pass instead of probing slot by slot. CHashMapFast(key, value): generic hash map on top of the engine, with key/value pairs, iteration,TryGet,CopyTo,GetValues.CHashSetFast(key): generic hash set on the same engine, key-only, withAdd/Contains/Remove/iteration.- Pluggable hash functions (
Generic.mqh): swap the hashing strategy per key type via thePvariant of the macros. Built-in: FNV-1a (default forstring), djb2, xxHash64 (string), and forulongkeys splitmix64, fmix64 (MurmurHash3 finalizer), Fibonacci hashing, and MurmurHash3-style mixing. - Depends on TsnTables for the SWAR macros and De Bruijn tables that make the group scan fast.
Usage examples
HashMap:
void OnStart()
{
CHashMapFast(string, int) map;
map.Add("hola", 10);
map.Add("cinco", 10);
map.Add("My key:", 20);
map.Add("Yo: ", 20);
CHashMapFastIterator(string, int) it = map.BeginIteration();
while(it.IsValid())
{
Print(it.Key(), " = ", it.Val());
it.Next();
}
}
HashSet:
void OnStart()
{
CHashSetFast(string) set;
set.Add("hola");
set.Add("como");
set.Add("siuu");
Print(set.Contains("hola"));
}
Using a different hash function for the same key type:
CHashMapFastP(ulong, int, _murmur) map; // usa CGenericHash_ulong_murmur en vez del hash por defecto
Hash map benchmarks
- Access test over 100,000 iterations
- Converting
ENUM_TIMEFRAMES(string) to integer - Same PC used for all tests
| Class | Time (microseconds, 100,000 iterations) |
|---|---|
| Perfect Hash | ~1705 |
| CHashMapFast | 1925–1949 |
| CDictSValue | 2438–2466 |
| CHashMap | 8750–8827 |
| Linear | 9818–9869 |
Test in Final.mq5
Repository Structure
FastCollectionsByLeo/
├── Src/ # HashMap/HashSet engine and generic hash functions
└── Test/ # Benchmarks and usage scripts
Requirements
See dependencies.json for the full list.
- MetaTrader 5, build 5430+
- TsnTables (SWAR macros)
Installation
cd "C:\Users\YOUR_USER\AppData\Roaming\MetaQuotes\Terminal\YOUR_ID\MQL5\Shared Projects"
tsndep install "https://forge.mql5.io/nique_372/FastCollectionsByLeo.git"
Requires the tsndep package, available on PyPI. It automatically downloads and installs all declared dependencies.
Quick Start
1. Include the collection you need:
// TSN Wrrapers Include style
#include <TSN\\GCol\\HashMap.mqh>
#include <TSN\\GCol\\GenericHashes.mqh
2. Use it:
CHashMapFast(string, int) map;
map.Add("clave", 1);
License
Read Full License By downloading or using this repository, you accept the license terms.
Contact
- Platform: MQL5 Community
- Profile: https://www.mql5.com/es/users/nique_372
- Articles: https://www.mql5.com/es/users/nique_372/publications