74 va_start(arglist,
string);
75 tokptr = va_arg(arglist,
char **);
78 while(*
string && isspace((
int)*
string))
87 while(*
string && !isspace((
int)*
string))
91 tokptr = va_arg(arglist,
char **);
123 {
"mt_elbert",
"14,433"},
124 {
"mt_massive",
"14,421"},
125 {
"mt_harvard",
"14,420"},
126 {
"blanca_peak",
"14,345"},
127 {
"la_plata_peak",
"14,336"},
128 {
"uncompahgre_peak",
"14,309"},
129 {
"crestone_peak",
"14,294"},
130 {
"mt_lincoln",
"14,286"},
131 {
"grays_peak",
"14,270"},
132 {
"mt_antero",
"14,269"},
133 {
"torreys_peak",
"14,267"},
134 {
"castle_peak",
"14,265"},
135 {
"quandary_peak",
"14,265"},
136 {
"mt_evans",
"14,264"},
137 {
"longs_peak",
"14,255"},
138 {
"mt_wilson",
"14,246"}
162 printf(
" starting count=%lu, table size=%lu\n", count, size);
167 while( count++ < size )
169 mtn = (int)(random() % (
long int)num_mtns);
176 puts(
"hash_insert failed");
182 printf(
" added %s -> %s\n", key, val);
189 printf(
" ending count=%lu, table size=%lu\n", count, size);
207 printf(
" starting count=%lu, table size=%lu\n", count, size);
219 printf(
" deleted %s -> %s\n", key, val);
226 printf(
" ending count=%lu, table size=%lu\n", count, size);
238 int main(
int argc,
char *argv[])
249 "n create new empty hash table\n" 250 "x delete entire hash table\n" 251 "a <key> <val> add value to hash table\n" 252 "d <key> delete value from hash table\n" 253 "l <key> lookup value in hash table\n" 254 "c show counts: number of entries and table size\n" 255 "t dump whole hash table\n" 256 "+ force increase hash table (by auto-adding)\n" 257 "- force decrease hash table (by auto-deleting)\n" 258 "v <level> set logging verbosity level 0-4\n" 262 puts(
"Hashing example (enter '?' for list of commands)");
270 if( !fgets(in, (
int)
sizeof(
input_t), stdin) )
287 printf(
"table exists, delete first\n");
307 printf(
"no table\n");
320 printf(
"no hash table\n");
322 else if(
tokenize(in+1, &tok1, &tok2, (
char **) 0) != 2)
335 puts(
"hash_insert failed");
345 printf(
"no hash table\n");
347 else if(
tokenize(in+1, &tok1, (
char **)0) != 1)
353 puts(
"hash_lookup failed");
359 printf(
"deleted %s -> %s\n", key, val);
368 printf(
"no hash table\n");
370 else if(
tokenize(in+1, &tok1, (
char **) 0) != 1)
376 puts(
"hash_lookup failed");
381 printf(
"%s -> %s\n", tok1, val);
389 printf(
"no hash table\n");
393 printf(
"count=%lu, size=%lu\n",
402 printf(
"no hash table\n");
419 printf(
"no hash table\n");
431 printf(
"no hash table\n");
441 if(
tokenize(in+1, &tok1, (
char **)0) != 1 )
int main(int argc, char *argv[])
Example main.
#define hnode_getkey(N)
Get hash node hash key.
static void force_grow(hash_t *h)
Force table to grow by feeding the table random entries.
#define HASHCOUNT_T_MAX
Maximum maximum hash table size.
hnode_t * hash_scan_next(hscan_t *scan)
Retrieve the next node from the hash table.
char * new_strdup(const char *s)
Duplicate a string.
static void del_node_data(void *key, void *val)
Delete node data - both key and value are dynamically allocated.
General purpose hash data and function declarations.
char input_t[256]
Working input buffer.
int LOG_SET_THRESHOLD(int nLevel)
Set new logging threshold level.
static int MtnCounter
Make random keys unique.
Memory allocation and deallocation declarations.
hnode_t * hash_lookup(hash_t *hash, const void *key)
Find a node in the hash table and return a pointer to it.
#define hash_size(H)
Returns size of hash table.
hashcount_t highmark
Note 4.
void hash_set_self_verify(bool_t selfverify)
Enable (disable) automatic self-checks during hash table modification operatations.
#define arraysize(array)
array size, i.e. number of array entries
unsigned long hashcount_t
maximum hash table size type
static void force_shrink(hash_t *h)
Force table to shink by deleting table random entries.
hashcount_t lowmark
Note 5.
void hash_scan_begin(hscan_t *scan, hash_t *hash)
Reset the hash scanner (iterator).
RoadNarrows Robotics common configuration file.
#define hnode_get(N)
Get hash node user data.
hash_t * hash_table_create(bool_t isdynamic, hashcount_t minsize, hashcount_t maxsize, hash_comp_t compfun, hash_fun_t hashfun, hnode_data_free_t freedatafun)
Create a dynamic hash table.
Hash table control structure.
Hash chain node structure.
void hash_node_delete(hash_t *hash, hnode_t *node)
Unlink and delete a hash node from the hash table.
#define hash_count(H)
Returns number of entires in hash table.
bool_t hash_insert(hash_t *hash, void *key, void *data)
Insert user data with the given key into the hash table.
static char * Colorado14ers[][2]
Colorado's 14,000+ foot mountains.
void hash_table_destroy(hash_t *hash)
Delete the hash table, all of its entries, and all of the user data.
static int tokenize(char *string,...)
Tokenize input.