Added TF2_StunPlayer native and TF2_GetPlayerConditionFlags stock to TF2 ext. (
bug 4331, r=pred)
1 #ifndef _INCLUDE_KNIGHT_KE_HASHTABLE_H_
2 #define _INCLUDE_KNIGHT_KE_HASHTABLE_H_
4 #include <KeStdTypes.h>
5 #include <KnightAllocator.h>
12 * @brief Must generate a hash function given a key.
14 * @param key Pointer to the key.
17 typedef uint32_t (*KeHashGenerator)(const void *key);
20 * @brief Must compare two values.
22 * @param val1 First value.
23 * @param val2 Second value.
24 * @return True if equal, false if not.
26 typedef bool (*KeHashComparator)(const void *val1, const void *val2);
29 * @brief Must call the destructor of the given data, and free if necessary.
31 * @param val Pointer to data.
33 typedef void (*KeHashDestructor)(const void *val);
36 * @brief Must transfer the contents of an object from the source to the destination.
38 * @param dest Destination address.
39 * @param source Source address.
41 typedef void (*KeHashCopyCtor)(void *dest, const void *source);
44 * @brief Contains information about how to process keys and values in a hash table.
48 size_t bytes; /**< Bytes of storage needed (0 to use pointers). */
49 KeHashComparator cmp; /**< Comparator (if NULL, void * comparison used) */
50 KeHashDestructor dtor; /**< Optional function for performing dtor cleanup. */
51 KeHashCopyCtor ctor; /**< If bytes != 0, must be a valid function
52 (ignored otherwise). */
56 * @brief Creates a new hash table structure.
58 * @param bits Dictates starting number of buckets as a power of two.
59 * Pass 0 for the default (which is 4).
60 * @param key_gen Key generation function.
61 * @param key_marshal Structure detailing how to marshal keys.
62 * @param vak_marshal Structure detailing how to marshal values.
63 * @param nodeAlloc Node allocator (can be NULL for malloc/free).
64 * @param keep_free_list True to keep a free list of nodes, false otherwise.
65 * @return New hash table container.
67 extern KeHashTable *KE_CreateHashTable(
69 KeHashGenerator key_gen,
70 const KeHashMarshal *key_marshal,
71 const KeHashMarshal *val_marshal,
72 ke_allocator_t *nodeAlloc,
77 * @brief Destroys a hash table.
79 * @param table Hash table.
81 extern void KE_DestroyHashTable(KeHashTable *table);
84 * @brief Adds a key/value to the hash table. If the pair already exists, the old value
85 * is overwritten (calling any destructors as necessary).
87 * @param table Hash table.
88 * @param key Key pointer.
89 * @param val Value pointer.
91 extern void KE_AddToHashTable(KeHashTable *table, const void *key, void *val);
94 * @brief Removes a key entry from the hash table.
96 * @param table Hash table.
97 * @param key Key pointer.
99 extern void KE_RemoveFromHashTable(KeHashTable *table, const void *key);
102 * @brief Finds an entry in the hash table.
104 * @param table Hash table.
105 * @param key Key pointer.
106 * @param value Pointer to store the value (optional).
107 * @return On success, true is returned and value is filled if given.
108 * On failure, false is failed and outputs are undefined.
110 extern bool KE_FindInHashTable(KeHashTable *table, const void *key, void **value);
113 * @brief Clears all entries in the hash table (caching free entries when possible).
115 * @param table Hash table.
117 extern void KE_ClearHashTable(KeHashTable *table);
120 * @brief Generic function for hashing strings.
122 * @param str Key string.
123 * @return Hash value.
125 extern uint32_t KE_HashString(const void *str);
128 * @brief Generic case-sensitive comparison of strings.
130 * @param str1 First string.
131 * @param str2 Second string.
132 * @return True if equal, false otherwise.
134 extern bool KE_AreStringsEqual(const void* str1, const void* str2);
137 #endif //_INCLUDE_KNIGHT_KE_HASHTABLE_H_