hash.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. GLIB - Library of useful routines for C programming
  3. Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  4. (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
  5. (c) Copyright 2000-2004 Convergence (integrated media) GmbH
  6. All rights reserved.
  7. Written by Denis Oliver Kropp <dok@directfb.org>,
  8. Andreas Hundt <andi@fischlustig.de>,
  9. Sven Neumann <neo@directfb.org>,
  10. Ville Syrjälä <syrjala@sci.fi>,
  11. Claudio Ciccani <klan@users.sf.net> and
  12. Michael Emmel <memmel@gmail.com>.
  13. This library is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU Lesser General Public
  15. License as published by the Free Software Foundation; either
  16. version 2 of the License, or (at your option) any later version.
  17. This library is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. Lesser General Public License for more details.
  21. You should have received a copy of the GNU Lesser General Public
  22. License along with this library; if not, write to the
  23. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. Boston, MA 02111-1307, USA.
  25. */
  26. /*
  27. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  28. * file for a list of people on the GLib Team. See the ChangeLog
  29. * files for a list of changes. These files are distributed with
  30. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  31. */
  32. #ifndef __FUSION_HASH_H__
  33. #define __FUSION_HASH_H__
  34. #include <fusion/types.h>
  35. #include <fusion/shmalloc.h>
  36. #include <string.h>
  37. #define FUSION_HASH_MIN_SIZE 11
  38. #define FUSION_HASH_MAX_SIZE 13845163
  39. typedef enum {
  40. HASH_PTR,
  41. HASH_STRING,
  42. HASH_INT
  43. }
  44. FusionHashType;
  45. typedef struct _FusionHashNode FusionHashNode;
  46. struct _FusionHashNode
  47. {
  48. void *key;
  49. void *value;
  50. FusionHashNode *next;
  51. };
  52. struct __Fusion_FusionHash
  53. {
  54. int magic;
  55. bool local;
  56. FusionHashType key_type;
  57. FusionHashType value_type;
  58. int size;
  59. int nnodes;
  60. FusionHashNode **nodes;
  61. FusionSHMPoolShared *pool;
  62. bool free_keys;
  63. bool free_values;
  64. };
  65. typedef bool (*FusionHashIteratorFunc)( FusionHash *hash,
  66. void *key,
  67. void *value,
  68. void *ctx );
  69. DirectResult
  70. fusion_hash_resize (FusionHash *hash);
  71. DirectResult
  72. fusion_hash_create (FusionSHMPoolShared *pool,
  73. FusionHashType key_type,
  74. FusionHashType value_type,
  75. int size, FusionHash **ret_hash );
  76. DirectResult
  77. fusion_hash_create_local (FusionHashType key_type, FusionHashType value_type,
  78. int size, FusionHash **ret_hash );
  79. DirectResult
  80. fusion_hash_remove (FusionHash *hash,
  81. const void * key,
  82. void **old_key,
  83. void **old_value);
  84. DirectResult
  85. fusion_hash_insert( FusionHash *hash, void *key, void *value );
  86. DirectResult
  87. fusion_hash_replace (FusionHash *hash,
  88. void * key,
  89. void * value,
  90. void **old_key,
  91. void **old_value);
  92. void
  93. fusion_hash_destroy( FusionHash *hash );
  94. void
  95. fusion_hash_set_autofree( FusionHash *hash, bool free_keys, bool free_values );
  96. void *
  97. fusion_hash_lookup (FusionHash *hash, const void * key);
  98. void
  99. fusion_hash_iterate( FusionHash *hash,
  100. FusionHashIteratorFunc func,
  101. void *ctx );
  102. unsigned int
  103. fusion_hash_size (FusionHash *hash);
  104. bool fusion_hash_should_resize ( FusionHash *hash);
  105. #endif /*__FUSION_HASH_H__*/