I have nothing against StringMap but, at certain times and in certain ways, it's inadequate.
I made OrdMap because I wanted a hash table that had the following qualities:
- Must preserve insertion order.
- Work performantly, OrdMap is a completely array-based hash table. No linked-lists involved.
- More type-safe by having a type tag for each entry.
- From having type-safety, getting the length of an entry's string or array.
- Being able to use integer indexes to access an entry.
Also as part of the library, you can use integers, floats, and other cell-based data as keys by using operations that end with 'CellKey'.
OrdMap methods that give string length will give the length + 1 for null terminator as compared to the length of an array.
PHP Code:
OrdMap g_players;
public void OnPluginStart() {
g_players = new OrdMap();
for( int i=MaxClients; i; i-- )
if( IsClientInGame(i) )
OnClientPutInServer(i);
}
public void OnClientPutInServer(int client) {
g_players.SetCellByCellKey(client, GetClientUserId(client));
}
public void OnClientDisconnect(int client) {
g_players.RemoveByCellKey(client);
}
public void OnGameFrame() {
int entries = g_players.Len;
for( int i; i<entries; i++ ) {
int userid;
if( !g_players.GetCellByIndex(i, userid) || userid <= 0 )
continue;
int client = GetClientOfUserId(userid);
if( client <= 0 )
continue;
/// code here.
}
}
Source Repo
__________________