Fri, 09 Aug 2013 18:46:07 +0200
changed parameter order of ucx_map_new_a
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
1 | /* |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
3 | * |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
5 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
8 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
11 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
15 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
27 | */ |
2
79646375a420
Added some source files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
29 | #include <stdlib.h> |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
30 | #include <string.h> |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
31 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
32 | #include "map.h" |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
33 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
34 | UcxMap *ucx_map_new(size_t size) { |
137
81a02ad99388
changed parameter order of ucx_map_new_a
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
35 | return ucx_map_new_a(NULL, size); |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
36 | } |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
37 | |
137
81a02ad99388
changed parameter order of ucx_map_new_a
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
136
diff
changeset
|
38 | UcxMap *ucx_map_new_a(UcxAllocator *allocator, size_t size) { |
45
dd03226c1a6b
map counts elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
39 | if(size == 0) { |
dd03226c1a6b
map counts elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
40 | size = 16; |
dd03226c1a6b
map counts elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
41 | } |
108
d2b1e67b2b48
new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
107
diff
changeset
|
42 | |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
43 | if(!allocator) { |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
44 | allocator = ucx_default_allocator(); |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
45 | } |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
46 | |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
47 | UcxMap *map = (UcxMap*)allocator->malloc(allocator->pool, sizeof(UcxMap)); |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
48 | if(map == NULL) { |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
49 | return NULL; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
50 | } |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
51 | |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
52 | map->allocator = allocator; |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
53 | map->map = (UcxMapElement**)allocator->calloc( |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
54 | allocator->pool, |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
55 | size, |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
56 | sizeof(UcxMapElement*)); |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
57 | if(map->map == NULL) { |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
58 | allocator->free(allocator->pool, map); |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
59 | return NULL; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
60 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
61 | map->size = size; |
45
dd03226c1a6b
map counts elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
62 | map->count = 0; |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
63 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
64 | return map; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
65 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
66 | |
116
234920008754
some fixes and some documentation
Mike Becker <universe@uap-core.de>
parents:
112
diff
changeset
|
67 | static void ucx_map_free_elmlist(UcxMap *map) { |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
68 | for (size_t n = 0 ; n < map->size ; n++) { |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
69 | UcxMapElement *elem = map->map[n]; |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
70 | if (elem != NULL) { |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
71 | do { |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
72 | UcxMapElement *next = elem->next; |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
73 | map->allocator->free(map->allocator->pool, elem->key.data); |
112
6384016df2a3
removed map load/store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
111
diff
changeset
|
74 | map->allocator->free(map->allocator->pool, elem); |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
75 | elem = next; |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
76 | } while (elem != NULL); |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
77 | } |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
78 | } |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
79 | map->allocator->free(map->allocator->pool, map->map); |
70
6721482eaf8e
fixed memory leak in ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
80 | } |
6721482eaf8e
fixed memory leak in ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
81 | |
6721482eaf8e
fixed memory leak in ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
82 | void ucx_map_free(UcxMap *map) { |
6721482eaf8e
fixed memory leak in ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
83 | ucx_map_free_elmlist(map); |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
84 | map->allocator->free(map->allocator->pool, map); |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
85 | } |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
86 | |
67
27e67e725d35
added some qualifiers + removed pointer alias in mergesort
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
87 | int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to, |
27e67e725d35
added some qualifiers + removed pointer alias in mergesort
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
88 | copy_func fnc, void *data) { |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
89 | UcxMapIterator i = ucx_map_iterator(from); |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
90 | void *value; |
111
c8c59d7f4536
new map foreach macro
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
91 | UCX_MAP_FOREACH(key, value, i) { |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
92 | int ret = ucx_map_put(to, i.cur->key, fnc ? fnc(value, data) : value); |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
93 | if(ret != 0) { |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
94 | return 1; |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
95 | } |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
96 | } |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
97 | return 0; |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
98 | } |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
99 | |
44 | 100 | UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data) { |
51
1c78cd19fb6b
added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
101 | size_t bs = (map->count * 5) >> 1; |
45
dd03226c1a6b
map counts elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
102 | UcxMap *newmap = ucx_map_new(bs > map->size ? bs : map->size); |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
103 | if(newmap == NULL) { |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
104 | return NULL; |
44 | 105 | } |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
106 | ucx_map_copy(map, newmap, fnc, data); |
44 | 107 | return newmap; |
108 | } | |
109 | ||
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
110 | int ucx_map_rehash(UcxMap *map) { |
51
1c78cd19fb6b
added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
111 | size_t load = (map->size * 3) >> 2; |
1c78cd19fb6b
added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
112 | if (map->count > load) { |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
113 | UcxMap oldmap; |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
114 | oldmap.map = map->map; |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
115 | oldmap.size = map->size; |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
116 | oldmap.count = map->count; |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
117 | oldmap.allocator = map->allocator; |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
118 | |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
119 | map->size = (map->count * 5) >> 1; |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
120 | map->map = (UcxMapElement**)map->allocator->calloc( |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
121 | map->allocator->pool, |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
122 | map->size, |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
123 | sizeof(UcxMapElement*)); |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
124 | if(map->map == NULL) { |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
125 | *map = oldmap; |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
126 | return 1; |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
127 | } |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
128 | map->count = 0; |
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
129 | ucx_map_copy(&oldmap, map, NULL, NULL); |
70
6721482eaf8e
fixed memory leak in ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
130 | |
6721482eaf8e
fixed memory leak in ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
131 | /* free the UcxMapElement list of oldmap */ |
6721482eaf8e
fixed memory leak in ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
69
diff
changeset
|
132 | ucx_map_free_elmlist(&oldmap); |
51
1c78cd19fb6b
added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
133 | } |
52
34f50d0bada4
added ucx_map_copy and fixed ucx_map_rehash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
134 | return 0; |
51
1c78cd19fb6b
added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
135 | } |
1c78cd19fb6b
added rehashing to maps by using clone function
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
136 | |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
137 | int ucx_map_put(UcxMap *map, UcxKey key, void *data) { |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
138 | UcxAllocator *allocator = map->allocator; |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
139 | |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
140 | if(key.hash == 0) { |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
141 | key.hash = ucx_hash((char*)key.data, key.len); |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
142 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
143 | |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
144 | size_t slot = key.hash%map->size; |
67
27e67e725d35
added some qualifiers + removed pointer alias in mergesort
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
145 | UcxMapElement *restrict elm = map->map[slot]; |
27e67e725d35
added some qualifiers + removed pointer alias in mergesort
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
146 | UcxMapElement *restrict prev = NULL; |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
147 | |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
148 | while (elm != NULL && elm->key.hash < key.hash) { |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
149 | prev = elm; |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
150 | elm = elm->next; |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
151 | } |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
152 | |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
153 | if (elm == NULL || elm->key.hash != key.hash) { |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
154 | UcxMapElement *e = (UcxMapElement*)allocator->malloc( |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
155 | allocator->pool, |
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
156 | sizeof(UcxMapElement)); |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
157 | if(e == NULL) { |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
158 | return -1; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
159 | } |
30 | 160 | e->key.data = NULL; |
53 | 161 | if (prev) { |
162 | prev->next = e; | |
163 | } else { | |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
164 | map->map[slot] = e; |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
165 | } |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
166 | e->next = elm; |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
167 | elm = e; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
168 | } |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
169 | |
30 | 170 | if(elm->key.data == NULL) { |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
171 | void *kd = allocator->malloc(allocator->pool, key.len); |
30 | 172 | if (kd == NULL) { |
173 | return -1; | |
174 | } | |
175 | memcpy(kd, key.data, key.len); | |
176 | key.data = kd; | |
177 | elm->key = key; | |
45
dd03226c1a6b
map counts elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
178 | map->count++; |
30 | 179 | } |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
180 | elm->data = data; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
181 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
182 | return 0; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
183 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
184 | |
53 | 185 | void* ucx_map_get_and_remove(UcxMap *map, UcxKey key, _Bool remove) { |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
186 | if(key.hash == 0) { |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
187 | key.hash = ucx_hash((char*)key.data, key.len); |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
188 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
189 | |
53 | 190 | size_t slot = key.hash%map->size; |
67
27e67e725d35
added some qualifiers + removed pointer alias in mergesort
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
191 | UcxMapElement *restrict elm = map->map[slot]; |
27e67e725d35
added some qualifiers + removed pointer alias in mergesort
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
192 | UcxMapElement *restrict pelm = NULL; |
53 | 193 | while (elm && elm->key.hash <= key.hash) { |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
194 | if(elm->key.hash == key.hash) { |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
195 | int n = (key.len > elm->key.len) ? elm->key.len : key.len; |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
196 | if (memcmp(elm->key.data, key.data, n) == 0) { |
53 | 197 | void *data = elm->data; |
198 | if (remove) { | |
199 | if (pelm) { | |
200 | pelm->next = elm->next; | |
201 | } else { | |
202 | map->map[slot] = elm->next; | |
203 | } | |
107
86b19c98b5fd
map uses an allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
204 | map->allocator->free(map->allocator->pool, elm); |
53 | 205 | map->count--; |
206 | } | |
207 | ||
208 | return data; | |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
209 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
210 | } |
53 | 211 | pelm = elm; |
212 | elm = pelm->next; | |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
213 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
214 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
215 | return NULL; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
216 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
217 | |
53 | 218 | void *ucx_map_get(UcxMap *map, UcxKey key) { |
219 | return ucx_map_get_and_remove(map, key, 0); | |
220 | } | |
221 | ||
222 | void *ucx_map_remove(UcxMap *map, UcxKey key) { | |
223 | return ucx_map_get_and_remove(map, key, 1); | |
224 | } | |
225 | ||
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
226 | UcxKey ucx_key(void *data, size_t len) { |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
227 | UcxKey key; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
228 | key.data = data; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
229 | key.len = len; |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
67
diff
changeset
|
230 | key.hash = ucx_hash((const char*) data, len); |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
231 | return key; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
232 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
233 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
234 | |
67
27e67e725d35
added some qualifiers + removed pointer alias in mergesort
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
235 | int ucx_hash(const char *data, size_t len) { |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
236 | /* murmur hash 2 */ |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
237 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
238 | int m = 0x5bd1e995; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
239 | int r = 24; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
240 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
241 | int h = 25 ^ len; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
242 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
243 | int i = 0; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
244 | while (len >= 4) { |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
245 | int k = data[i + 0] & 0xFF; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
246 | k |= (data[i + 1] & 0xFF) << 8; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
247 | k |= (data[i + 2] & 0xFF) << 16; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
248 | k |= (data[i + 3] & 0xFF) << 24; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
249 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
250 | k *= m; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
251 | k ^= k >> r; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
252 | k *= m; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
253 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
254 | h *= m; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
255 | h ^= k; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
256 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
257 | i += 4; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
258 | len -= 4; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
259 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
260 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
261 | switch (len) { |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
262 | case 3: h ^= (data[i + 2] & 0xFF) << 16; |
38
35f67a8ef875
added missing stddef includes
Mike Becker <universe@uap-core.de>
parents:
31
diff
changeset
|
263 | /* no break */ |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
264 | case 2: h ^= (data[i + 1] & 0xFF) << 8; |
38
35f67a8ef875
added missing stddef includes
Mike Becker <universe@uap-core.de>
parents:
31
diff
changeset
|
265 | /* no break */ |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
266 | case 1: h ^= (data[i + 0] & 0xFF); h *= m; |
38
35f67a8ef875
added missing stddef includes
Mike Becker <universe@uap-core.de>
parents:
31
diff
changeset
|
267 | /* no break */ |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
268 | } |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
269 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
270 | h ^= h >> 13; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
271 | h *= m; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
272 | h ^= h >> 15; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
273 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
274 | return h; |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
2
diff
changeset
|
275 | } |
31
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
276 | |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
277 | UcxMapIterator ucx_map_iterator(UcxMap *map) { |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
278 | UcxMapIterator i; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
279 | i.map = map; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
280 | i.cur = NULL; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
281 | i.index = 0; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
282 | return i; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
283 | } |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
284 | |
111
c8c59d7f4536
new map foreach macro
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
285 | int ucx_map_iter_next(UcxMapIterator *i, UcxKey *key, void **elm) { |
31
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
286 | UcxMapElement *e = i->cur; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
287 | |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
288 | if(e == NULL) { |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
289 | e = i->map->map[0]; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
290 | } else { |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
291 | e = e->next; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
292 | } |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
293 | |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
294 | while(i->index < i->map->size) { |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
295 | if(e != NULL) { |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
296 | if(e->data != NULL) { |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
297 | i->cur = e; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
298 | *elm = e->data; |
111
c8c59d7f4536
new map foreach macro
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
299 | *key = e->key; |
31
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
300 | return 0; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
301 | } |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
302 | |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
303 | e = e->next; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
304 | } else { |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
305 | i->index++; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
306 | |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
307 | if(i->index < i->map->size) { |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
308 | e = i->map->map[i->index]; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
309 | } |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
310 | } |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
311 | } |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
312 | |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
313 | return 1; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
314 | } |
42
ff3dd1ee7dee
(broken-commit) - added load and store functions, tests failing
Mike Becker <universe@uap-core.de>
parents:
38
diff
changeset
|
315 |