Switch GameConfigs to hash tables (bug 5878 part 3, r=ds).

This commit is contained in:
David Anderson
2013-08-25 01:42:16 -07:00
parent 04bb2d1066
commit d14b5fe00b
4 changed files with 49 additions and 47 deletions
+1
View File
@@ -33,6 +33,7 @@
#include <new>
#include <limits.h>
#include <stdlib.h>
#include "am-allocator-policies.h"
#include "am-utility.h"
namespace ke {
+23 -1
View File
@@ -32,6 +32,18 @@
#ifndef _include_sourcemod_hashtable_h_
#define _include_sourcemod_hashtable_h_
/**
* @file sm_stringhashmap.h
*
* @brief Generic Key -> Value map class, based on a hash table. The Key, in
* this case, is always an ASCII string, and the value type is a template
* parameter. This class is intended as a drop-in replacement for KTrie
* (though the retrieve() signature has been improved).
*
* If your Value type already contains the key string, consider using
* NameHashSet instead.
*/
#include <am-allocator-policies.h>
#include <am-hashmap.h>
#include <am-string.h>
@@ -102,6 +114,8 @@ public:
internal_.reportOutOfMemory();
}
typedef typename Internal::Result Result;
// Some KTrie-like helper functions.
bool retrieve(const char *aKey, T *aResult = NULL)
{
@@ -114,6 +128,12 @@ public:
return true;
}
Result find(const char *aKey)
{
CharsAndLength key(aKey);
return internal_.find(key);
}
bool contains(const char *aKey)
{
CharsAndLength key(aKey);
@@ -128,7 +148,9 @@ public:
if (!i.found())
{
memory_used_ += key.length() + 1;
return internal_.add(i, value);
if (!internal_.add(i, value))
return false;
i->key = aKey;
}
i->value = value;
return true;