Generic collection library (HashMap, etc.) Fast
  • MQL5 98.4%
  • MQL4 1.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-08-04 15:59:08 -05:00
Src/ColHash comentario extra para seguridad 2026-08-04 15:59:08 -05:00
Test 2026-07-19 09:25:59 -05:00
dependencies.json Añadir dependencies.json 2026-07-19 13:37:42 +00:00
FastCollectionsByLeo.mqproj Generated by MQL5 Wizard 2026-07-19 08:23:37 -05:00
LICENSE Añadir LICENSE 2026-07-19 13:37:10 +00:00
README.md new files added 2026-08-01 17:50:36 -05:00

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 metadata ulong (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, with Add/Contains/Remove/iteration.
  • Pluggable hash functions (Generic.mqh): swap the hashing strategy per key type via the P variant of the macros. Built-in: FNV-1a (default for string), djb2, xxHash64 (string), and for ulong keys 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