SDL_hashtable.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef SDL_hashtable_h_
  19. #define SDL_hashtable_h_
  20. /* this is not (currently) a public API. But maybe it should be! */
  21. struct SDL_HashTable;
  22. typedef struct SDL_HashTable SDL_HashTable;
  23. typedef Uint32 (*SDL_HashTable_HashFn)(const void *key, void *data);
  24. typedef SDL_bool (*SDL_HashTable_KeyMatchFn)(const void *a, const void *b, void *data);
  25. typedef void (*SDL_HashTable_NukeFn)(const void *key, const void *value, void *data);
  26. SDL_HashTable *SDL_CreateHashTable(void *data,
  27. const Uint32 num_buckets,
  28. const SDL_HashTable_HashFn hashfn,
  29. const SDL_HashTable_KeyMatchFn keymatchfn,
  30. const SDL_HashTable_NukeFn nukefn,
  31. const SDL_bool stackable);
  32. void SDL_DestroyHashTable(SDL_HashTable *table);
  33. SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *value);
  34. SDL_bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key);
  35. SDL_bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void **_value);
  36. SDL_bool SDL_HashTableEmpty(SDL_HashTable *table);
  37. // iterate all values for a specific key. This only makes sense if the hash is stackable. If not-stackable, just use SDL_FindInHashTable().
  38. SDL_bool SDL_IterateHashTableKey(const SDL_HashTable *table, const void *key, const void **_value, void **iter);
  39. // iterate all key/value pairs in a hash (stackable hashes can have duplicate keys with multiple values).
  40. SDL_bool SDL_IterateHashTable(const SDL_HashTable *table, const void **_key, const void **_value, void **iter);
  41. Uint32 SDL_HashString(const void *key, void *unused);
  42. SDL_bool SDL_KeyMatchString(const void *a, const void *b, void *unused);
  43. Uint32 SDL_HashID(const void *key, void *unused);
  44. SDL_bool SDL_KeyMatchID(const void *a, const void *b, void *unused);
  45. #endif /* SDL_hashtable_h_ */