// // E_CreateString // // Creates an EDF string object with the given value which is hashable // by one or two different keys. The mnemonic key is required and must // be 128 or fewer characters long. The numeric key is optional. If a // negative value is passed as the numeric key, the object will not be // added to the numeric hash table. // edf_string_t *E_CreateString(const char *value, const char *key, int num) { int keyval; edf_string_t *newStr; if((newStr = E_StringForName(key))) { // Modify existing object. E_ReplaceString(newStr->string, estrdup(value)); // Modify numeric id and rehash object if necessary if(num != newStr->numkey) { // If old key is >= 0, must remove from hash first if(newStr->numkey >= 0) E_DelStringFromNumHash(newStr); // Set new key newStr->numkey = num; // If new key >= 0, add back to hash if(newStr->numkey >= 0) E_AddStringToNumHash(newStr); } } else { // Create a new string object newStr = estructalloc(edf_string_t, 1); // copy keys into string object if(strlen(key) >= sizeof(newStr->key)) { E_EDFLoggedErr(2, "E_CreateString: invalid string mnemonic '%s'\n", key); } strncpy(newStr->key, key, sizeof(newStr->key)); newStr->numkey = num; // duplicate value newStr->string = estrdup(value); // add to hash tables keyval = D_HashTableKey(newStr->key) % NUM_EDFSTR_CHAINS; newStr->next = edf_str_chains[keyval]; edf_str_chains[keyval] = newStr; // numeric key is not required if(num >= 0) E_AddStringToNumHash(newStr); } return newStr; }
// // HUDWidget::WidgetForName // // Retrieves a widget given its name, using hashing. // Returns NULL if no such widget exists. // HUDWidget *HUDWidget::WidgetForName(const char *name) { int key = D_HashTableKey(name) % NUMWIDGETCHAINS; HUDWidget *cur = hu_chains[key]; while(cur && strncasecmp(name, cur->name, 33)) cur = cur->next; return cur; }
// // E_StringForName // // Returns a pointer to an EDF string given a mnemonic value. // Returns NULL if not found. // edf_string_t *E_StringForName(const char *key) { int keyval = D_HashTableKey(key) % NUM_EDFSTR_CHAINS; edf_string_t *cur = edf_str_chains[keyval]; while(cur && strncasecmp(cur->key, key, sizeof(cur->key))) cur = cur->next; return cur; }
// // HUDWidget::AddWidgetToHash // // Adds a widget to the hash table, but only if one of the given // name doesn't exist. Returns true if successful. // bool HUDWidget::AddWidgetToHash(HUDWidget *widget) { int key; // make sure one doesn't already exist by this name if(WidgetForName(widget->name)) { #ifdef RANGECHECK // for debug, cause an error to alert programmer of internal mishaps I_Error("HUDWidget::AddWidgetToHash: duplicate mnemonic %s\n", widget->name); #endif return false; } key = D_HashTableKey(widget->name) % NUMWIDGETCHAINS; widget->next = hu_chains[key]; hu_chains[key] = widget; return true; }
static unsigned int HashCode(const char *input) { return EE_PLATFORM_TEST(EE_PLATF_CSFS) ? D_HashTableKeyCase(input) : D_HashTableKey(input); }