hashmap.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. *
  3. * Embedded Linux library
  4. *
  5. * Copyright (C) 2011-2014 Intel Corporation. All rights reserved.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. */
  22. #ifndef __ELL_HASHMAP_H
  23. #define __ELL_HASHMAP_H
  24. #include <stdbool.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. typedef void (*l_hashmap_foreach_func_t) (const void *key, void *value,
  29. void *user_data);
  30. typedef void (*l_hashmap_destroy_func_t) (void *value);
  31. typedef unsigned int (*l_hashmap_hash_func_t) (const void *p);
  32. typedef int (*l_hashmap_compare_func_t) (const void *a, const void *b);
  33. typedef void *(*l_hashmap_key_new_func_t) (const void *p);
  34. typedef void (*l_hashmap_key_free_func_t) (void *p);
  35. typedef bool (*l_hashmap_remove_func_t)(const void *key, void *value,
  36. void *user_data);
  37. struct l_hashmap;
  38. unsigned int l_str_hash(const void *p);
  39. struct l_hashmap *l_hashmap_new(void);
  40. struct l_hashmap *l_hashmap_string_new(void);
  41. bool l_hashmap_set_hash_function(struct l_hashmap *hashmap,
  42. l_hashmap_hash_func_t func);
  43. bool l_hashmap_set_compare_function(struct l_hashmap *hashmap,
  44. l_hashmap_compare_func_t func);
  45. bool l_hashmap_set_key_copy_function(struct l_hashmap *hashmap,
  46. l_hashmap_key_new_func_t func);
  47. bool l_hashmap_set_key_free_function(struct l_hashmap *hashmap,
  48. l_hashmap_key_free_func_t func);
  49. void l_hashmap_destroy(struct l_hashmap *hashmap,
  50. l_hashmap_destroy_func_t destroy);
  51. bool l_hashmap_insert(struct l_hashmap *hashmap,
  52. const void *key, void *value);
  53. bool l_hashmap_replace(struct l_hashmap *hashmap,
  54. const void *key, void *value,
  55. void **old_value);
  56. void *l_hashmap_remove(struct l_hashmap *hashmap, const void *key);
  57. void *l_hashmap_lookup(struct l_hashmap *hashmap, const void *key);
  58. void l_hashmap_foreach(struct l_hashmap *hashmap,
  59. l_hashmap_foreach_func_t function, void *user_data);
  60. unsigned int l_hashmap_foreach_remove(struct l_hashmap *hashmap,
  61. l_hashmap_remove_func_t function, void *user_data);
  62. unsigned int l_hashmap_size(struct l_hashmap *hashmap);
  63. bool l_hashmap_isempty(struct l_hashmap *hashmap);
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* __ELL_HASHMAP_H */