src/rbtab.c File Reference

#include "copyright.h"
#include "config.h"
#include "db.h"
#include "externs.h"
#include "htab.h"
#include "alloc.h"
#include "mudconf.h"

Include dependency graph for rbtab.c:

Go to the source code of this file.

Data Structures

struct  string_dict_entry
struct  hashreplstat

Functions

static int hrbtab_compare (char *left, char *right, void *arg)
void hashinit (RBTAB *htab, int size)
void hashreset (RBTAB *htab)
void * hashfind (char *str, RBTAB *htab)
int hashadd (char *str, void *hashdata, RBTAB *htab)
void hashdelete (char *str, RBTAB *htab)
static int nuke_hash_ent (void *key, void *data, int depth, void *arg)
void hashflush (RBTAB *htab, int size)
int hashrepl (char *str, void *hashdata, RBTAB *htab)
static int hashreplall_cb (void *key, void *data, int depth, void *arg)
void hashreplall (void *old, void *new, RBTAB *htab)
char * hashinfo (const char *tab_name, RBTAB *htab)
void * hash_firstentry (RBTAB *htab)
void * hash_nextentry (RBTAB *htab)
char * hash_firstkey (RBTAB *htab)
char * hash_nextkey (RBTAB *htab)


Function Documentation

void* hash_firstentry ( RBTAB htab  ) 

Definition at line 187 of file rbtab.c.

References string_dict_entry::data, string_dict_entry::key, rbtable::last, rb_search(), SEARCH_FIRST, and rbtable::tree.

Referenced by do_chanlist(), do_channelnuke(), do_dbclean(), do_listchannels(), fun_clist(), hash_nextentry(), help_write(), helpindex_read(), save_comsystem(), and vattr_first().

00188 {
00189         struct string_dict_entry *ent;
00190 
00191         if(htab->last)
00192                 free(htab->last);
00193 
00194         ent = rb_search(htab->tree, SEARCH_FIRST, NULL);
00195         if(ent) {
00196                 htab->last = strdup(ent->key);
00197                 return ent->data;
00198         }
00199         htab->last = NULL;
00200 
00201         return NULL;
00202 }

char* hash_firstkey ( RBTAB htab  ) 

Definition at line 224 of file rbtab.c.

References string_dict_entry::key, rbtable::last, rb_search(), SEARCH_FIRST, and rbtable::tree.

Referenced by hash_nextkey().

00225 {
00226         struct string_dict_entry *ent;
00227         if(htab->last)
00228                 free(htab->last);
00229 
00230         ent = rb_search(htab->tree, SEARCH_FIRST, NULL);
00231         if(ent) {
00232                 htab->last = strdup(ent->key);
00233                 return ent->key;
00234         }
00235         htab->last = NULL;
00236 
00237         return NULL;
00238 }

void* hash_nextentry ( RBTAB htab  ) 

Definition at line 204 of file rbtab.c.

References string_dict_entry::data, hash_firstentry(), string_dict_entry::key, rbtable::last, rb_search(), SEARCH_GT, and rbtable::tree.

Referenced by do_chanlist(), do_channelnuke(), do_dbclean(), do_listchannels(), fun_clist(), help_write(), helpindex_read(), save_comsystem(), and vattr_next().

00205 {
00206         struct string_dict_entry *ent;
00207 
00208         if(!htab->last) {
00209                 return hash_firstentry(htab);
00210         }
00211 
00212         ent = rb_search(htab->tree, SEARCH_GT, htab->last);
00213         free(htab->last);
00214 
00215         if(ent) {
00216                 htab->last = strdup(ent->key);
00217                 return ent->data;
00218         } else {
00219                 htab->last = NULL;
00220                 return NULL;
00221         }
00222 }

char* hash_nextkey ( RBTAB htab  ) 

Definition at line 240 of file rbtab.c.

References hash_firstkey(), string_dict_entry::key, rbtable::last, rb_search(), SEARCH_NEXT, and rbtable::tree.

00241 {
00242         struct string_dict_entry *ent;
00243 
00244         if(!htab->last) {
00245                 return hash_firstkey(htab);
00246         }
00247 
00248         ent = rb_search(htab->tree, SEARCH_NEXT, htab->last);
00249         free(htab->last);
00250 
00251         if(ent) {
00252                 htab->last = strdup(ent->key);
00253                 return ent->key;
00254         } else {
00255                 htab->last = NULL;
00256                 return NULL;
00257         }
00258 }

int hashadd ( char *  str,
void *  hashdata,
RBTAB htab 
)

Definition at line 68 of file rbtab.c.

References string_dict_entry::data, string_dict_entry::key, rb_exists(), rb_insert(), and rbtable::tree.

Referenced by cf_alias(), cf_cmd_alias(), cf_flagalias(), do_createchannel(), helpindex_read(), init_attrtab(), init_btechstats(), init_cmdtab(), init_flagtab(), init_functab(), init_logout_cmdtab(), init_mactab(), init_powertab(), InitSpecialHash(), load_comsystem(), mmdb_db_read(), and vattr_define().

00069 {
00070         struct string_dict_entry *ent = malloc(sizeof(struct string_dict_entry));
00071 
00072         if(rb_exists(htab->tree, str))
00073                 return (-1);
00074 
00075         ent->key = strdup(str);
00076         ent->data = hashdata;
00077 
00078         rb_insert(htab->tree, ent->key, ent);
00079         return 0;
00080 
00081 }

void hashdelete ( char *  str,
RBTAB htab 
)

Definition at line 88 of file rbtab.c.

References string_dict_entry::key, rb_delete(), rb_exists(), and rbtable::tree.

Referenced by do_channelnuke(), do_dbclean(), do_destroychannel(), and vattr_delete().

