[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r7865 - in GNUnet: . src/applications/sqstore_mysql src/inc
From: |
gnunet |
Subject: |
[GNUnet-SVN] r7865 - in GNUnet: . src/applications/sqstore_mysql src/include src/util/containers |
Date: |
Sat, 8 Nov 2008 21:20:21 -0700 (MST) |
Author: grothoff
Date: 2008-11-08 21:20:20 -0700 (Sat, 08 Nov 2008)
New Revision: 7865
Added:
GNUnet/src/util/containers/maptest.c
Modified:
GNUnet/src/applications/sqstore_mysql/mysql.c
GNUnet/src/include/gnunet_util_containers.h
GNUnet/src/util/containers/Makefile.am
GNUnet/src/util/containers/multihashmap.c
GNUnet/todo
Log:
multihashmap test and bugfixes
Modified: GNUnet/src/applications/sqstore_mysql/mysql.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysql.c 2008-11-08 09:21:08 UTC
(rev 7864)
+++ GNUnet/src/applications/sqstore_mysql/mysql.c 2008-11-09 04:20:20 UTC
(rev 7865)
@@ -451,7 +451,9 @@
if ((ret != GNUNET_OK) ||
(rbind[0].buffer_length != contentSize) || (length != contentSize))
{
- GNUNET_GE_BREAK (NULL, 0);
+ GNUNET_GE_BREAK (NULL, (ret != GNUNET_OK));
+ GNUNET_GE_BREAK (NULL, (rbind[0].buffer_length != contentSize));
+ GNUNET_GE_BREAK (NULL, (length != contentSize));
do_delete_entry_by_vkey (vkey);
content_size -= ntohl (datum->size);
GNUNET_free (datum);
Modified: GNUnet/src/include/gnunet_util_containers.h
===================================================================
--- GNUnet/src/include/gnunet_util_containers.h 2008-11-08 09:21:08 UTC (rev
7864)
+++ GNUnet/src/include/gnunet_util_containers.h 2008-11-09 04:20:20 UTC (rev
7865)
@@ -334,19 +334,52 @@
/* ******************************* HashMap **************************** */
+/**
+ * Opaque handle for a HashMap.
+ */
struct GNUNET_MultiHashMap;
+/**
+ * Options for storing values in the HashMap.
+ */
enum GNUNET_MultiHashMapOption
{
+ /**
+ * If a value with the given key exists, replace it.
+ * Note that the old value would NOT be freed
+ * by replace (the application has to make sure that
+ * this happens if required).
+ */
GNUNET_MultiHashMapOption_REPLACE,
+
+ /**
+ * Allow multiple values with the same key.
+ */
GNUNET_MultiHashMapOption_MULTIPLE,
+
+ /**
+ * There must only be one value per key; storing
+ * a value should fail if a value under the same
+ * key already exists.
+ */
GNUNET_MultiHashMapOption_UNIQUE_ONLY,
+
+ /**
+ * There must only be one value per key, but don't
+ * bother checking if a value already exists
+ * (faster than UNIQUE_ONLY; implemented just like
+ * MULTIPLE but this option documents better what
+ * is intended if UNIQUE is what is desired).
+ */
GNUNET_MultiHashMapOption_UNIQUE_FAST
};
/**
* Iterator over HashCodes.
*
+ * @param key current key code
+ * @param value value in the hash map
+ * @param cls client-defined argument
* @return GNUNET_YES if we should continue to
* iterate,
* GNUNET_NO if not.
@@ -355,34 +388,126 @@
void *value, void *cls);
+/**
+ * Create a multi hash map.
+ *
+ * @param map the map
+ * @param len initial size (map will grow as needed)
+ * @return NULL on error
+ */
struct GNUNET_MultiHashMap *GNUNET_multi_hash_map_create (unsigned int len);
+/**
+ * Destroy a hash map. Will not free any values
+ * stored in the hash map!
+ *
+ * @param map the map
+ */
void GNUNET_multi_hash_map_destroy (struct GNUNET_MultiHashMap *map);
+/**
+ * Given a key find a value in the
+ * map matching the key.
+ *
+ * @param map the map
+ * @param key what to look for
+ * @return NULL if no value was found; note that
+ * this is indistinguishable from values that just
+ * happen to be NULL; use "contains" to test for
+ * key-value pairs with value NULL
+ */
void *GNUNET_multi_hash_map_get (const struct GNUNET_MultiHashMap *map,
const GNUNET_HashCode * key);
+/**
+ * Remove the given key-value pair from the map.
+ * Note that if the key-value pair is in the map
+ * multiple times, only one of the pairs will be
+ * removed.
+ *
+ * @param map the map
+ * @param key key of the key-value pair
+ * @param value value of the key-value pair
+ * @return GNUNET_YES on success, GNUNET_NO if the key-value pair
+ * is not in the map
+ */
int GNUNET_multi_hash_map_remove (struct GNUNET_MultiHashMap *map,
const GNUNET_HashCode * key, void *value);
+/**
+ * Remove all entries for the given key from the map.
+ * Note that the values would not be "freed".
+ *
+ * @param map the map
+ * @param key identifies values to be removed
+ * @return number of values removed
+ */
int GNUNET_multi_hash_map_remove_all (struct GNUNET_MultiHashMap *map,
const GNUNET_HashCode * key);
+/**
+ * Check if the map contains any value under the given
+ * key (including values that are NULL).
+ *
+ * @param map the map
+ * @param key the key to test if a value exists for it
+ * @return GNUNET_YES if such a value exists,
+ * GNUNET_NO if not
+ */
int GNUNET_multi_hash_map_contains (const struct GNUNET_MultiHashMap *map,
const GNUNET_HashCode * key);
+/**
+ * Store a key-value pair in the map.
+ *
+ * @param map the map
+ * @param key key to use
+ * @param value value to use
+ * @param opt options for put
+ * @return GNUNET_OK on success,
+ * GNUNET_NO if a value was replaced (with REPLACE)
+ * GNUNET_SYSERR if UNIQUE_ONLY was the option and the
+ * value already exists
+ */
int GNUNET_multi_hash_map_put (struct GNUNET_MultiHashMap *map,
const GNUNET_HashCode * key,
void *value,
enum GNUNET_MultiHashMapOption opt);
+/**
+ * Get the number of key-value pairs in the map.
+ *
+ * @param map the map
+ * @return the number of key value pairs
+ */
unsigned int GNUNET_multi_hash_map_size (const struct GNUNET_MultiHashMap
*map);
+
+/**
+ * Iterate over all entries in the map.
+ *
+ * @param map the map
+ * @param iterator function to call on each entry
+ * @param cls extra argument to it
+ * @return the number of key value pairs processed,
+ * GNUNET_SYSERR if it aborted iteration
+ */
int GNUNET_multi_hash_map_iterate (const struct GNUNET_MultiHashMap *map,
GNUNET_HashMapIterator iterator,
void *cls);
+/**
+ * Iterate over all entries in the map
+ * that match a particular key.
+ *
+ * @param map the map
+ * @param key key that the entries must correspond to
+ * @param iterator function to call on each entry
+ * @param cls extra argument to it
+ * @return the number of key value pairs processed,
+ * GNUNET_SYSERR if it aborted iteration
+ */
int GNUNET_multi_hash_map_get_multiple (const struct GNUNET_MultiHashMap *map,
const GNUNET_HashCode * key,
GNUNET_HashMapIterator iterator,
Modified: GNUnet/src/util/containers/Makefile.am
===================================================================
--- GNUnet/src/util/containers/Makefile.am 2008-11-08 09:21:08 UTC (rev
7864)
+++ GNUnet/src/util/containers/Makefile.am 2008-11-09 04:20:20 UTC (rev
7865)
@@ -15,7 +15,8 @@
check_PROGRAMS = \
bloomtest \
- metatest
+ maptest \
+ metatest
TESTS = $(check_PROGRAMS)
@@ -24,6 +25,10 @@
bloomtest_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la
+maptest_SOURCES = \
+ maptest.c
+maptest_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la
metatest_SOURCES = \
metatest.c
Added: GNUnet/src/util/containers/maptest.c
===================================================================
--- GNUnet/src/util/containers/maptest.c (rev 0)
+++ GNUnet/src/util/containers/maptest.c 2008-11-09 04:20:20 UTC (rev
7865)
@@ -0,0 +1,108 @@
+/*
+ This file is part of GNUnet.
+ (C) 2008 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file util/containers/maptest.c
+ * @brief Test for multihashmap.c
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include <extractor.h>
+#include "gnunet_util.h"
+
+#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); if
(m != NULL) GNUNET_multi_hash_map_destroy(m); return 1; }
+#define CHECK(c) { if (! (c)) ABORT(); }
+
+static int
+testMap (int i)
+{
+ struct GNUNET_MultiHashMap *m;
+ GNUNET_HashCode k1;
+ GNUNET_HashCode k2;
+ int j;
+
+ CHECK(NULL != (m = GNUNET_multi_hash_map_create (i)));
+ memset(&k1, 0, sizeof(k1));
+ memset(&k2, 1, sizeof(k2));
+ CHECK(GNUNET_NO == GNUNET_multi_hash_map_contains(m, &k1));
+ CHECK(GNUNET_NO == GNUNET_multi_hash_map_contains(m, &k2));
+ CHECK(GNUNET_NO == GNUNET_multi_hash_map_remove(m, &k1, NULL));
+ CHECK(GNUNET_NO == GNUNET_multi_hash_map_remove(m, &k2, NULL));
+ CHECK(NULL == GNUNET_multi_hash_map_get(m, &k1));
+ CHECK(NULL == GNUNET_multi_hash_map_get(m, &k2));
+ CHECK(0 == GNUNET_multi_hash_map_remove_all(m, &k1));
+ CHECK(0 == GNUNET_multi_hash_map_size(m));
+ CHECK(0 == GNUNET_multi_hash_map_iterate(m, NULL, NULL));
+ CHECK(0 == GNUNET_multi_hash_map_get_multiple(m, &k1, NULL, NULL));
+
+ CHECK(GNUNET_OK == GNUNET_multi_hash_map_put(m,
+ &k1,
+ "v1",
+
GNUNET_MultiHashMapOption_REPLACE));
+ CHECK(1 == GNUNET_multi_hash_map_size(m));
+ CHECK(0 == strcmp("v1", GNUNET_multi_hash_map_get(m, &k1)));
+ CHECK(GNUNET_NO == GNUNET_multi_hash_map_put(m,
+ &k1,
+ "v1",
+
GNUNET_MultiHashMapOption_REPLACE));
+ CHECK(1 == GNUNET_multi_hash_map_size(m));
+ CHECK(GNUNET_OK == GNUNET_multi_hash_map_put(m,
+ &k1,
+ "v2",
+
GNUNET_MultiHashMapOption_MULTIPLE));
+ CHECK(GNUNET_OK == GNUNET_multi_hash_map_put(m,
+ &k1,
+ "v3",
+
GNUNET_MultiHashMapOption_MULTIPLE));
+ CHECK(3 == GNUNET_multi_hash_map_size(m));
+ CHECK(GNUNET_OK == GNUNET_multi_hash_map_remove(m,
+ &k1,
+ "v3"));
+ CHECK(2 == GNUNET_multi_hash_map_size(m));
+ CHECK(GNUNET_YES == GNUNET_multi_hash_map_contains(m, &k1));
+ CHECK(GNUNET_NO == GNUNET_multi_hash_map_contains(m, &k2));
+ CHECK(2 == GNUNET_multi_hash_map_get_multiple(m, &k1, NULL, NULL));
+ CHECK(0 == GNUNET_multi_hash_map_get_multiple(m, &k2, NULL, NULL));
+ CHECK(2 == GNUNET_multi_hash_map_iterate(m, NULL, NULL));
+ CHECK(2 == GNUNET_multi_hash_map_remove_all(m, &k1));
+ for (j=0;j<1024;j++)
+ CHECK(GNUNET_OK == GNUNET_multi_hash_map_put(m,
+ &k1,
+ "v2",
+
GNUNET_MultiHashMapOption_MULTIPLE));
+ GNUNET_multi_hash_map_destroy(m);
+ return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+ int failureCount = 0;
+ int i;
+
+ for (i = 1; i < 255; i++)
+ failureCount += testMap (i);
+ if (failureCount != 0)
+ return 1;
+ return 0;
+}
+
+/* end of maptest.c */
Modified: GNUnet/src/util/containers/multihashmap.c
===================================================================
--- GNUnet/src/util/containers/multihashmap.c 2008-11-08 09:21:08 UTC (rev
7864)
+++ GNUnet/src/util/containers/multihashmap.c 2008-11-09 04:20:20 UTC (rev
7865)
@@ -117,7 +117,8 @@
e = map->map[i];
while (e != NULL)
{
- if (GNUNET_OK != it (&e->key, e->value, cls))
+ if ( (NULL != it) &&
+ (GNUNET_OK != it (&e->key, e->value, cls)) )
return GNUNET_SYSERR;
count++;
e = e->next;
@@ -246,7 +247,7 @@
unsigned int i;
i = idx_of (map, key);
- if ((opt != GNUNET_MultiHashMapOption_MULTIPLE) ||
+ if ((opt != GNUNET_MultiHashMapOption_MULTIPLE) &&
(opt != GNUNET_MultiHashMapOption_UNIQUE_FAST))
{
e = map->map[i];
@@ -286,9 +287,15 @@
e = map->map[idx_of (map, key)];
while (e != NULL)
{
- if (GNUNET_OK != it (&e->key, e->value, cls))
- return GNUNET_SYSERR;
- count++;
+ if (0 == memcmp(key,
+ &e->key,
+ sizeof(GNUNET_HashCode)))
+ {
+ if ( (it != NULL) &&
+ (GNUNET_OK != it (&e->key, e->value, cls)) )
+ return GNUNET_SYSERR;
+ count++;
+ }
e = e->next;
}
return count;
Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2008-11-08 09:21:08 UTC (rev 7864)
+++ GNUnet/todo 2008-11-09 04:20:20 UTC (rev 7865)
@@ -1,7 +1,6 @@
This is just the current plan, plans change.
-0.8.1 [8'08] (aka "growth"):
-- test & document multihashmap
+0.8.1 [12'08] (aka "growth"):
- make GUIs handle namespace advertisement events
=> enable publishing of namespace ads in FSUI
=> test
@@ -17,7 +16,7 @@
* improve gnunet-setup (more auto-detection in wizards, more testing)
* external IP detector webpage
-0.8.2 [12'08] (aka "integration"):
+0.8.2 [?'09] (aka "integration"):
- Performance:
* tune DHT
* tune GAP query planning code
@@ -30,11 +29,11 @@
* HTTPS support (#1225)
* support NAT-PMP (in addition to UPnP)
-0.8.3 [5'09] (aka "chat"):
+0.8.3 [?'09] (aka "chat"):
- P2P chat
-1.0.0 [6'09] (aka "userfriendly"):
+1.0.0 [?'09] (aka "userfriendly"):
- transport selection (given multiple choices,
how should GNUnet pick a transport?)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r7865 - in GNUnet: . src/applications/sqstore_mysql src/include src/util/containers,
gnunet <=