hash.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Hash routine.
  2. Copyright (C) 1998 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 2, or (at your
  7. option) any later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. #ifndef _ZEBRA_HASH_H
  17. #define _ZEBRA_HASH_H
  18. /* Default hash table size. */
  19. #define HASHTABSIZE 1024
  20. struct hash_backet
  21. {
  22. /* Linked list. */
  23. struct hash_backet *next;
  24. /* Hash key. */
  25. unsigned int key;
  26. /* Data. */
  27. void *data;
  28. };
  29. struct hash
  30. {
  31. /* Hash backet. */
  32. struct hash_backet **index;
  33. /* Hash table size. */
  34. unsigned int size;
  35. /* Key make function. */
  36. unsigned int (*hash_key) (void *);
  37. /* Data compare function. */
  38. int (*hash_cmp) (const void *, const void *);
  39. /* Backet alloc. */
  40. unsigned long count;
  41. };
  42. extern struct hash *hash_create (unsigned int (*) (void *),
  43. int (*) (const void *, const void *));
  44. extern struct hash *hash_create_size (unsigned int, unsigned int (*) (void *),
  45. int (*) (const void *, const void *));
  46. extern void *hash_get (struct hash *, void *, void * (*) (void *));
  47. extern void *hash_alloc_intern (void *);
  48. extern void *hash_lookup (struct hash *, void *);
  49. extern void *hash_release (struct hash *, void *);
  50. extern void hash_iterate (struct hash *,
  51. void (*) (struct hash_backet *, void *), void *);
  52. extern void hash_clean (struct hash *, void (*) (void *));
  53. extern void hash_free (struct hash *);
  54. extern unsigned int string_hash_make (const char *);
  55. #endif /* _ZEBRA_HASH_H */