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