ucx/map.h

Tue, 26 Jan 2016 20:06:16 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 26 Jan 2016 20:06:16 +0100
changeset 117
38c53b8a6139
parent 0
1f419bd32da1
child 124
80609f9675f1
permissions
-rw-r--r--

added combobox (Motif)

0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 * @file map.h
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 * Hash map implementation.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 * This implementation uses murmur hash 2 and separate chaining with linked
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 * lists.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 * @author Mike Becker
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 * @author Olaf Wintermann
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #ifndef UCX_MAP_H
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #define UCX_MAP_H
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 #include "ucx.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #include "string.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 #include "allocator.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 #include <stdio.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 #ifdef __cplusplus
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 extern "C" {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 #endif
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 * Loop statement for UCX maps.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 * The <code>key</code> variable is implicitly defined, but the
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 * <code>value</code> variable must be already declared as type information
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 * cannot be inferred.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 * @param key the variable name for the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 * @param value the variable name for the value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 * @param iter an UcxMapIterator
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 * @see ucx_map_iterator()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 #define UCX_MAP_FOREACH(key,value,iter) \
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 for(UcxKey key;ucx_map_iter_next(&iter,&key, (void**)&value);)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 /** Type for the UCX map. @see UcxMap */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 typedef struct UcxMap UcxMap;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 /** Type for a key of an UcxMap. @see UcxKey */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 typedef struct UcxKey UcxKey;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 /** Type for an element of an UcxMap. @see UcxMapElement */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 typedef struct UcxMapElement UcxMapElement;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 /** Type for an iterator over an UcxMap. @see UcxMapIterator */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 typedef struct UcxMapIterator UcxMapIterator;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 /** Structure for the UCX map. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 struct UcxMap {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 /** An allocator that is used for the map elements. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 UcxAllocator *allocator;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 /** The array of map element lists. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 UcxMapElement **map;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 /** The size of the map is the length of the element list array. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 size_t size;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 /** The count of elements currently stored in this map. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 size_t count;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 };
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 /** Structure for a key of an UcxMap. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 struct UcxKey {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 /** The key data. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 void *data;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 /** The length of the key data. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 size_t len;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 /** The hash value of the key data. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 int hash;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 };
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 /** Structure for an element of an UcxMap. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 struct UcxMapElement {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 /** The value data. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 void *data;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 /** A pointer to the next element in the current list. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 UcxMapElement *next;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 /** The corresponding key. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 UcxKey key;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 };
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 /** Structure for an iterator over an UcxMap. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 struct UcxMapIterator {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 /** The map to iterate over. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 UcxMap *map;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 /** The current map element. */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 UcxMapElement *cur;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 * The current index of the element list array.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 * <b>Attention: </b> this is <b>NOT</b> the element index! Do <b>NOT</b>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 * manually iterate over the map by increasing this index. Use
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 * ucx_map_iter_next().
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 * @see UcxMap.map*/
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 size_t index;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 };
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 * Creates a new hash map with the specified size.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 * @param size the size of the hash map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 * @return a pointer to the new hash map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 UcxMap *ucx_map_new(size_t size);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 * Creates a new hash map with the specified size using an UcxAllocator.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 * @param allocator the allocator to use
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 * @param size the size of the hash map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 * @return a pointer to the new hash map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 UcxMap *ucx_map_new_a(UcxAllocator *allocator, size_t size);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 * Frees a hash map.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 * <b>Note:</b> the contents are <b>not</b> freed, use an UcxMempool for that
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 * purpose.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 * @param map the map to be freed
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 void ucx_map_free(UcxMap *map);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 * Copies contents from a map to another map using a copy function.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 * <b>Note:</b> The destination map does not need to be empty. However, if it
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 * contains data with keys that are also present in the source map, the contents
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 * are overwritten.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 * @param from the source map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 * @param to the destination map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 * @param fnc the copy function or <code>NULL</code> if the pointer address
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 * shall be copied
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 * @param data additional data for the copy function
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 * @return 0 on success or a non-zero value on memory allocation errors
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 copy_func fnc, void *data);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 * Clones the map and rehashes if necessary.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 * <b>Note:</b> In contrast to ucx_map_rehash() the load factor is irrelevant.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 * This function <i>always</i> ensures a new UcxMap.size of at least
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 * 2.5*UcxMap.count.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 * @param map the map to clone
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 * @param fnc the copy function to use or <code>NULL</code> if the new and
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 * the old map shall share the data pointers
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 * @param data additional data for the copy function
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 * @return the cloned map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 * @see ucx_map_copy()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 * Increases size of the hash map, if necessary.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 * The load value is 0.75*UcxMap.size. If the element count exceeds the load
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 * value, the map needs to be rehashed. Otherwise no action is performed and
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 * this function simply returns 0.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 * The rehashing process ensures, that the UcxMap.size is at least
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 * 2.5*UcxMap.count. So there is enough room for additional elements without
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 * the need of another soon rehashing.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 * You can use this function to dramatically increase access performance.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 * @param map the map to rehash
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 * @return 1, if a memory allocation error occurred, 0 otherwise
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 int ucx_map_rehash(UcxMap *map);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 * Puts a key/value-pair into the map.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 * @param value the value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 * @return 0 on success, non-zero value on failure
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 int ucx_map_put(UcxMap *map, UcxKey key, void *value);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 * Retrieves a value by using a key.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 * @return the value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 void* ucx_map_get(UcxMap *map, UcxKey key);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 * Removes a key/value-pair from the map by using the key.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 * @return the removed value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 void* ucx_map_remove(UcxMap *map, UcxKey key);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 * Shorthand for putting data with a sstr_t key into the map.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 * @param value the value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 * @return 0 on success, non-zero value on failure
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 * @see ucx_map_put()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 #define ucx_map_sstr_put(map, key, value) \
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 ucx_map_put(map, ucx_key(key.ptr, key.length), (void*)value)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 * Shorthand for putting data with a C string key into the map.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 * @param value the value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 * @return 0 on success, non-zero value on failure
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 * @see ucx_map_put()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 #define ucx_map_cstr_put(map, key, value) \
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 ucx_map_put(map, ucx_key((void*)key, strlen(key)), (void*)value)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 * Shorthand for putting data with an integer key into the map.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 * @param value the value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 * @return 0 on success, non-zero value on failure
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 * @see ucx_map_put()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 #define ucx_map_int_put(map, key, value) \
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 ucx_map_put(map, ucx_key((void*)&key, sizeof(key)), (void*)value)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 * Shorthand for getting data from the map with a sstr_t key.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 * @return the value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 * @see ucx_map_get()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 #define ucx_map_sstr_get(map, key) \
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 ucx_map_get(map, ucx_key(key.ptr, key.length))
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 * Shorthand for getting data from the map with a C string key.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 * @return the value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 * @see ucx_map_get()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 #define ucx_map_cstr_get(map, key) \
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 ucx_map_get(map, ucx_key((void*)key, strlen(key)))
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 * Shorthand for getting data from the map with an integer key.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 * @return the value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 * @see ucx_map_get()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 #define ucx_map_int_get(map, key) \
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 ucx_map_get(map, ucx_key((void*)&key, sizeof(int)))
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 * Shorthand for removing data from the map with a sstr_t key.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 * @return the removed value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 * @see ucx_map_remove()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 #define ucx_map_sstr_remove(map, key) \
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 ucx_map_remove(map, ucx_key(key.ptr, key.length))
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 * Shorthand for removing data from the map with a C string key.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 * @return the removed value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 * @see ucx_map_remove()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 #define ucx_map_cstr_remove(map, key) \
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 ucx_map_remove(map, ucx_key((void*)key, strlen(key)))
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 * Shorthand for removing data from the map with an integer key.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 * @param map the map
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 * @param key the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 * @return the removed value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 * @see ucx_map_remove()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 #define ucx_map_int_remove(map, key) \
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 ucx_map_remove(map, ucx_key((void*)&key, sizeof(key)))
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 * Creates an UcxKey based on the given data.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 * This function implicitly computes the hash.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 * @param data the data for the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 * @param len the length of the data
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 * @return an UcxKey with implicitly computed hash
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 * @see ucx_hash()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 UcxKey ucx_key(void *data, size_t len);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 * Computes a murmur hash-2.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 * @param data the data to hash
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 * @param len the length of the data
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 * @return the murmur hash-2 of the data
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 int ucx_hash(const char *data, size_t len);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 * Creates an iterator for a map.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352 * <b>Note:</b> An UcxMapIterator iterates over all elements in all element
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 * lists successively. Therefore the order highly depends on the key hashes and
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354 * may vary under different map sizes. So generally you may <b>NOT</b> rely on
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 * the iteration order.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 * <b>Note:</b> The iterator is <b>NOT</b> initialized. You need to call
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 * ucx_map_iter_next() at least once before accessing any information. However,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 * it is not recommended to access the fields of an UcxMapIterator directly.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361 * @param map the map to create the iterator for
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362 * @return an iterator initialized on the first element of the
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 * first element list
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 * @see ucx_map_iter_next()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 UcxMapIterator ucx_map_iterator(UcxMap *map);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 /**
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369 * Proceeds to the next element of the map (if any).
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 * Subsequent calls on the same iterator proceed to the next element and
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 * store the key/value-pair into the memory specified as arguments of this
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 * function.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 * If no further elements are found, this function returns zero and leaves the
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 * last found key/value-pair in memory.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 * @param iterator the iterator to use
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
379 * @param key a pointer to the memory where to store the key
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 * @param value a pointer to the memory where to store the value
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381 * @return 1, if another element was found, 0 if all elements has been processed
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382 * @see ucx_map_iterator()
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
384 int ucx_map_iter_next(UcxMapIterator *iterator, UcxKey *key, void **value);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
385
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
386
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387 #ifdef __cplusplus
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
388 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
389 #endif
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
390
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 #endif /* UCX_MAP_H */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392

mercurial