#include "copyright.h"
#include "autoconf.h"
#include "config.h"
#include "externs.h"
Include dependency graph for htab.cpp:
Go to the source code of this file.
Functions | |
void | hashreset (CHashTable *htab) |
Reset hash table statistics. | |
void * | hashfindLEN (const void *pKey, size_t nKey, CHashTable *htab) |
Look for a previously-added (Key, Data) pair in a hash table, and return its data pointer. | |
int | hashaddLEN (const void *pKey, size_t nKey, void *pData, CHashTable *htab) |
Add a new (Key, Data) pair to a hash table. | |
void | hashdeleteLEN (const void *pKey, size_t nKey, CHashTable *htab) |
Removes a (Key, Data) pair from a hash table. | |
void | hashflush (CHashTable *htab) |
Removes all (Key, Data) entries in a hash table. | |
bool | hashreplLEN (const void *str, size_t nStr, void *pData, CHashTable *htab) |
void | hashreplall (const void *old, void *new0, CHashTable *htab) |
void * | hash_firstentry (CHashTable *htab) |
void * | hash_nextentry (CHashTable *htab) |
void * | hash_firstkey (CHashTable *htab, int *nKeyLength, char **pKey) |
void * | hash_nextkey (CHashTable *htab, int *nKeyLength, char **pKey) |
bool | search_nametab (dbref player, NAMETAB *ntab, char *flagname, int *pflag) |
NAMETAB * | find_nametab_ent (dbref player, NAMETAB *ntab, char *flagname) |
void | display_nametab (dbref player, NAMETAB *ntab, char *prefix, bool list_if_none) |
void | interp_nametab (dbref player, NAMETAB *ntab, int flagword, const char *prefix, const char *true_text, const char *false_text) |
void | listset_nametab (dbref player, NAMETAB *ntab, int flagword, char *prefix, bool list_if_none) |
CF_HAND (cf_ntab_access) | |
Variables | |
struct { | |
void * pData | |
char aKey [LBUF_SIZE+125] | |
} | htab_rec |
Staging area for reads and writes into CHashTable. |
The functions here outsource most of their work to CHashTable. There are several reasons to use the functions here instead of using CHashTable directly: 1) they are briefer to use, 2) this interface predates CHashTable, 3) there are many references to these functions throughout the code, and 4) MUSH hardcoders are generally more familiar with this interface than with the CHashTable interface.
To replace them all would require rexamining the assumptions near every reference.
CHashTable is not aware of Keys -- only hashes of Keys. In fact, CHashTable could not tell you anything about the Keys kept within its records. It will give you all the records stored under a specific hash, but it leaves to its callers the small chore of looking in each record for a desired Key.
Definition in file htab.cpp.
CF_HAND | ( | cf_ntab_access | ) |
Definition at line 458 of file htab.cpp.
References cf_modify_bits(), name_table::minlen, minmatch(), mux_isspace, name_table::name, and name_table::perm.
00459 { 00460 NAMETAB *np; 00461 char *ap; 00462 00463 for (ap = str; *ap && !mux_isspace(*ap); ap++) 00464 { 00465 ; // Nothing. 00466 } 00467 if (*ap) 00468 { 00469 *ap++ = '\0'; 00470 } 00471 00472 while (mux_isspace(*ap)) 00473 { 00474 ap++; 00475 } 00476 00477 for (np = (NAMETAB *) vp; np->name; np++) 00478 { 00479 if (minmatch(str, np->name, np->minlen)) 00480 { 00481 return cf_modify_bits(&(np->perm), ap, pExtra, nExtra, player, cmd); 00482 } 00483 } 00484 cf_log_notfound(player, cmd, "Entry", str); 00485 return -1; 00486 }
Definition at line 353 of file htab.cpp.
References alloc_lbuf, check_access(), God, name_table::name, name_table::perm, safe_chr, and safe_str.
Referenced by do_list(), do_list_file(), and list_cmdswitches().
00354 { 00355 NAMETAB *nt; 00356 bool got_one = false; 00357 char *buf = alloc_lbuf("display_nametab"); 00358 char *bp = buf; 00359 00360 safe_str(prefix, buf, &bp); 00361 for (nt = ntab; nt->name; nt++) 00362 { 00363 if ( God(player) 00364 || check_access(player, nt->perm)) 00365 { 00366 safe_chr(' ', buf, &bp); 00367 safe_str(nt->name, buf, &bp); 00368 got_one = true; 00369 } 00370 } 00371 *bp = '\0'; 00372 if ( got_one 00373 || list_if_none) 00374 { 00375 notify(player, buf); 00376 } 00377 free_lbuf(buf); 00378 }
Definition at line 331 of file htab.cpp.
References check_access(), name_table::minlen, minmatch(), name_table::name, and name_table::perm.
Referenced by CF_HAND().
00332 { 00333 NAMETAB *nt; 00334 00335 for (nt = ntab; nt->name; nt++) 00336 { 00337 if (minmatch(flagname, nt->name, nt->minlen)) 00338 { 00339 if (check_access(player, nt->perm)) 00340 { 00341 return nt; 00342 } 00343 } 00344 } 00345 return NULL; 00346 }
void* hash_firstentry | ( | CHashTable * | htab | ) |
Definition at line 246 of file htab.cpp.
References CHashTable::FindFirst(), HF_FIND_END, and htab_rec.
Referenced by dbclean_CheckANHtoAT(), do_chanlist(), do_channelnuke(), do_listchannels(), FUNCTION(), helpindex_clean(), ReportMatchedTopics(), and save_comsystem().
00247 { 00248 HP_HEAPLENGTH nRecord; 00249 HP_DIRINDEX iDir = htab->FindFirst(&nRecord, &htab_rec); 00250 if (iDir != HF_FIND_END) 00251 { 00252 return htab_rec.pData; 00253 } 00254 return NULL; 00255 }
void* hash_firstkey | ( | CHashTable * | htab, | |
int * | nKeyLength, | |||
char ** | pKey | |||
) |
Definition at line 268 of file htab.cpp.
References CHashTable::FindFirst(), HF_FIND_END, and htab_rec.
Referenced by dbclean_RenumberAttributes(), and do_listcommands().
00269 { 00270 HP_HEAPLENGTH nRecord; 00271 HP_DIRINDEX iDir = htab->FindFirst(&nRecord, &htab_rec); 00272 if (iDir != HF_FIND_END) 00273 { 00274 *nKeyLength = nRecord-sizeof(int *); 00275 *pKey = htab_rec.aKey; 00276 return htab_rec.pData; 00277 } 00278 *nKeyLength = 0; 00279 *pKey = NULL; 00280 return NULL; 00281 }
void* hash_nextentry | ( | CHashTable * | htab | ) |
Definition at line 257 of file htab.cpp.
References CHashTable::FindNext(), HF_FIND_END, and htab_rec.
Referenced by dbclean_CheckANHtoAT(), do_chanlist(), do_channelnuke(), do_listchannels(), FUNCTION(), helpindex_clean(), ReportMatchedTopics(), and save_comsystem().
00258 { 00259 HP_HEAPLENGTH nRecord; 00260 HP_DIRINDEX iDir = htab->FindNext(&nRecord, &htab_rec); 00261 if (iDir != HF_FIND_END) 00262 { 00263 return htab_rec.pData; 00264 } 00265 return NULL; 00266 }
void* hash_nextkey | ( | CHashTable * | htab, | |
int * | nKeyLength, | |||
char ** | pKey | |||
) |
Definition at line 283 of file htab.cpp.
References CHashTable::FindNext(), HF_FIND_END, and htab_rec.
Referenced by dbclean_RenumberAttributes(), and do_listcommands().
00284 { 00285 HP_HEAPLENGTH nRecord; 00286 HP_DIRINDEX iDir = htab->FindNext(&nRecord, &htab_rec); 00287 if (iDir != HF_FIND_END) 00288 { 00289 *nKeyLength = nRecord-sizeof(int *); 00290 *pKey = htab_rec.aKey; 00291 return htab_rec.pData; 00292 } 00293 *nKeyLength = 0; 00294 *pKey = NULL; 00295 return NULL; 00296 }
int hashaddLEN | ( | const void * | pKey, | |
size_t | nKey, | |||
void * | pData, | |||
CHashTable * | htab | |||
) |
Add a new (Key, Data) pair to a hash table.
hashaddLEN() associates a variable-sized key with a pointer using a hash table. The pointer, pData, given to hashaddLEN() may be obtained again later by presenting the the same key to hashfindLEN(). The data given in (pKey, nKey) is saved, so the caller is free to reuse the Key buffer. While the value of pData is also saved, the data that pData points to is not.
This function requires that the Key does not already exist in the hash table. It may be necessary to use hashfindLEN() to insure this.
pKey | Pointer to Key of (Key, Data) pair to add. | |
nKey | Size (in bytes) of the above Key. | |
pData | Pointer to Data part of (Key, Data) pair. | |
htab | Hash Table. |
Definition at line 123 of file htab.cpp.
References HASH_ProcessBuffer(), htab_rec, and CHashTable::Insert().
Referenced by add_helpfile(), add_player_name(), MailList::AppendItem(), atr_match1(), cache_get(), cache_put(), CF_HAND(), commands_no_arg_add(), commands_one_arg_add(), commands_one_arg_cmdarg_add(), commands_two_arg_add(), commands_two_arg_argv_add(), commands_two_arg_argv_cmdarg_add(), commands_two_arg_cmdarg_add(), desc_addhash(), do_addcommand(), do_createchannel(), do_delcommand(), do_function(), find_wild_attrs(), flag_rename(), function_add(), functions_add(), fwdlist_set(), helpindex_read(), init_attrtab(), init_cmdtab(), init_flagtab(), init_logout_cmdtab(), init_powertab(), load_comsystem(), look_atrs1(), and pcache_find().
00124 { 00125 if ( pKey == NULL 00126 || nKey <= 0) 00127 { 00128 return -1; 00129 } 00130 00131 UINT32 nHash = HASH_ProcessBuffer(0, pKey, nKey); 00132 00133 htab_rec.pData = pData; 00134 memcpy(htab_rec.aKey, pKey, nKey); 00135 size_t nRecord = nKey + sizeof(void *); 00136 htab->Insert((HP_HEAPLENGTH)nRecord, nHash, &htab_rec); 00137 return 0; 00138 }
void hashdeleteLEN | ( | const void * | pKey, | |
size_t | nKey, | |||
CHashTable * | htab | |||
) |
Removes a (Key, Data) pair from a hash table.
hashdeleteLEN() disassociates a variable-sized Key from its Data pointer by removing the (Key, Data) pair from the hash table and freeing any related storage. However, it is the caller's responsibility to free any memory that Data points to.
pKey | The Key to remove. | |
nKey | Size (in bytes) of the above Key. | |
htab | Hash Table. |
Definition at line 153 of file htab.cpp.
References CHashTable::Copy(), CHashTable::FindFirstKey(), CHashTable::FindNextKey(), HASH_ProcessBuffer(), HF_FIND_END, htab_rec, and CHashTable::Remove().
Referenced by add_helpfile(), cache_del(), cache_put(), delete_player_name(), desc_delhash(), do_addcommand(), do_channelnuke(), do_delcommand(), do_destroychannel(), do_flag(), fwdlist_clr(), pcache_trim(), MailList::RemoveAll(), MailList::RemoveItem(), and TrimCache().
00154 { 00155 if ( pKey == NULL 00156 || nKey <= 0) 00157 { 00158 return; 00159 } 00160 00161 UINT32 nHash = HASH_ProcessBuffer(0, pKey, nKey); 00162 00163 HP_DIRINDEX iDir = htab->FindFirstKey(nHash); 00164 while (iDir != HF_FIND_END) 00165 { 00166 HP_HEAPLENGTH nRecord; 00167 htab->Copy(iDir, &nRecord, &htab_rec); 00168 size_t nTarget = nRecord - sizeof(int *); 00169 00170 if ( nTarget == nKey 00171 && memcmp(pKey, htab_rec.aKey, nKey) == 0) 00172 { 00173 htab->Remove(iDir); 00174 } 00175 iDir = htab->FindNextKey(iDir, nHash); 00176 } 00177 }
void* hashfindLEN | ( | const void * | pKey, | |
size_t | nKey, | |||
CHashTable * | htab | |||
) |
Look for a previously-added (Key, Data) pair in a hash table, and return its data pointer.
Given a variable-sized Key, hashfindLEN() uses the associations previously created with hashaddLEN() to find and return the corresponding 'Data' part of a (Key, Data) pair, if it exists.
NULL is returned if the request is not valid or if the (Key, Data) pair is not found.
pKey | Pointer to Key to find. | |
nKey | Size (in bytes) of the above Key. | |
htab | Hash Table. |
Definition at line 76 of file htab.cpp.
References CHashTable::Copy(), CHashTable::FindFirstKey(), CHashTable::FindNextKey(), HASH_ProcessBuffer(), HF_FIND_END, HF_FIND_FIRST, and htab_rec.
Referenced by add_player_name(), MailList::AppendItem(), atr_match1(), atr_str(), cache_del(), cache_get(), cache_put(), CF_HAND(), check_command(), commands_no_arg_add(), commands_one_arg_add(), commands_one_arg_cmdarg_add(), commands_two_arg_add(), commands_two_arg_argv_add(), commands_two_arg_argv_cmdarg_add(), commands_two_arg_cmdarg_add(), dbclean_CheckATtoANH(), decode_power(), delete_player_name(), desc_addhash(), desc_delhash(), do_addcommand(), do_command(), do_delcommand(), do_destroychannel(), do_flag(), do_function(), do_hook(), do_icmd(), do_listcommands(), do_quitprog(), find_flag(), find_power(), find_wild_attrs(), MailList::FirstItem(), flag_rename(), FUNCTION(), fwdlist_get(), handle_prog(), help_helper(), help_write(), helpindex_read(), init_flagtab(), init_powertab(), look_atrs1(), lookup_player(), mux_exec(), pcache_find(), process_command(), MailList::RemoveAll(), and select_channel().
00077 { 00078 if ( pKey == NULL 00079 || nKey <= 0) 00080 { 00081 return NULL; 00082 } 00083 00084 UINT32 nHash = HASH_ProcessBuffer(0, pKey, nKey); 00085 00086 HP_DIRINDEX iDir = HF_FIND_FIRST; 00087 iDir = htab->FindFirstKey(nHash); 00088 while (iDir != HF_FIND_END) 00089 { 00090 HP_HEAPLENGTH nRecord; 00091 htab->Copy(iDir, &nRecord, &htab_rec); 00092 size_t nTarget = nRecord - sizeof(int *); 00093 00094 if ( nTarget == nKey 00095 && memcmp(pKey, htab_rec.aKey, nKey) == 0) 00096 { 00097 return htab_rec.pData; 00098 } 00099 iDir = htab->FindNextKey(iDir, nHash); 00100 } 00101 return NULL; 00102 }
void hashflush | ( | CHashTable * | htab | ) |
Removes all (Key, Data) entries in a hash table.
The Hash Table is re-initialized from scratch and all storage is reclaimed. The resulting Hash Table is empty.
htab | Hash Table. |
Definition at line 188 of file htab.cpp.
References CHashTable::Reset().
Referenced by atr_match(), look_atrs(), and parse_attrib_wild().
00189 { 00190 htab->Reset(); 00191 }
void hashreplall | ( | const void * | old, | |
void * | new0, | |||
CHashTable * | htab | |||
) |
Definition at line 227 of file htab.cpp.
References CHashTable::FindFirst(), CHashTable::FindNext(), HF_FIND_END, htab_rec, and CHashTable::Update().
Referenced by do_addcommand(), and do_delcommand().
00228 { 00229 HP_HEAPLENGTH nRecord; 00230 for ( HP_DIRINDEX iDir = htab->FindFirst(&nRecord, &htab_rec); 00231 iDir != HF_FIND_END; 00232 iDir = htab->FindNext(&nRecord, &htab_rec)) 00233 { 00234 if (htab_rec.pData == old) 00235 { 00236 htab_rec.pData = new0; 00237 htab->Update(iDir, nRecord, &htab_rec); 00238 } 00239 } 00240 }
bool hashreplLEN | ( | const void * | str, | |
size_t | nStr, | |||
void * | pData, | |||
CHashTable * | htab | |||
) |
Definition at line 198 of file htab.cpp.
References CHashTable::Copy(), CHashTable::FindFirstKey(), CHashTable::FindNextKey(), HASH_ProcessBuffer(), HF_FIND_END, htab_rec, and CHashTable::Update().
Referenced by add_player_name(), desc_addhash(), desc_delhash(), fwdlist_set(), and MailList::RemoveItem().
00199 { 00200 if ( str == NULL 00201 || nStr <= 0) 00202 { 00203 return false; 00204 } 00205 00206 UINT32 nHash = HASH_ProcessBuffer(0, str, nStr); 00207 00208 HP_DIRINDEX iDir = htab->FindFirstKey(nHash); 00209 while (iDir != HF_FIND_END) 00210 { 00211 HP_HEAPLENGTH nRecord; 00212 htab->Copy(iDir, &nRecord, &htab_rec); 00213 size_t nTarget = nRecord - sizeof(int *); 00214 00215 if ( nTarget == nStr 00216 && memcmp(str, htab_rec.aKey, nStr) == 0) 00217 { 00218 htab_rec.pData = pData; 00219 htab->Update(iDir, nRecord, &htab_rec); 00220 return true; 00221 } 00222 iDir = htab->FindNextKey(iDir, nHash); 00223 } 00224 return false; 00225 }
void hashreset | ( | CHashTable * | htab | ) |
Reset hash table statistics.
Each Hash Table maintains certain statistics regarding the type and number of requests they receive as well as the hash table's performance in responding to those requests. The hashreset() function allows callers to reset these statistics. Typically, this is done when the caller knows future access patterns are of more interest than past access paterns.
htab | Hash Table. |
Definition at line 39 of file htab.cpp.
References CHashTable::ResetStats().
Referenced by helpindex_read(), and main().
00040 { 00041 htab->ResetStats(); 00042 }
void interp_nametab | ( | dbref | player, | |
NAMETAB * | ntab, | |||
int | flagword, | |||
const char * | prefix, | |||
const char * | true_text, | |||
const char * | false_text | |||
) |
Definition at line 384 of file htab.cpp.
References alloc_lbuf, check_access(), God, name_table::name, safe_chr, and safe_str.
Referenced by do_list().
00386 { 00387 bool bFirst = true; 00388 char *buf = alloc_lbuf("interp_nametab"); 00389 char *bp = buf; 00390 00391 safe_str(prefix, buf, &bp); 00392 for (NAMETAB *nt = ntab; nt->name; nt++) 00393 { 00394 if ( God(player) 00395 || check_access(player, nt->perm)) 00396 { 00397 if (!bFirst) 00398 { 00399 safe_chr(';', buf, &bp); 00400 bFirst = false; 00401 } 00402 safe_chr(' ', buf, &bp); 00403 safe_str(nt->name, buf, &bp); 00404 safe_str("...", buf, &bp); 00405 if ((flagword & nt->flag) != 0) 00406 { 00407 safe_str(true_text, buf, &bp); 00408 } 00409 else 00410 { 00411 safe_str(false_text, buf, &bp); 00412 } 00413 } 00414 } 00415 *bp = '\0'; 00416 notify(player, buf); 00417 free_lbuf(buf); 00418 }
void listset_nametab | ( | dbref | player, | |
NAMETAB * | ntab, | |||
int | flagword, | |||
char * | prefix, | |||
bool | list_if_none | |||
) |
Definition at line 424 of file htab.cpp.
References alloc_lbuf, check_access(), name_table::flag, free_lbuf, God, name_table::name, notify, name_table::perm, safe_chr, and safe_str.
Referenced by list_attraccess(), list_cf_access(), list_cmdaccess(), and list_vattrs().
00425 { 00426 char *buf = alloc_lbuf("listset_nametab"); 00427 char *bp = buf; 00428 00429 safe_str(prefix, buf, &bp); 00430 00431 NAMETAB *nt = ntab; 00432 bool got_one = false; 00433 while (nt->name) 00434 { 00435 if ( ((flagword & nt->flag) != 0) 00436 && ( God(player) 00437 || check_access(player, nt->perm))) 00438 { 00439 safe_chr(' ', buf, &bp); 00440 safe_str(nt->name, buf, &bp); 00441 got_one = true; 00442 } 00443 nt++; 00444 } 00445 *bp = '\0'; 00446 if ( got_one 00447 || list_if_none) 00448 { 00449 notify(player, buf); 00450 } 00451 free_lbuf(buf); 00452 }
Definition at line 303 of file htab.cpp.
References check_access(), name_table::flag, name_table::minlen, minmatch(), name_table::name, and name_table::perm.
Referenced by CF_HAND(), do_attribute(), do_global(), do_list(), do_list_file(), do_set(), FUNCTION(), get_obj_and_lock(), process_cmdent(), and process_command().
00304 { 00305 NAMETAB *nt; 00306 for (nt = ntab; nt->name; nt++) 00307 { 00308 if (minmatch(flagname, nt->name, nt->minlen)) 00309 { 00310 if (check_access(player, nt->perm)) 00311 { 00312 *pflag = nt->flag; 00313 return true; 00314 } 00315 else 00316 { 00317 *pflag = -2; 00318 return false; 00319 } 00320 } 00321 } 00322 *pflag = -1; 00323 return false; 00324 }
struct { ... } htab_rec [static] |
Staging area for reads and writes into CHashTable.
The htab_rec structure is a fixed size, but only part of htab_rec is used. Since requests use variable-sized Keys, the portion of htab_rec used on any particular request is also variable-sized. pData is always present, but aKey may occupy as little as a single byte.
Referenced by hash_firstentry(), hash_firstkey(), hash_nextentry(), hash_nextkey(), hashaddLEN(), hashdeleteLEN(), hashfindLEN(), hashreplall(), and hashreplLEN().