- MQL5 92%
- MQL4 8%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| Src | ||
| dependencies.json | ||
| EA.mq5 | ||
| LICENSE | ||
| README.md | ||
| SimPHash.mqproj | ||
Simple perfect hash generator, driven by a YAML config file.
Runs as an EA: reads your key/value map from
YAML, builds a perfect hash with PerfectHashByLeo,
and emits a ready-to-include .mqh with the tables and lookup function already written.
Main Features
- YAML-driven, no code required: you don't write the perfect hash tables by hand — you list your keys (and optionally values) in a YAML file, run the EA once, and it generates the
.mqhfor you. - Two swappable hash stages, matching how PerfectHashByLeo works internally (bucket hash + final displacement hash):
- Bucket hash (
hash.type): converts each string key into aulongbefore bucketing. Supported:TSN_PHASH_TYPE_FNV1A_64(FNV-1a 64-bit, with configurablebasis/prime) andTSN_PHASH_TYPE_XXHASH_64(xxHash64, with a configurableseed). - Final hash (
final_hash): the per-bucket displacement hash, applied to the already-bucketedulongkey plus a seed. Supported:HASH_UL1_MUR_MUR(MurMur-style finalizer),HASH_UL1_SPLITMIX(SplitMix64),HASH_UL1_FMIX(MurmurHash3 fmix64 finalizer),HASH_UL1_FIBBO(Fibonacci hashing).
- Bucket hash (
- Two output modes: either a table of final values (
map_use_value: true— the generated function returns your mapped value directly) or a table of indices (map_use_value: false— the function returns a position into your own array, which is useful when the value is too complex to inline). - Optional binary export: alongside the
.mqh, you can dump the seeds/hashes/values/meta as raw.binfiles (useful if you want to load the table at runtime instead of compiling it in). - Generates a complete, working lookup function — both a
string-keyed overload and a pre-hashedulong-keyed overload, so callers who already computed the hash elsewhere can skip re-hashing.
YAML config parameters
| Parameter | Description |
|---|---|
max_attepms |
Maximum displacement attempts (seed values 0, 1, 2, ...) tried per bucket before giving up. |
namespace |
Namespace the generated tables/function are wrapped in (leave empty/null to skip). |
file_name_out |
Full path of the .mqh file to generate. |
table_prefix |
Prefix used for all generated table names (<prefix>_seeds, <prefix>_hashes, <prefix>_values/<prefix>_tindex). |
copyright |
Text written into the generated file's #property copyright. |
link |
Text written into the generated file's #property link. |
func_name |
Name of the generated lookup function. |
def_name_table_size |
Name of the #define for the final table size. |
def_bucket_size_name |
Name of the #define for the bucket count. |
invalid_value |
Value returned by the generated function when a key isn't found (also used to fill unused slots). |
comment_funct |
If true, the generated function body is wrapped in /* */ (useful when you only want the tables and will write the function yourself). |
guard_name |
Optional #ifndef/#define include guard name for the generated file. |
bin |
Optional object with seeds, values, hash and meta file paths — if present, the raw tables are also written as binary files. |
hash.type |
Bucket hash algorithm: TSN_PHASH_TYPE_FNV1A_64 or TSN_PHASH_TYPE_XXHASH_64. |
hash.config.basis / hash.config.prime |
FNV-1a offset basis / prime (use def for the standard FNV-1a-64 constants). |
hash.config.seed |
xxHash64 seed (only used when hash.type is TSN_PHASH_TYPE_XXHASH_64). |
final_hash |
Final displacement hash: HASH_UL1_MUR_MUR, HASH_UL1_SPLITMIX, HASH_UL1_FMIX or HASH_UL1_FIBBO. |
perfect_hash.elements_por_bucket |
Target average number of keys per bucket (lower = more buckets, generally faster to find a working seed). |
perfect_hash.load_factor |
Final table load factor (keys / final table size) — lower leaves more free slots, easing displacement at the cost of memory. |
map_use_value |
true = generate a values table (function returns the value directly); false = generate an indices table (function returns a position for you to index your own array with). |
map |
The key set itself: a YAML object (KEY: value) when map_use_value: true, or an array of keys otherwise. |
Usage example
# config.yaml
max_attepms: 15000
namespace: TSN
file_name_out: C:\Path\To\Out.mqh
table_prefix: g_table_test
copyright: Copyright 2026, Niquel Mendoza
link: https://www.mql5.com/
func_name: HashCustom
invalid_value: -1
hash:
type: TSN_PHASH_TYPE_FNV1A_64
config:
basis: def
prime: def
final_hash: HASH_UL1_MUR_MUR
perfect_hash:
elements_por_bucket: 3
load_factor: 0.81
map_use_value: true
map: { UNO: 1, DOS: 2, TRES: 3, CUATRO: 4, CINCO: 5 }
Run the EA (EA.mq5) pointing InpYamlFileName to this config, and it generates Out.mqh with the seed/hash/value tables plus a ready HashCustom(const string& key) / HashCustom(const ulong key_hash) function.
Repository Structure
SimPHash/
└── Src/ # Generator, hash strategies (Hash/), YAML enum registry (EnumReg/), and test config/output
⚠️ License Notice
This repository requires access to two private repositories (YamlParserByLeo, ExtraCodes)
to compile. See Requirements above for how to obtain access.
Requirements
See dependencies.json for the full list.
Installation
cd "C:\Users\YOUR_USER\AppData\Roaming\MetaQuotes\Terminal\YOUR_ID\MQL5\Shared Projects"
tsndep install "https://forge.mql5.io/nique_372/SimPHash.git"
Requires the tsndep package, available on PyPI. It automatically downloads and installs all declared dependencies.
Quick Start
1. Download the latest EA from the releases section of the repository: https://forge.mql5.io/nique_372/SimPHash/releases
2. Write your YAML config (see parameters and example above).
3. Point EA.mq5 at it and run it:
input string InpYamlFileName = "C:\\...\\config.yaml";
4. Include the generated .mqh in your project and call the generated function.
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