Raised This Month: $32 Target: $400
 8% 

[A N Y] OrdMap - Order-preserving hash table.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nergal
Veteran Member
Join Date: Apr 2012
Old 03-14-2021 , 20:45   [A N Y] OrdMap - Order-preserving hash table.
Reply With Quote #1

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=MaxClientsii-- )
        if( 
IsClientInGame(i) )
            
OnClientPutInServer(i);
}

public 
void OnClientPutInServer(int client) {
    
g_players.SetCellByCellKey(clientGetClientUserId(client));
}

public 
void OnClientDisconnect(int client) {
    
g_players.RemoveByCellKey(client);
}

public 
void OnGameFrame() {
    
int entries g_players.Len;
    for( 
int ii<entriesi++ ) {
        
int userid;
        if( !
g_players.GetCellByIndex(iuserid) || userid <= )
            continue;
        
        
int client GetClientOfUserId(userid);
        if( 
client <= )
            continue;
        
        
/// code here.
    
}

Source Repo
__________________

Last edited by nergal; 03-15-2021 at 20:14.
nergal is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode