src/server/ucx/map.h

changeset 66
74babc0082b7
parent 51
b28cf69f42e8
child 67
50505dc3f8a6
--- a/src/server/ucx/map.h	Wed May 22 15:05:06 2013 +0200
+++ b/src/server/ucx/map.h	Sun May 26 12:12:07 2013 +0200
@@ -1,5 +1,29 @@
 /*
- * 
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef MAP_H
@@ -15,7 +39,7 @@
 #endif
 
 #define UCX_MAP_FOREACH(elm,iter) \
-        for(;ucx_map_iter_next(&iter,(void*)&elm)==0;)
+        for(;ucx_map_iter_next(&iter,(void**)&elm)==0;)
 
 typedef struct UcxMap          UcxMap;
 typedef struct UcxKey          UcxKey;
@@ -37,7 +61,7 @@
 };
 
 struct UcxKey {
-    void   *data;
+    char   *data;
     size_t len;
     int    hash;
 };
@@ -51,28 +75,46 @@
 struct UcxMapIterator {
     UcxMap        *map;
     UcxMapElement *cur;
-    int           index;
+    size_t        index;
 };
 
 
 UcxMap *ucx_map_new(size_t size);
 void ucx_map_free(UcxMap *map);
 /* you cannot clone maps with more than 390 mio entries */
-int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data);
+int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to,
+        copy_func fnc, void *data);
 UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data);
 int ucx_map_rehash(UcxMap *map);
 
 int ucx_map_put(UcxMap *map, UcxKey key, void *data);
 void* ucx_map_get(UcxMap *map, UcxKey key);
+void* ucx_map_remove(UcxMap *map, UcxKey key);
 
-#define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d)
-#define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, strlen(s)), d)
-#define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length))
-#define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, strlen(s)))
+#define ucx_map_sstr_put(m, s, d) \
+    ucx_map_put(m, ucx_key(s.ptr, s.length), d)
+#define ucx_map_cstr_put(m, s, d) \
+    ucx_map_put(m, ucx_key((void*)s, strlen(s)), d)
+#define ucx_map_int_put(m, i, d) \
+    ucx_map_put(m, ucx_key((void*)&i, sizeof(i)), d)
+
+#define ucx_map_sstr_get(m, s) \
+    ucx_map_get(m, ucx_key(s.ptr, s.length))
+#define ucx_map_cstr_get(m, s) \
+    ucx_map_get(m, ucx_key((void*)s, strlen(s)))
+#define ucx_map_int_get(m, i) \
+    ucx_map_get(m, ucx_key((void*)&i, sizeof(int)))
+
+#define ucx_map_sstr_remove(m, s) \
+    ucx_map_remove(m, ucx_key(s.ptr, s.length))
+#define ucx_map_cstr_remove(m, s) \
+    ucx_map_remove(m, ucx_key((void*)s, strlen(s)))
+#define ucx_map_int_remove(m, i) \
+    ucx_map_remove(m, ucx_key((void*)&i, sizeof(i)))
 
 UcxKey ucx_key(void *data, size_t len);
 
-int ucx_hash(char *data, size_t len);
+int ucx_hash(const char *data, size_t len);
 
 UcxMapIterator ucx_map_iterator(UcxMap *map);
 

mercurial