ReactOS 0.4.15-dev-7924-g5949c20
dictionary.h
Go to the documentation of this file.
1/* Simple dictionary
2 *
3 * Copyright 2005 Juan Lang
4 *
5 * This is a pretty basic dictionary, or map if you prefer. It's not
6 * thread-safe.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22#ifndef __DICTIONARY_H__
23#define __DICTIONARY_H__
24
25#include <stdarg.h>
26#include "windef.h"
27#include "winbase.h"
28
29struct dictionary;
30
31/* Returns whether key a is less than, equal to, or greater than key b, in
32 * the same way (a - b) would for integers or strcmp(a, b) would for ANSI
33 * strings.
34 */
35typedef int (*comparefunc)(const void *a, const void *b, void *extra);
36
37/* Called for every element removed from the dictionary. See
38 * dictionary_destroy, dictionary_insert, and dictionary_remove.
39 */
40typedef void (*destroyfunc)(void *k, void *v, void *extra);
41
42/* Called for each element in the dictionary. Return FALSE if you don't want
43 * to enumerate any more.
44 */
45typedef BOOL (*enumeratefunc)(const void *k, const void *v, void *extra,
46 void *closure);
47
48/* Constructs a dictionary, using c as a comparison function for keys.
49 * If d is not NULL, it will be called whenever an item is about to be removed
50 * from the table, for example when dictionary_remove is called for a key, or
51 * when dictionary_destroy is called.
52 * extra is passed to c (and d, if it's provided).
53 * Assumes c is not NULL.
54 */
56
57/* Assumes d is not NULL. */
59
60/* Returns how many entries have been stored in the dictionary. If two values
61 * with the same key are inserted, only one is counted.
62 */
64
65/* Sets an element with key k and value v to the dictionary. If a value
66 * already exists with key k, its value is replaced, and the destroyfunc (if
67 * set) is called for the previous item.
68 * Assumes k and v can be bitwise-copied.
69 * Both k and v are allowed to be NULL, in case you want to use integer
70 * values for either the key or the value.
71 * Assumes d is not NULL.
72 */
73void dictionary_insert(struct dictionary *d, const void *k, const void *v) DECLSPEC_HIDDEN;
74
75/* If a value with key k has been inserted into the dictionary, *v is set
76 * to its associated value. Returns FALSE if the key is not found, and TRUE
77 * if it is. *v is undefined if it returns FALSE. (It is not set to NULL,
78 * because this dictionary doesn't prevent you from using NULL as a value
79 * value; see dictionary_insert.)
80 * Assumes d and v are not NULL.
81 */
82BOOL dictionary_find(struct dictionary *d, const void *k, void **v) DECLSPEC_HIDDEN;
83
84/* Removes the element with key k from the dictionary. Calls the destroyfunc
85 * for the dictionary with the element if found (so you may destroy it if it's
86 * dynamically allocated.)
87 * Assumes d is not NULL.
88 */
89void dictionary_remove(struct dictionary *d, const void *k) DECLSPEC_HIDDEN;
90
92
93#endif /* ndef __DICTIONARY_H__ */
BOOL(* enumeratefunc)(const void *k, const void *v, void *extra, void *closure)
Definition: dictionary.h:45
void(* destroyfunc)(void *k, void *v, void *extra)
Definition: dictionary.h:40
BOOL dictionary_find(struct dictionary *d, const void *k, void **v) DECLSPEC_HIDDEN
Definition: dictionary.c:142
void dictionary_insert(struct dictionary *d, const void *k, const void *v) DECLSPEC_HIDDEN
Definition: dictionary.c:113
UINT dictionary_num_entries(struct dictionary *d) DECLSPEC_HIDDEN
Definition: dictionary.c:85
void dictionary_enumerate(struct dictionary *d, enumeratefunc e, void *closure) DECLSPEC_HIDDEN
Definition: dictionary.c:179
struct dictionary * dictionary_create(comparefunc c, destroyfunc d, void *extra) DECLSPEC_HIDDEN
Definition: dictionary.c:45
void dictionary_destroy(struct dictionary *d) DECLSPEC_HIDDEN
Definition: dictionary.c:65
int(* comparefunc)(const void *a, const void *b, void *extra)
Definition: dictionary.h:35
void dictionary_remove(struct dictionary *d, const void *k) DECLSPEC_HIDDEN
Definition: dictionary.c:161
#define DECLSPEC_HIDDEN
Definition: precomp.h:8
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned int BOOL
Definition: ntddk_ex.h:94
const GLdouble * v
Definition: gl.h:2040
const GLubyte * c
Definition: glext.h:8905
@ extra
Definition: id3.c:95
#define d
Definition: ke_i.h:81
#define e
Definition: ke_i.h:82
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
int k
Definition: mpi.c:3369
unsigned int UINT
Definition: ndis.h:50
#define BOOL
Definition: nt_native.h:43