PageRenderTime 37ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/src/kangmodb/set.h

#
C Header | 87 lines | 27 code | 24 blank | 36 comment | 4 complexity | 5de8adc43e2041d9be1cd17022eb26e4 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #ifndef _KD_SET_H__
  2. #define _KD_SET_H__ (1)
  3. #include "key.h"
  4. typedef stgKey setkey_t;
  5. typedef void * setval_t;
  6. /*************************************
  7. * INTERNAL DEFINITIONS
  8. */
  9. /* Fine for 2^NUM_LEVELS nodes. */
  10. #define NUM_LEVELS 20
  11. /* Internal key values with special meanings. */
  12. // TODO : If we need to enable week ordering, we need to define this macro constant with an appropriate value.
  13. #define INVALID_FIELD (0) /* Uninitialised field value. */
  14. /** @brief The minimum key simply has an empty string. This is used in dummy nodes in skip-list implementation.
  15. */
  16. #define SENTINEL_KEYMIN ( stgKey("") ) /* Key value of first dummy node. */
  17. /** @brief The maximum key has its key_ as NULL. This is used in dummy nodes in skip-list implementation.
  18. */
  19. #define SENTINEL_KEYMAX ( stgKey() ) /* Key value of last dummy node. */
  20. #define CALLER_TO_INTERNAL_KEY(_k) (_k)
  21. /*
  22. * SUPPORT FOR WEAK ORDERING OF MEMORY ACCESSES
  23. */
  24. #ifdef WEAK_MEM_ORDER
  25. /* Read field @_f into variable @_x. */
  26. #define READ_FIELD(_x,_f) \
  27. do { \
  28. (_x) = (_f); \
  29. if ( (_x) == INVALID_FIELD ) { RMB(); (_x) = (_f); } \
  30. assert((_x) != INVALID_FIELD); \
  31. } while ( 0 )
  32. #else
  33. /* Read field @_f into variable @_x. */
  34. #define READ_FIELD(_x,_f) ((_x) = (_f))
  35. #endif
  36. /*************************************
  37. * PUBLIC DEFINITIONS
  38. */
  39. struct set_t; /* opaque */
  40. void _init_set_subsystem(void);
  41. /*
  42. * Allocate an empty set.
  43. */
  44. set_t *set_alloc(void);
  45. /*
  46. * Add mapping (@k -> @v) into set @s. Return previous mapped value if
  47. * one existed, or NULL if no previous mapping for @k existed.
  48. *
  49. * If @overwrite is FALSE, then if a mapping already exists it is not
  50. * modified, and the existing value is returned unchanged. It is possible
  51. * to see if the value was changed by observing if the return value is NULL.
  52. */
  53. setval_t set_update(set_t *s, setkey_t k, setval_t v, int overwrite);
  54. /*
  55. * Remove mapping for key @k from set @s. Return value associated with
  56. * removed mapping, or NULL is there was no mapping to delete.
  57. */
  58. setval_t set_remove(set_t *s, setkey_t k);
  59. /*
  60. * Look up mapping for key @k in set @s. Return value if found, else NULL.
  61. */
  62. setval_t set_lookup(set_t *s, setkey_t k);
  63. #endif /* _KD_SET_H__ */