Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.9 KiB

  1. /* See xmlhash.c for copyright info */
  2. #ifndef XMLHASH__H
  3. #define XMLHASH__H
  4. #include <stddef.h> /* For size_t */
  5. /*
  6. ** A hash table consists of an array of these buckets. Each bucket
  7. ** holds a copy of the key, a pointer to the data associated with the
  8. ** key, and a pointer to the next bucket that collided with this one,
  9. ** if there was one.
  10. */
  11. typedef struct tagXMLHTABLEBUCKET {
  12. char *key;
  13. void *data;
  14. struct tagXMLHTABLEBUCKET *next;
  15. } XMLHTABLEBUCKET;
  16. /*
  17. ** This is what you actually declare an instance of to create a table.
  18. ** You then call 'construct_table' with the address of this structure,
  19. ** and a guess at the size of the table. Note that more nodes than this
  20. ** can be inserted in the table, but performance degrades as this
  21. ** happens. Performance should still be quite adequate until 2 or 3
  22. ** times as many nodes have been inserted as the table was created with.
  23. */
  24. typedef struct tagXMLHTABLE {
  25. size_t size;
  26. XMLHTABLEBUCKET **table;
  27. void *userdata;
  28. } XMLHTABLE, *LPXMLHTABLE;
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /*
  33. ** This is used to construct the table. If it doesn't succeed, it sets
  34. ** the table's size to 0, and the pointer to the table to NULL.
  35. */
  36. LPXMLHTABLE XMLHTable_Create(LPXMLHTABLE table,size_t size);
  37. /*
  38. ** Inserts a pointer to 'data' in the table, with a copy of 'key' as its
  39. ** key. Note that this makes a copy of the key, but NOT of the
  40. ** associated data.
  41. */
  42. void *XMLHTable_Insert(LPXMLHTABLE table, char *key, void *data);
  43. /*
  44. ** Returns a pointer to the data associated with a key. If the key has
  45. ** not been inserted in the table, returns NULL.
  46. */
  47. void *XMLHTable_Lookup(LPXMLHTABLE table, char *key);
  48. /*
  49. ** Deletes an entry from the table. Returns a pointer to the data that
  50. ** was associated with the key so the calling code can dispose of it
  51. ** properly.
  52. */
  53. void *XMLHTable_Remove(LPXMLHTABLE table, char *key);
  54. /*
  55. ** Goes through a hash table and calls the function passed to it
  56. ** for each node that has been inserted. The function is passed
  57. ** a pointer to the key, and a pointer to the data associated
  58. ** with it.
  59. */
  60. int XMLHTable_Enumerate(LPXMLHTABLE table, int (*func)(char *,void *,void *));
  61. /*
  62. ** Frees a hash table. For each node that was inserted in the table,
  63. ** it calls the function whose address it was passed, with a pointer
  64. ** to the data that was in the table. The function is expected to
  65. ** free the data. Typical usage would be:
  66. ** free_table(&table, free);
  67. ** if the data placed in the table was dynamically allocated, or:
  68. ** free_table(&table, NULL);
  69. ** if not. ( If the parameter passed is NULL, it knows not to call
  70. ** any function with the data. )
  71. */
  72. int XMLHTable_Destroy(LPXMLHTABLE table, int (*func)(char *, void *, void *), int FreeTable);
  73. #ifdef __cplusplus
  74. }
  75. #endif /* __cplusplus */
  76. #endif /* XMLHASH__H */