Global arrays of the TSN ecosystem
  • MQL5 65.9%
  • MQL4 34.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-08-08 08:42:44 -05:00
Src new files added 2026-08-08 08:42:44 -05:00
LICENSE Actualizar LICENSE 2026-05-16 22:26:24 +00:00
README.md 2026-08-01 17:43:50 -05:00
TsnTables.mqproj Generated by MQL5 Wizard 2026-05-16 16:42:17 -05:00

Low-level base primitives for building fast parsers in MQL5: SWAR byte-scanning tricks, string hashing (FNV-1a, xxHash64), lookup tables for hex decoding and float parsing without pow(), and fast integer-to-string helpers.
No external dependencies — pure MQL5, meant to be included directly by higher-level parsers (JSON, YAML, SetFile, etc.).


Main Features

  • SWAR byte-scanning (Swar.mqh): bit-trick macros (TSNTABLES_SWAR_HAS) to check 8 packed bytes at once against a delimiter mask (", \, ,, :, \n, etc.), plus a De Bruijn lookup table (g_table_i64) to find which byte matched — the base technique for scanning structured-text formats a full machine word at a time instead of byte by byte.
  • String hashing (PHash/): FNV-1a 64-bit (FNV1a_64, plus inlineable FNV1a_64_AsM_* macros) and a full xxHash64 implementation (XSTR::XXH64 for string, XU::XXH64 for uchar[]) — same algorithm, two entry points depending on the buffer type.
  • Fast float parsing tables (Exp.mqh / Pow.mqh): precomputed 1e-308..1e308 tables (g_Exp10, g_Pow10) to convert exponents during string→double conversion without calling MathPow().
  • Hex decoding table (Hex.mqh): 256-entry lookup (g_arr_valid_hex_chars) mapping ASCII to its hex nibble (or 0xFF if invalid), for decoding \xXX / \uXXXX escapes.
  • Fast digit-pair table (DPairs.mqh): 200-entry table (g_tsn_digit_pairs) with pre-built two-digit strings "00".."99", for writing integers two digits at a time instead of one.
  • Escape/unescape sentinels (EscapeUnescape.mqh): shared sentinel codes (0xFD hex, 0xFE unicode, 0xFF invalid/passthrough) that define the contract consumers use when building their own escape tables.

Usage examples

Scan 8 bytes for a delimiter (SWAR):

#include <TsnTables\\Src\\Swar\\Swar.mqh>

ulong word;   // 8 packed bytes read from the buffer
ulong flags = TSNTABLES_SWAR_HAS(word ^ TSNTABLES_SWAR_MASK_COMILLA); // busca '"'
if(flags != 0)
 {
  int byte_index = int(TSNTABLES_SWAR_64_GET_BYTE(flags & (~flags + 1)));
  Print("Comilla encontrada en el byte ", byte_index);
 }

Hash a string (xxHash64):

#include <TsnTables\\Src\\PHash\\XXHash\\Main.mqh>

string s = "hola mundo";
ulong h = TSN::XSTR::XXH64(s, StringLen(s), 5105151ULL);
Print("Hash: ", h);

Convert an exponent without MathPow:

#include <TsnTables\\Src\\Exp.mqh>

double value = 1.5 * TSN::g_Pow10[3]; // 1.5 * 1000.0 = 1500.0

Repository Structure

TsnTables/
├── Src/
│   ├── Swar/                 # SWAR byte-scanning macros + De Bruijn tables
│   │   ├── Swar.mqh
│   │   └── TableConstant.mq5 # script that regenerates the De Bruijn table
│   ├── PHash/                # String hashing algorithms
│   │   ├── AllHash.mqh       # includes both hashers
│   │   ├── FNV1-1A/Main.mqh
│   │   ├── XXHash/           # Def, Main, XString (string), XU (uchar[])
│   │   └── Test.mq5
│   ├── DPairs.mqh            # Digit-pair table for fast int-to-string
│   ├── EscapeUnescape.mqh    # Escape/unescape sentinel codes
│   ├── Exp.mqh               # 1e-308..1e308 table
│   ├── Hex.mqh               # ASCII-to-hex-nibble table
│   ├── Pow.mqh               # 1e0..1e308 table
│   └── Tables.mqh            # true/false byte arrays + misc constants
└── LICENSE

Requirements

  • MetaTrader 5
  • No external dependencies (base repository, no dependencies.json)

Installation

cd "C:\Users\YOUR_USER\AppData\Roaming\MetaQuotes\Terminal\YOUR_ID\MQL5\Shared Projects"
tsndep install "https://forge.mql5.io/nique_372/TsnTables.git"

Requires the tsndep package, available on PyPI. It automatically downloads and installs all declared dependencies.


Quick Start

1. Include the module you need:

#include <TsnTables\\Src\\PHash\\AllHash.mqh>

2. Use it:

ulong h = TSN::FNV1a_64("clave", 5);

License

Read Full License By downloading or using this repository, you accept the license terms.


Contact