open.mp forum
[Plugin] IndexWeaver - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Releases (https://forum.open.mp/forumdisplay.php?fid=13)
---- Forum: Plugins (https://forum.open.mp/forumdisplay.php?fid=32)
---- Thread: [Plugin] IndexWeaver (/showthread.php?tid=4321)



IndexWeaver - itskoleban - 2026-07-14

IndexWeaver
A high-performance, lightweight in-memory ID-to-index registry plugin designed specifically for open.mp.

- The Problem
How many times have you written a linear `for` loop across `MAX_PLAYERS` or `MAX_VEHICLES` just to find the array slot that matches a specific SQL Database ID or an arbitrary key? Linear loops `O(N)` are slow and unnecessary.

- The Solution
IndexWeaver completely eliminates these linear searches. It maps your primary keys (like SQL IDs) directly to your Pawn array slots, allowing your Pawn code to remain the single source of truth for the actual data, while giving you instantaneous O(1) memory lookups.

- Architecture & Performance
IndexWeaver implements a heavily optimized Hybrid Storage Model:
  • Fast Registries (Type 0 - 63): Uses a fixed contiguous array. Erasing elements retains capacity (Zero-Allocation Retention), ensuring that frequent re-insertions (like players reconnecting) never trigger expensive OS heap allocations.
  • Slow Registries (Type >= 64): Uses `robin_hood` flat maps as a dynamic fallback. It features aggressive cleanup; when a registry drops to zero elements, it is safely destroyed to prevent memory leaks in long-running servers.
Benchmarks (MSVC /O2): 10 Million Insertions in ~0.92s, 10 Million Lookups in ~0.62s!

- Pawn API
Code:
native bool:SetMapIndex(registry_type, id, index);
native GetMapIndex(registry_type, id);
native bool:RemoveMapIndex(registry_type, id);
native bool:HasMapIndex(registry_type, id);
native bool:ClearMapRegistry(registry_type);
native ClearAllMapRegistries();
native bool:ReserveMapRegistry(registry_type, capacity);
native bool:SetMapDebugLevel(level);

- Quick Example
Instead of looping through all loaded clans to find the one with `SQL_ID == 850`:
Code:
// Store the index when loading from the database
SetMapIndex(REGISTRY_CLANS, 850, array_slot);

// Later, instantly retrieve the slot! No loops!
new slot = GetMapIndex(REGISTRY_CLANS, 850);
if(slot != INVALID_MAP_INDEX) {
    printf("Clan Name: %s", ClanData[slot][cName]);
}

- Download & Source Code
The plugin is entirely open-source, beautifully documented, and cross-platform (Windows/Linux).

Contributions and Pull Requests are welcome!