/usr/include/qb/qbmap.h is in libqb-dev 0.16.0.real-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | /*
* Copyright (C) 2011 Red Hat, Inc.
*
* Author: Angus Salkeld <asalkeld@redhat.com>
*
* This file is part of libqb.
*
* libqb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* libqb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef QB_MAP_H_DEFINED
#define QB_MAP_H_DEFINED
#include <stdint.h>
#ifndef S_SPLINT_S
#include <unistd.h>
#endif /* S_SPLINT_S */
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/**
* @file qbmap.h
* This provides a map interface to a Patricia trie, hashtable or skiplist.
*
* @par Ordering
* The hashtable is NOT ordered, but ptrie and skiplist are.
*
* @par Iterating
* Below is a simple example of how to iterate over a map.
* @code
* const char *p;
* void *data;
* qb_map_iter_t *it = qb_map_iter_create(m);
* for (p = qb_map_iter_next(it, &data); p; p = qb_map_iter_next(it, &data)) {
* printf("%s > %s\n", p, (char*) data);
* }
* qb_map_iter_free(it);
* @endcode
*
* Deletion of items within the iterator is supported. But note do not
* free the item memory in the iterator. If you need to free the data
* items then register for a notifier and free the memory there. This
* is required as the items are reference counted.
* @code
* qb_map_notify_add(m, NULL, my_map_free_handler,
* QB_MAP_NOTIFY_FREE, NULL);
* @endcode
*
* @par Notifications
* These allow you to get callbacks when values are inserted/removed or
* replaced.
* @note hashtable only supports deletion and replacement notificatins.
* There is also a special global callback for freeing deleted and replaced
* values (QB_MAP_NOTIFY_FREE).
* @see qb_map_notify_add() qb_map_notify_del_2()
*
* @par Prefix matching
* The ptrie supports prefixes in the iterator:
*
* @code
* it = qb_map_pref_iter_create(m, "aa");
* while ((p = qb_map_iter_next(it, &data)) != NULL) {
* printf("%s > %s\n", p, (char*)data);
* }
* qb_map_iter_free(it);
* @endcode
*
* The ptrie also supports prefixes in notifications:
* (remember to pass QB_MAP_NOTIFY_RECURSIVE into the notify_add.
* @code
* qb_map_notify_add(m, "root", my_map_notification,
* (QB_MAP_NOTIFY_INSERTED|
* QB_MAP_NOTIFY_DELETED|
* QB_MAP_NOTIFY_REPLACED|
* QB_MAP_NOTIFY_RECURSIVE),
* NULL);
*
* @endcode
*/
/**
* This is an opaque data type representing an instance of a map.
*/
typedef struct qb_map qb_map_t;
/**
* This is an opaque data type representing an iterator instance.
*/
typedef struct qb_map_iter qb_map_iter_t;
#define QB_MAP_NOTIFY_DELETED 1
#define QB_MAP_NOTIFY_REPLACED 2
#define QB_MAP_NOTIFY_INSERTED 4
#define QB_MAP_NOTIFY_RECURSIVE 8
#define QB_MAP_NOTIFY_FREE 16
typedef void (*qb_map_notify_fn)(uint32_t event,
char* key,
void* old_value,
void* value,
void* user_data);
typedef int32_t (*qb_map_transverse_fn)(const char* key,
void* value,
void* user_data);
/**
* Create an unsorted map based on a hashtable.
*
* @param max_size maximum size of the hashtable
*
* @return the map instance
*/
qb_map_t* qb_hashtable_create(size_t max_size);
/**
* Create a sorted map using a skiplist.
*
* @return the map instance
*/
qb_map_t* qb_skiplist_create(void);
/**
* Create a sorted map using a Patricia trie or "Radix tree".
*
* @htmlonly
* See the wikipedia <a href="http://en.wikipedia.org/wiki/Radix_Tree">Radix_tree</a>
* and <a href="http://en.wikipedia.org/wiki/Trie">Trie</a> pages.
* @endhtmlonly
*/
qb_map_t* qb_trie_create(void);
/**
* print out the nodes in the trie
*
* (for debug purposes)
*/
void
qb_trie_dump(qb_map_t* m);
/**
* Add a notifier to the map.
*
* @param m the map instance
* @param key the key (or prefix) to attach the notification to.
* @param fn the callback
* @param events the type of events to register for.
* @param user_data a pointer to be passed into the callback
*
* @note QB_MAP_NOTIFY_INSERTED is only valid on tries.
* @note you can use key prefixes with trie maps.
*
* @retval 0 success
* @retval -errno failure
*/
int32_t qb_map_notify_add(qb_map_t* m, const char* key,
qb_map_notify_fn fn, int32_t events,
void *user_data);
/**
* Delete a notifier from the map.
*
* @note the key,fn and events must match those you added.
*
* @param m the map instance
* @param key the key (or prefix) to attach the notification to.
* @param fn the callback
* @param events the type of events to register for.
*
* @retval 0 success
* @retval -errno failure
*/
int32_t qb_map_notify_del(qb_map_t* m, const char* key,
qb_map_notify_fn fn, int32_t events);
/**
* Delete a notifier from the map (including the userdata).
*
* @note the key, fn, events and userdata must match those you added.
*
* @param m the map instance
* @param key the key (or prefix) to attach the notification to.
* @param fn the callback
* @param events the type of events to register for.
* @param user_data a pointer to be passed into the callback
*
* @retval 0 success
* @retval -errno failure
*/
int32_t qb_map_notify_del_2(qb_map_t* m, const char* key,
qb_map_notify_fn fn, int32_t events,
void *user_data);
/**
* Inserts a new key and value into a qb_map_t.
*
* If the key already exists in the qb_map_t, it gets replaced by the new key.
*/
void qb_map_put(qb_map_t *map, const char* key, const void* value);
/**
* Gets the value corresponding to the given key.
*
* @retval NULL (if the key does not exist)
* @retval a pointer to the value
*/
void* qb_map_get(qb_map_t *map, const char* key);
/**
* Removes a key/value pair from a map.
*/
int32_t qb_map_rm(qb_map_t *map, const char* key);
/**
* Get the number of items in the map.
*/
size_t qb_map_count_get(qb_map_t *map);
/**
* Calls the given function for each of the key/value pairs in the map.
*
* The function is passed the key and value of each pair, and the given data
* parameter. The map is traversed in sorted order.
*/
void qb_map_foreach(qb_map_t *map, qb_map_transverse_fn func, void* user_data);
/**
* Create an iterator
*/
qb_map_iter_t* qb_map_iter_create(qb_map_t *map);
/**
* Create a prefix iterator.
*
* This will iterate over all items with the given
* prefix.
* @note this is only supported by the trie.
*/
qb_map_iter_t* qb_map_pref_iter_create(qb_map_t *map, const char* prefix);
/**
* Get the next item
*
* @param i the iterator
* @param value (out) the next item's value
*
* @retval the next key
* @retval NULL - the end of the iteration
*/
const char* qb_map_iter_next(qb_map_iter_t* i, void** value);
/**
* free the iterator
*
* @param i the iterator
*/
void qb_map_iter_free(qb_map_iter_t* i);
/**
* Destroy the map, removes all the items from the map.
*/
void qb_map_destroy(qb_map_t *map);
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* QB_MAP_H_DEFINED */
|