[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8001 - in GNUnet/src: include util/containers
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8001 - in GNUnet/src: include util/containers |
Date: |
Sat, 13 Dec 2008 17:45:05 -0700 (MST) |
Author: nevans
Date: 2008-12-13 17:45:04 -0700 (Sat, 13 Dec 2008)
New Revision: 8001
Modified:
GNUnet/src/include/dv.h
GNUnet/src/include/gnunet_util_containers.h
GNUnet/src/util/containers/multihashmap.c
Log:
more fun
Modified: GNUnet/src/include/dv.h
===================================================================
--- GNUnet/src/include/dv.h 2008-12-14 00:36:20 UTC (rev 8000)
+++ GNUnet/src/include/dv.h 2008-12-14 00:45:04 UTC (rev 8001)
@@ -32,18 +32,14 @@
#define GNUNET_DV_LEAST_COST 1
#define GNUNET_DV_MAX_COST -1
-
+/**
+ * Message that gets sent between nodes updating dv infos
+ */
typedef struct
{
GNUNET_MessageHeader header;
/**
- * Reserved (for alignment).
- */
- unsigned int reserved;
- // CG: you are not aligning here -- header is 4 bytes!
-
- /**
* Cost from received from node to neighbor node, takes distance into account
*/
unsigned int cost;
@@ -55,26 +51,40 @@
} p2p_dv_MESSAGE_NeighborInfo;
-// CG: not sure any of these prototypes should live
-// here; you need to add comments
-// describing the functions and arguments
-// name all arguments in prototypes, even
-// if C does not require you to do so.
-struct GNUNET_dv_neighbor *findNeighbor (const GNUNET_PeerIdentity *, short);
+/*
+ * Struct where actual neighbor information is stored,
+ * referenced by min_heap and max_heap. Freeing dealt
+ * with when items removed from hashmap.
+ */
+struct GNUNET_dv_neighbor
+{
+ /*
+ * Back-pointer location in min heap
+ */
+ struct GNUNET_dv_heap_node *min_loc;
-// CG: NEVER EVER put a "static" function
-// prototype into any header anywhere!
-static int
-addUpdateNeighbor (const GNUNET_PeerIdentity *, const GNUNET_PeerIdentity *,
- unsigned int);
+ /*
+ * Back-pointer location in max heap
+ */
+ struct GNUNET_dv_heap_node *max_loc;
-static void initialAddNeighbor (const GNUNET_PeerIdentity *, void *);
+ /**
+ * Identity of neighbor
+ */
+ GNUNET_PeerIdentity *neighbor;
-// CG: If a prototype has no arguments, put "void"
-struct GNUNET_dv_neighbor *chooseToNeighbor ();
+ /**
+ * Identity of referrer (where we got the information)
+ */
+ GNUNET_PeerIdentity *referrer;
-struct GNUNET_dv_neighbor *chooseAboutNeighbor ();
+ /**
+ * Cost to neighbor, used for actual distance vector computations
+ */
+ unsigned int cost;
+};
+
#endif
/* end of dv.h */
Modified: GNUnet/src/include/gnunet_util_containers.h
===================================================================
--- GNUnet/src/include/gnunet_util_containers.h 2008-12-14 00:36:20 UTC (rev
8000)
+++ GNUnet/src/include/gnunet_util_containers.h 2008-12-14 00:45:04 UTC (rev
8001)
@@ -346,14 +346,14 @@
{
/**
* If a value with the given key exists, replace it.
- * Note that the old value would NOT be freed
+ * 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.
+ * Allow multiple values with the same key.
*/
GNUNET_MultiHashMapOption_MULTIPLE,
@@ -366,7 +366,7 @@
/**
* There must only be one value per key, but don't
- * bother checking if a value already exists
+ * 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).
@@ -448,7 +448,7 @@
/**
* 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,
@@ -466,7 +466,7 @@
* @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
+ * GNUNET_SYSERR if UNIQUE_ONLY was the option and the
* value already exists
*/
int GNUNET_multi_hash_map_put (struct GNUNET_MultiHashMap *map,
@@ -512,8 +512,15 @@
const GNUNET_HashCode * key,
GNUNET_HashMapIterator iterator,
void *cls);
+/**
+ * Returns the stored value of a random non-null entry
+ * in the hash table. Returns only the first value, does
+ * not go inside bucket linked list (yet). Runs with a
+ * worst case time of N, so it's not efficient in any way
+ * shape or form!!!!.
+ */
+void * GNUNET_multi_hash_map_get_random (const struct GNUNET_MultiHashMap
*map);
-
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
Modified: GNUnet/src/util/containers/multihashmap.c
===================================================================
--- GNUnet/src/util/containers/multihashmap.c 2008-12-14 00:36:20 UTC (rev
8000)
+++ GNUnet/src/util/containers/multihashmap.c 2008-12-14 00:45:04 UTC (rev
8001)
@@ -117,8 +117,7 @@
e = map->map[i];
while (e != NULL)
{
- if ( (NULL != it) &&
- (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;
@@ -287,19 +286,35 @@
e = map->map[idx_of (map, key)];
while (e != NULL)
{
- if (0 == memcmp(key,
- &e->key,
- sizeof(GNUNET_HashCode)))
- {
- if ( (it != NULL) &&
- (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;
}
+void *
+GNUNET_multi_hash_map_get_random (const struct GNUNET_MultiHashMap *map)
+{
+ unsigned int rand;
+ struct MapEntry *e;
+ e = NULL;
+ if (map->size == 0)
+ return NULL;
+
+ while(e == NULL)
+ {
+ rand = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK,
+ map->size);
+ e = map->map[rand];
+ }
+
+ return e->value;
+}
+
/* end of multihashmap.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8001 - in GNUnet/src: include util/containers,
gnunet <=