Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
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.

73 lines
2.6 KiB

  1. #ifndef OHASH_H
  2. #define OHASH_H
  3. /* $OpenBSD: ohash.h,v 1.10 2012/09/23 15:05:23 espie Exp $ */
  4. /* ex:ts=8 sw=4:
  5. */
  6. /* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
  7. *
  8. * Permission to use, copy, modify, and distribute this software for any
  9. * purpose with or without fee is hereby granted, provided that the above
  10. * copyright notice and this permission notice appear in all copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  13. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  15. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  16. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  18. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19. */
  20. /* Open hashing support.
  21. * Open hashing was chosen because it is much lighter than other hash
  22. * techniques, and more efficient in most cases.
  23. */
  24. struct ohash_info {
  25. ptrdiff_t key_offset;
  26. void *data; /* user data */
  27. void *(*halloc)(size_t, void *);
  28. void (*hfree)(void *, size_t, void *);
  29. void *(*alloc)(size_t, void *);
  30. };
  31. struct _ohash_record;
  32. struct ohash {
  33. struct _ohash_record *t;
  34. struct ohash_info info;
  35. unsigned int size;
  36. unsigned int total;
  37. unsigned int deleted;
  38. };
  39. /* For this to be tweakable, we use small primitives, and leave part of the
  40. * logic to the client application. e.g., hashing is left to the client
  41. * application. We also provide a simple table entry lookup that yields
  42. * a hashing table index (opaque) to be used in find/insert/remove.
  43. * The keys are stored at a known position in the client data.
  44. */
  45. __BEGIN_DECLS
  46. void ohash_init(struct ohash *, unsigned, struct ohash_info *);
  47. void ohash_delete(struct ohash *);
  48. unsigned int ohash_lookup_interval(struct ohash *, const char *,
  49. const char *, uint32_t);
  50. unsigned int ohash_lookup_memory(struct ohash *, const char *,
  51. size_t, uint32_t)
  52. __attribute__ ((__bounded__(__string__,2,3)));
  53. void *ohash_find(struct ohash *, unsigned int);
  54. void *ohash_remove(struct ohash *, unsigned int);
  55. void *ohash_insert(struct ohash *, unsigned int, void *);
  56. void *ohash_first(struct ohash *, unsigned int *);
  57. void *ohash_next(struct ohash *, unsigned int *);
  58. unsigned int ohash_entries(struct ohash *);
  59. void *ohash_create_entry(struct ohash_info *, const char *, const char **);
  60. uint32_t ohash_interval(const char *, const char **);
  61. unsigned int ohash_qlookupi(struct ohash *, const char *, const char **);
  62. unsigned int ohash_qlookup(struct ohash *, const char *);
  63. __END_DECLS
  64. #endif