00089 {
00090         struct string_dict_entry *ent = NULL;
00091 
00092         if(!rb_exists(htab->tree, str)) {
00093                 return;
00094         }
00095         ent = rb_delete(htab->tree, str);
00096 
00097         if(ent) {
00098                 if(ent->key)
00099                         free(ent->key);
00100                 free(ent);
00101         }
00102 
00103         return;
00104 }

void* hashfind ( char *  str,
RBTAB htab 
)

Definition at line 50 of file rbtab.c.

References rbtable::checks, string_dict_entry::data, rb_find(), and rbtable::tree.

Referenced by add_player_name(), atr_str(), cf_access(), cf_acmd_access(), cf_alias(), cf_cmd_alias(), cf_flagalias(), cf_set_flags(), char_getvaluecode(), check_command(), decode_power(), delete_player_name(), do_addcommand(), do_command(), do_delcommand(), do_destroychannel(), do_function(), do_listcommands(), do_macro(), do_unauth_command(), exec(), find_flag(), find_matching_short_part(), find_matching_vlong_part(), find_power(), HandledCommand_sub(), help_write(), lookup_player(), process_command(), select_channel(), set_prefix_cmds(), vattr_delete(), vattr_find(), and vattr_rename().

00051 {
00052         int hval, numchecks;
00053         struct string_dict_entry *ent;
00054 
00055         htab->checks++;
00056         ent = rb_find(htab->tree, str);
00057         if(ent) {
00058                 return ent->data;
00059         } else
00060                 return (void *)ent;
00061 }

void hashflush ( RBTAB htab,
int  size 
)

Definition at line 119 of file rbtab.c.

References hrbtab_compare(), rbtable::last, nuke_hash_ent(), rb_destroy(), rb_init(), rb_walk(), rbtable::tree, and WALK_POSTORDER.

Referenced by helpindex_read().

00120 {
00121         rb_walk(htab->tree, WALK_POSTORDER, nuke_hash_ent, NULL);
00122         rb_destroy(htab->tree);
00123         htab->tree = rb_init((void *)hrbtab_compare, NULL);
00124         if(htab->last)
00125                 free(htab->last);
00126         htab->last = NULL;
00127 }

char* hashinfo ( const char *  tab_name,
RBTAB htab 
)

Definition at line 174 of file rbtab.c.

References alloc_mbuf, rb_size(), and rbtable::tree.

00175 {
00176         char *buff;
00177 
00178         buff = alloc_mbuf("hashinfo");
00179         sprintf(buff, "%-15s %8d", tab_name, rb_size(htab->tree));
00180         return buff;
00181 }

void hashinit ( RBTAB htab,
int  size 
)

Definition at line 25 of file rbtab.c.

References hrbtab_compare(), rbtable::last, rb_init(), and rbtable::tree.

Referenced by helpindex_init(), init_attrtab(), init_btechstats(), init_chantab(), init_cmdtab(), init_flagtab(), init_functab(), init_logout_cmdtab(), init_mactab(), init_powertab(), initialize_partname_tables(), InitSpecialHash(), main(), and vattr_init().

00026 {
00027         memset(htab, 0, sizeof(RBTAB));
00028         htab->tree = rb_init((void *)hrbtab_compare, NULL);
00029         htab->last = NULL;
00030 }

int hashrepl ( char *  str,
void *  hashdata,
RBTAB htab 
)

Definition at line 134 of file rbtab.c.

References string_dict_entry::data, rb_find(), and rbtable::tree.

00135 {
00136         struct string_dict_entry *ent;
00137 
00138         ent = rb_find(htab->tree, str);
00139         if(!ent)
00140                 return 0;
00141 
00142         ent->data = hashdata;
00143         return 1;
00144 }

void hashreplall ( void *  old,
void *  new,
RBTAB htab 
)

Definition at line 162 of file rbtab.c.

References hashreplall_cb(), rb_walk(), rbtable::tree, and WALK_INORDER.

00163 {
00164         struct hashreplstat repl = { old, new };
00165 
00166         rb_walk(htab->tree, WALK_INORDER, hashreplall_cb, &repl);
00167 }

static int hashreplall_cb ( void *  key,
void *  data,
int  depth,
void *  arg 
) [static]

Definition at line 151 of file rbtab.c.

References string_dict_entry::data, hashreplstat::new, and hashreplstat::old.

Referenced by hashreplall().

00152 {
00153         struct string_dict_entry *ent = (struct string_dict_entry *) data;
00154         struct hashreplstat *repl = (struct hashreplstat *) arg;
00155 
00156         if(ent->data == repl->old) {
00157                 ent->data = repl->new;
00158         }
00159         return 1;
00160 }

void hashreset ( RBTAB htab  ) 

Definition at line 37 of file rbtab.c.

References rbtable::checks, rbtable::hits, and rbtable::scans.

Referenced by helpindex_read(), and main().

00038 {
00039         htab->checks = 0;
00040         htab->scans = 0;
00041         htab->hits = 0;
00042 }

static int hrbtab_compare ( char *  left,
char *  right,
void *  arg 
) [static]

Definition at line 20 of file rbtab.c.

Referenced by hashflush(), and hashinit().

00021 {
00022         return strcasecmp(left, right);
00023 }

static int nuke_hash_ent ( void *  key,
void *  data,
int  depth,
void *  arg 
) [static]

Definition at line 111 of file rbtab.c.

References string_dict_entry::key.

Referenced by hashflush().

00112 {
00113         struct string_dict_entry *ent = (struct string_dict_entry *) data;
00114         free(ent->key);
00115         free(ent);
00116         return 1;
00117 }


Generated on Mon May 28 04:25:47 2007 for BattletechMUX by  doxygen 1.4.7