[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8002 - GNUnet/src/applications/dv/module
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8002 - GNUnet/src/applications/dv/module |
Date: |
Sat, 13 Dec 2008 18:01:16 -0700 (MST) |
Author: nevans
Date: 2008-12-13 18:01:16 -0700 (Sat, 13 Dec 2008)
New Revision: 8002
Modified:
GNUnet/src/applications/dv/module/dv.c
GNUnet/src/applications/dv/module/heap.c
GNUnet/src/applications/dv/module/heap.h
GNUnet/src/applications/dv/module/heaptest.c
Log:
pre-commit, i always forget
Modified: GNUnet/src/applications/dv/module/dv.c
===================================================================
--- GNUnet/src/applications/dv/module/dv.c 2008-12-14 00:45:04 UTC (rev
8001)
+++ GNUnet/src/applications/dv/module/dv.c 2008-12-14 01:01:16 UTC (rev
8002)
@@ -63,28 +63,31 @@
// other C source files (or used with dlsym),'
// make sure all of your functions are declared "static"
static int
-printTableEntry (const GNUNET_HashCode * key,
- void *value, void *cls)
+printTableEntry (const GNUNET_HashCode * key, void *value, void *cls)
{
- struct GNUNET_dv_neighbor *neighbor = (struct GNUNET_dv_neighbor *)value;
- char *type = (char *)cls;
+ struct GNUNET_dv_neighbor *neighbor = (struct GNUNET_dv_neighbor *) value;
+ char *type = (char *) cls;
GNUNET_EncName encPeer;
GNUNET_hash_to_enc (&neighbor->referrer->hashPubKey, &encPeer);
- fprintf (stderr, "%s\tNeighbor: %s\nCost: %d",type, (char *) &encPeer,
neighbor->cost);
+ fprintf (stderr, "%s\tNeighbor: %s\nCost: %d", type, (char *) &encPeer,
+ neighbor->cost);
- return GNUNET_OK;
+ return GNUNET_OK;
}
-static void print_tables()
+static void
+print_tables ()
{
fprintf (stderr, "Printing directly connected neighbors:\n");
- GNUNET_multi_hash_map_iterate(ctx->direct_neighbors, &printTableEntry,
"DIRECT");
+ GNUNET_multi_hash_map_iterate (ctx->direct_neighbors, &printTableEntry,
+ "DIRECT");
- fprintf (stderr, "Printing extended neighbors:\n");
- GNUNET_multi_hash_map_iterate(ctx->extended_neighbors,
&printTableEntry, "EXTENDED");
+ fprintf (stderr, "Printing extended neighbors:\n");
+ GNUNET_multi_hash_map_iterate (ctx->extended_neighbors, &printTableEntry,
+ "EXTENDED");
- return;
+ return;
}
/*
@@ -116,80 +119,90 @@
#ifdef DEBUG_DV
GNUNET_EncName encPeer;
- fprintf (stderr, "Entering addUpdateNeighbor\n");
- if (referrer == NULL)
- fprintf (stderr, "Referrer is NULL\n");
+ fprintf (stderr, "Entering addUpdateNeighbor\n");
+ if (referrer == NULL)
+ fprintf (stderr, "Referrer is NULL\n");
GNUNET_hash_to_enc (&peer->hashPubKey, &encPeer);
fprintf (stderr, "Adding/Updating Node %s\n", (char *) &encPeer);
#endif
ret = GNUNET_OK;
- GNUNET_mutex_lock(ctx->dvMutex);
+ GNUNET_mutex_lock (ctx->dvMutex);
- if (GNUNET_YES !=
GNUNET_multi_hash_map_contains(ctx->extended_neighbors,&peer->hashPubKey))
- {
- neighbor = GNUNET_malloc(sizeof (struct GNUNET_dv_neighbor));
- neighbor->cost = cost;
- neighbor->neighbor = GNUNET_malloc(sizeof(GNUNET_PeerIdentity));
- memcpy(neighbor->neighbor,peer,sizeof(GNUNET_PeerIdentity));
- GNUNET_multi_hash_map_put
(ctx->extended_neighbors,&peer->hashPubKey,
-
neighbor,
-
GNUNET_MultiHashMapOption_REPLACE);
+ if (GNUNET_YES !=
+ GNUNET_multi_hash_map_contains (ctx->extended_neighbors,
+ &peer->hashPubKey))
+ {
+ neighbor = GNUNET_malloc (sizeof (struct GNUNET_dv_neighbor));
+ neighbor->cost = cost;
+ neighbor->neighbor = GNUNET_malloc (sizeof (GNUNET_PeerIdentity));
+ memcpy (neighbor->neighbor, peer, sizeof (GNUNET_PeerIdentity));
+ GNUNET_multi_hash_map_put (ctx->extended_neighbors, &peer->hashPubKey,
+ neighbor, GNUNET_MultiHashMapOption_REPLACE);
- GNUNET_DV_Heap_insert(&ctx->neighbor_max_heap, neighbor);
- GNUNET_DV_Heap_insert(&ctx->neighbor_min_heap, neighbor);
+ GNUNET_DV_Heap_insert (&ctx->neighbor_max_heap, neighbor);
+ GNUNET_DV_Heap_insert (&ctx->neighbor_min_heap, neighbor);
- }
- else
- {
- neighbor =
GNUNET_multi_hash_map_get(ctx->extended_neighbors,&peer->hashPubKey);
+ }
+ else
+ {
+ neighbor =
+ GNUNET_multi_hash_map_get (ctx->extended_neighbors,
+ &peer->hashPubKey);
- if (neighbor->cost > cost)
- {
- if (memcmp(neighbor->referrer, peer,
sizeof(GNUNET_PeerIdentity)) == 0)
- {
- neighbor->cost = cost;
-
GNUNET_DV_Heap_updatedCost(&ctx->neighbor_max_heap, neighbor);
-
GNUNET_DV_Heap_updatedCost(&ctx->neighbor_min_heap, neighbor);
- }
- else
- {
-
GNUNET_DV_Heap_removeNode(&ctx->neighbor_max_heap, neighbor);
-
GNUNET_DV_Heap_removeNode(&ctx->neighbor_min_heap, neighbor);
- GNUNET_free(neighbor->neighbor);
- GNUNET_free(neighbor->referrer);
- GNUNET_free(neighbor);
+ if (neighbor->cost > cost)
+ {
+ if (memcmp (neighbor->referrer, peer, sizeof (GNUNET_PeerIdentity))
+ == 0)
+ {
+ neighbor->cost = cost;
+ GNUNET_DV_Heap_updatedCost (&ctx->neighbor_max_heap, neighbor);
+ GNUNET_DV_Heap_updatedCost (&ctx->neighbor_min_heap, neighbor);
+ }
+ else
+ {
+ GNUNET_DV_Heap_removeNode (&ctx->neighbor_max_heap, neighbor);
+ GNUNET_DV_Heap_removeNode (&ctx->neighbor_min_heap, neighbor);
+ GNUNET_free (neighbor->neighbor);
+ GNUNET_free (neighbor->referrer);
+ GNUNET_free (neighbor);
- neighbor = GNUNET_malloc(sizeof (struct
GNUNET_dv_neighbor));
- neighbor->cost = cost;
- neighbor->neighbor =
GNUNET_malloc(sizeof(GNUNET_PeerIdentity));
-
memcpy(neighbor->neighbor,peer,sizeof(GNUNET_PeerIdentity));
- if (referrer == NULL)
- neighbor->referrer = NULL;
- else
- memcpy(neighbor->referrer, referrer,
sizeof(GNUNET_PeerIdentity));
+ neighbor = GNUNET_malloc (sizeof (struct GNUNET_dv_neighbor));
+ neighbor->cost = cost;
+ neighbor->neighbor =
+ GNUNET_malloc (sizeof (GNUNET_PeerIdentity));
+ memcpy (neighbor->neighbor, peer, sizeof (GNUNET_PeerIdentity));
+ if (referrer == NULL)
+ neighbor->referrer = NULL;
+ else
+ memcpy (neighbor->referrer, referrer,
+ sizeof (GNUNET_PeerIdentity));
- GNUNET_multi_hash_map_put
(ctx->extended_neighbors,&peer->hashPubKey,
-
neighbor,
-
GNUNET_MultiHashMapOption_REPLACE);
+ GNUNET_multi_hash_map_put (ctx->extended_neighbors,
+ &peer->hashPubKey, neighbor,
+ GNUNET_MultiHashMapOption_REPLACE);
- GNUNET_DV_Heap_insert(&ctx->neighbor_max_heap,
neighbor);
- GNUNET_DV_Heap_insert(&ctx->neighbor_min_heap,
neighbor);
- }
- }
- else if ((neighbor->cost < cost) && (memcmp(neighbor->referrer,
referrer, sizeof(GNUNET_PeerIdentity)) == 0))
- {
- neighbor->cost = cost;
+ GNUNET_DV_Heap_insert (&ctx->neighbor_max_heap, neighbor);
+ GNUNET_DV_Heap_insert (&ctx->neighbor_min_heap, neighbor);
+ }
+ }
+ else if ((neighbor->cost < cost)
+ &&
+ (memcmp
+ (neighbor->referrer, referrer,
+ sizeof (GNUNET_PeerIdentity)) == 0))
+ {
+ neighbor->cost = cost;
- GNUNET_DV_Heap_updatedCost(&ctx->neighbor_max_heap,
neighbor);
- GNUNET_DV_Heap_updatedCost(&ctx->neighbor_min_heap,
neighbor);
+ GNUNET_DV_Heap_updatedCost (&ctx->neighbor_max_heap, neighbor);
+ GNUNET_DV_Heap_updatedCost (&ctx->neighbor_min_heap, neighbor);
- }
+ }
- }
+ }
#ifdef DEBUG_DV
- print_tables();
+ print_tables ();
fprintf (stderr, "Exiting addUpdateNeighbor\n");
#endif
@@ -242,44 +255,46 @@
{
#ifdef DEBUG_DV
fprintf (stderr, "Entering peer_connect_handler:\n");
- print_tables();
+ print_tables ();
#endif
- struct GNUNET_dv_neighbor *neighbor;
- unsigned int cost = GNUNET_DV_LEAST_COST;
+ struct GNUNET_dv_neighbor *neighbor;
+ unsigned int cost = GNUNET_DV_LEAST_COST;
- if (GNUNET_YES !=
GNUNET_multi_hash_map_contains(ctx->direct_neighbors,&peer->hashPubKey))
- {
- neighbor = GNUNET_malloc(sizeof (struct GNUNET_dv_neighbor));
- neighbor->cost = cost;
- neighbor->neighbor = GNUNET_malloc(sizeof(GNUNET_PeerIdentity));
- memcpy(neighbor->neighbor,peer, sizeof(GNUNET_PeerIdentity));
- GNUNET_multi_hash_map_put
(ctx->direct_neighbors,&peer->hashPubKey,
-
neighbor,
-
GNUNET_MultiHashMapOption_REPLACE);
- }
- else
- {
- neighbor =
GNUNET_multi_hash_map_get(ctx->direct_neighbors,&peer->hashPubKey);
+ if (GNUNET_YES !=
+ GNUNET_multi_hash_map_contains (ctx->direct_neighbors,
+ &peer->hashPubKey))
+ {
+ neighbor = GNUNET_malloc (sizeof (struct GNUNET_dv_neighbor));
+ neighbor->cost = cost;
+ neighbor->neighbor = GNUNET_malloc (sizeof (GNUNET_PeerIdentity));
+ memcpy (neighbor->neighbor, peer, sizeof (GNUNET_PeerIdentity));
+ GNUNET_multi_hash_map_put (ctx->direct_neighbors, &peer->hashPubKey,
+ neighbor, GNUNET_MultiHashMapOption_REPLACE);
+ }
+ else
+ {
+ neighbor =
+ GNUNET_multi_hash_map_get (ctx->direct_neighbors, &peer->hashPubKey);
- if (neighbor->cost != cost)
- {
- GNUNET_mutex_lock(ctx->dvMutex);
- GNUNET_multi_hash_map_put
(ctx->direct_neighbors,&peer->hashPubKey,
-
neighbor,
-
GNUNET_MultiHashMapOption_REPLACE);
- GNUNET_mutex_unlock(ctx->dvMutex);
- }
+ if (neighbor->cost != cost)
+ {
+ GNUNET_mutex_lock (ctx->dvMutex);
+ GNUNET_multi_hash_map_put (ctx->direct_neighbors, &peer->hashPubKey,
+ neighbor,
+ GNUNET_MultiHashMapOption_REPLACE);
+ GNUNET_mutex_unlock (ctx->dvMutex);
+ }
- }
+ }
- addUpdateNeighbor(peer, NULL, cost);
+ addUpdateNeighbor (peer, NULL, cost);
#ifdef DEBUG_DV
- print_tables();
+ print_tables ();
#endif
- return;
+ return;
}
@@ -287,19 +302,21 @@
* May use as a callback for deleting nodes from heaps...
*/
static void
-delete_callback(struct GNUNET_dv_neighbor *neighbor, struct GNUNET_dv_heap
*root,GNUNET_PeerIdentity * toMatch)
+delete_callback (struct GNUNET_dv_neighbor *neighbor,
+ struct GNUNET_dv_heap *root, GNUNET_PeerIdentity * toMatch)
{
- if (memcmp(neighbor->referrer, toMatch, sizeof(GNUNET_PeerIdentity)) ==
0)
- {
- GNUNET_DV_Heap_removeNode(&ctx->neighbor_max_heap, neighbor);
- GNUNET_DV_Heap_removeNode(&ctx->neighbor_min_heap, neighbor);
- GNUNET_multi_hash_map_remove_all(ctx->extended_neighbors,
&neighbor->neighbor->hashPubKey);
+ if (memcmp (neighbor->referrer, toMatch, sizeof (GNUNET_PeerIdentity)) == 0)
+ {
+ GNUNET_DV_Heap_removeNode (&ctx->neighbor_max_heap, neighbor);
+ GNUNET_DV_Heap_removeNode (&ctx->neighbor_min_heap, neighbor);
+ GNUNET_multi_hash_map_remove_all (ctx->extended_neighbors,
+ &neighbor->neighbor->hashPubKey);
- GNUNET_free(neighbor->neighbor);
- GNUNET_free(neighbor->referrer);
- GNUNET_free(neighbor);
- }
- return;
+ GNUNET_free (neighbor->neighbor);
+ GNUNET_free (neighbor->referrer);
+ GNUNET_free (neighbor);
+ }
+ return;
}
/*
@@ -323,28 +340,33 @@
fprintf (stderr, "Entering peer_disconnect_handler\n");
GNUNET_hash_to_enc (&peer->hashPubKey, &myself);
fprintf (stderr, "disconnected peer: %s\n", (char *) &myself);
- print_tables();
+ print_tables ();
#endif
GNUNET_mutex_lock (ctx->dvMutex);
- if (GNUNET_YES == GNUNET_multi_hash_map_contains(ctx->direct_neighbors,
&peer->hashPubKey))
- {
- neighbor = GNUNET_multi_hash_map_get(ctx->direct_neighbors,
&peer->hashPubKey);
- if (neighbor != NULL)
- {
- GNUNET_multi_hash_map_remove_all(ctx->direct_neighbors,
&peer->hashPubKey);
+ if (GNUNET_YES ==
+ GNUNET_multi_hash_map_contains (ctx->direct_neighbors,
+ &peer->hashPubKey))
+ {
+ neighbor =
+ GNUNET_multi_hash_map_get (ctx->direct_neighbors, &peer->hashPubKey);
+ if (neighbor != NULL)
+ {
+ GNUNET_multi_hash_map_remove_all (ctx->direct_neighbors,
+ &peer->hashPubKey);
- GNUNET_DV_Heap_Iterator (&delete_callback,
&ctx->neighbor_max_heap, ctx->neighbor_max_heap.root, peer);
+ GNUNET_DV_Heap_Iterator (&delete_callback, &ctx->neighbor_max_heap,
+ ctx->neighbor_max_heap.root, peer);
- GNUNET_free(neighbor->neighbor);
- if (neighbor->referrer)
- GNUNET_free(neighbor->referrer);
+ GNUNET_free (neighbor->neighbor);
+ if (neighbor->referrer)
+ GNUNET_free (neighbor->referrer);
- GNUNET_free(neighbor);
+ GNUNET_free (neighbor);
- }
- }
+ }
+ }
GNUNET_mutex_unlock (ctx->dvMutex);
#ifdef DEBUG_DV
@@ -357,23 +379,25 @@
static struct GNUNET_dv_neighbor *
chooseToNeighbor ()
{
- if (GNUNET_multi_hash_map_size(ctx->direct_neighbors) == 0)
+ if (GNUNET_multi_hash_map_size (ctx->direct_neighbors) == 0)
return NULL;
- return (struct GNUNET_dv_neighbor
*)GNUNET_multi_hash_map_get_random(ctx->direct_neighbors);
+ return (struct GNUNET_dv_neighbor *) GNUNET_multi_hash_map_get_random (ctx->
+
direct_neighbors);
}
static struct GNUNET_dv_neighbor *
chooseAboutNeighbor ()
{
- if (ctx->neighbor_min_heap.size == 0)
+ if (ctx->neighbor_min_heap.size == 0)
return NULL;
#ifdef DEBUG_DV
- fprintf (stderr, "Min heap size %d\nMax heap size %d\n",
ctx->neighbor_min_heap.size,ctx->neighbor_max_heap.size);
+ fprintf (stderr, "Min heap size %d\nMax heap size %d\n",
+ ctx->neighbor_min_heap.size, ctx->neighbor_max_heap.size);
#endif
- return GNUNET_DV_Heap_Walk_getNext(&ctx->neighbor_min_heap);
+ return GNUNET_DV_Heap_Walk_getNext (&ctx->neighbor_min_heap);
}
@@ -416,7 +440,8 @@
memcpy (&message->neighbor, about->neighbor,
sizeof (GNUNET_PeerIdentity));
coreAPI->ciphertext_send (to->neighbor, &message->header, 0,
- ctx->send_interval *
GNUNET_CRON_MILLISECONDS);
+ ctx->send_interval *
+ GNUNET_CRON_MILLISECONDS);
}
GNUNET_thread_sleep (ctx->send_interval * GNUNET_CRON_MILLISECONDS);
@@ -475,20 +500,21 @@
0, -1, 100, &ctx->max_table_size);
GNUNET_GC_get_configuration_value_number (coreAPI->cfg,
-
"gnunetd","connection-max-hosts",1,-1,50,
- &max_hosts);
+ "gnunetd", "connection-max-hosts",
+ 1, -1, 50, &max_hosts);
ctx->direct_neighbors = GNUNET_multi_hash_map_create (max_hosts);
if (ctx->direct_neighbors == NULL)
- {
- ok = GNUNET_SYSERR;
- }
+ {
+ ok = GNUNET_SYSERR;
+ }
- ctx->extended_neighbors = GNUNET_multi_hash_map_create (ctx->max_table_size
* 3);
+ ctx->extended_neighbors =
+ GNUNET_multi_hash_map_create (ctx->max_table_size * 3);
if (ctx->extended_neighbors == NULL)
- {
- ok = GNUNET_SYSERR;
- }
+ {
+ ok = GNUNET_SYSERR;
+ }
GNUNET_GE_ASSERT (capi->ectx,
0 == GNUNET_GC_set_configuration_value_string (capi->cfg,
@@ -512,7 +538,7 @@
coreAPI->peer_disconnect_notification_unregister (&peer_disconnect_handler,
NULL);
coreAPI->peer_disconnect_notification_unregister (&peer_connect_handler,
- NULL);
+ NULL);
GNUNET_mutex_destroy (ctx->dvMutex);
coreAPI = NULL;
Modified: GNUnet/src/applications/dv/module/heap.c
===================================================================
--- GNUnet/src/applications/dv/module/heap.c 2008-12-14 00:45:04 UTC (rev
8001)
+++ GNUnet/src/applications/dv/module/heap.c 2008-12-14 01:01:16 UTC (rev
8002)
@@ -28,378 +28,412 @@
#include "dv.h"
#include "heap.h"
-void printTree(struct GNUNET_dv_heap_node *root)
+void
+printTree (struct GNUNET_dv_heap_node *root)
{
- if (root->neighbor != NULL)
- fprintf(stdout,"%d\n",root->neighbor->cost);
- if (root->left_child != NULL)
- printTree(root->left_child);
- if (root->right_child != NULL)
- printTree(root->right_child);
+ if (root->neighbor != NULL)
+ fprintf (stdout, "%d\n", root->neighbor->cost);
+ if (root->left_child != NULL)
+ printTree (root->left_child);
+ if (root->right_child != NULL)
+ printTree (root->right_child);
}
-static struct GNUNET_dv_heap_node *getNextPos(struct GNUNET_dv_heap *root)
+static struct GNUNET_dv_heap_node *
+getNextPos (struct GNUNET_dv_heap *root)
{
- struct GNUNET_dv_heap_node *ret;
- struct GNUNET_dv_heap_node *parent;
- int pos;
- int depth;
- int i;
+ struct GNUNET_dv_heap_node *ret;
+ struct GNUNET_dv_heap_node *parent;
+ int pos;
+ int depth;
+ int i;
- ret = malloc(sizeof(struct GNUNET_dv_heap_node));
- pos = root->size + 1;
- depth = (int)log2(pos);
- ret->left_child = NULL;
- ret->right_child = NULL;
+ ret = malloc (sizeof (struct GNUNET_dv_heap_node));
+ pos = root->size + 1;
+ depth = (int) log2 (pos);
+ ret->left_child = NULL;
+ ret->right_child = NULL;
- if (depth == 0)
- {
- ret->parent = NULL;
- root->root = ret;
- }
- else
- {
- parent = root->root;
- for (i=depth;i>1;i--)
- {
- if (((pos / (1 << (i-1))) % 2) == 0)
- parent = parent->left_child;
- else
- parent = parent->right_child;
- }
+ if (depth == 0)
+ {
+ ret->parent = NULL;
+ root->root = ret;
+ }
+ else
+ {
+ parent = root->root;
+ for (i = depth; i > 1; i--)
+ {
+ if (((pos / (1 << (i - 1))) % 2) == 0)
+ parent = parent->left_child;
+ else
+ parent = parent->right_child;
+ }
- ret->parent = parent;
- if ((pos % 2) == 0)
- parent->left_child = ret;
- else
- parent->right_child = ret;
+ ret->parent = parent;
+ if ((pos % 2) == 0)
+ parent->left_child = ret;
+ else
+ parent->right_child = ret;
- }
+ }
- return ret;
+ return ret;
}
static struct GNUNET_dv_heap_node *
-getPos(struct GNUNET_dv_heap *root,unsigned int pos)
+getPos (struct GNUNET_dv_heap *root, unsigned int pos)
{
- struct GNUNET_dv_heap_node *ret;
+ struct GNUNET_dv_heap_node *ret;
- int depth;
- int i;
+ int depth;
+ int i;
- depth = (int)log2(pos);
- ret = NULL;
- if (pos > root->size)
- {
- return ret;
- }
- else
- {
- ret = root->root;
- for (i=depth;i>0;i--)
- {
- if (((pos / (1 << (i-1))) % 2) == 0)
- ret = ret->left_child;
- else
- ret = ret->right_child;
- }
- }
+ depth = (int) log2 (pos);
+ ret = NULL;
+ if (pos > root->size)
+ {
+ return ret;
+ }
+ else
+ {
+ ret = root->root;
+ for (i = depth; i > 0; i--)
+ {
+ if (((pos / (1 << (i - 1))) % 2) == 0)
+ ret = ret->left_child;
+ else
+ ret = ret->right_child;
+ }
+ }
- return ret;
+ return ret;
}
void
-swapNodes(struct GNUNET_dv_heap_node *first, struct GNUNET_dv_heap_node
*second, struct GNUNET_dv_heap *root)
+swapNodes (struct GNUNET_dv_heap_node *first,
+ struct GNUNET_dv_heap_node *second, struct GNUNET_dv_heap *root)
{
- struct GNUNET_dv_neighbor *tempNeighbor;
+ struct GNUNET_dv_neighbor *tempNeighbor;
- tempNeighbor = first->neighbor;
- first->neighbor = second->neighbor;
- second->neighbor = tempNeighbor;
+ tempNeighbor = first->neighbor;
+ first->neighbor = second->neighbor;
+ second->neighbor = tempNeighbor;
- if ((root->type == GNUNET_DV_MAX_HEAP))
- {
- first->neighbor->max_loc = first;
- second->neighbor->max_loc = second;
- }
- else if ((root->type == GNUNET_DV_MAX_HEAP))
- {
- first->neighbor->min_loc = first;
- second->neighbor->min_loc = second;
- }
+ if ((root->type == GNUNET_DV_MAX_HEAP))
+ {
+ first->neighbor->max_loc = first;
+ second->neighbor->max_loc = second;
+ }
+ else if ((root->type == GNUNET_DV_MAX_HEAP))
+ {
+ first->neighbor->min_loc = first;
+ second->neighbor->min_loc = second;
+ }
- return;
+ return;
}
void
-percolateHeap(struct GNUNET_dv_heap_node *pos, struct GNUNET_dv_heap *root)
+percolateHeap (struct GNUNET_dv_heap_node *pos, struct GNUNET_dv_heap *root)
{
- while((pos->parent != NULL) &&
- (((root->type == GNUNET_DV_MAX_HEAP) &&
(pos->parent->neighbor->cost < pos->neighbor->cost)) ||
- ((root->type == GNUNET_DV_MIN_HEAP) &&
(pos->parent->neighbor->cost > pos->neighbor->cost))))
- {
- swapNodes(pos,pos->parent,root);
- pos = pos->parent;
- }
+ while ((pos->parent != NULL) &&
+ (((root->type == GNUNET_DV_MAX_HEAP)
+ && (pos->parent->neighbor->cost < pos->neighbor->cost))
+ || ((root->type == GNUNET_DV_MIN_HEAP)
+ && (pos->parent->neighbor->cost > pos->neighbor->cost))))
+ {
+ swapNodes (pos, pos->parent, root);
+ pos = pos->parent;
+ }
- return;
+ return;
}
void
-percolateDownHeap(struct GNUNET_dv_heap_node *pos, struct GNUNET_dv_heap *root)
+percolateDownHeap (struct GNUNET_dv_heap_node *pos,
+ struct GNUNET_dv_heap *root)
{
- struct GNUNET_dv_heap_node *switchNeighbor;
+ struct GNUNET_dv_heap_node *switchNeighbor;
- switchNeighbor = pos;
+ switchNeighbor = pos;
- if ((root->type == GNUNET_DV_MAX_HEAP))
- {
- if ((pos->left_child != NULL) &&
(pos->left_child->neighbor->cost > switchNeighbor->neighbor->cost))
- {
- switchNeighbor = pos->left_child;
- }
+ if ((root->type == GNUNET_DV_MAX_HEAP))
+ {
+ if ((pos->left_child != NULL)
+ && (pos->left_child->neighbor->cost >
+ switchNeighbor->neighbor->cost))
+ {
+ switchNeighbor = pos->left_child;
+ }
- if ((pos->right_child != NULL) &&
(pos->right_child->neighbor->cost > switchNeighbor->neighbor->cost))
- {
- switchNeighbor = pos->right_child;
- }
- }
- else if ((root->type == GNUNET_DV_MIN_HEAP))
- {
- if ((pos->left_child != NULL) &&
(pos->left_child->neighbor->cost < switchNeighbor->neighbor->cost))
- {
- switchNeighbor = pos->left_child;
- }
+ if ((pos->right_child != NULL)
+ && (pos->right_child->neighbor->cost >
+ switchNeighbor->neighbor->cost))
+ {
+ switchNeighbor = pos->right_child;
+ }
+ }
+ else if ((root->type == GNUNET_DV_MIN_HEAP))
+ {
+ if ((pos->left_child != NULL)
+ && (pos->left_child->neighbor->cost <
+ switchNeighbor->neighbor->cost))
+ {
+ switchNeighbor = pos->left_child;
+ }
- if ((pos->right_child != NULL) &&
(pos->right_child->neighbor->cost < switchNeighbor->neighbor->cost))
- {
- switchNeighbor = pos->right_child;
- }
- }
+ if ((pos->right_child != NULL)
+ && (pos->right_child->neighbor->cost <
+ switchNeighbor->neighbor->cost))
+ {
+ switchNeighbor = pos->right_child;
+ }
+ }
- if (switchNeighbor != pos)
- {
- swapNodes(switchNeighbor,pos,root);
- percolateDownHeap(switchNeighbor,root);
- }
+ if (switchNeighbor != pos)
+ {
+ swapNodes (switchNeighbor, pos, root);
+ percolateDownHeap (switchNeighbor, root);
+ }
- return;
+ return;
}
int
-GNUNET_DV_Heap_insert(struct GNUNET_dv_heap *root, struct GNUNET_dv_neighbor
*neighbor)
+GNUNET_DV_Heap_insert (struct GNUNET_dv_heap *root,
+ struct GNUNET_dv_neighbor *neighbor)
{
- struct GNUNET_dv_heap_node *new_pos;
- int ret;
- ret = GNUNET_YES;
+ struct GNUNET_dv_heap_node *new_pos;
+ int ret;
+ ret = GNUNET_YES;
- if (root->max_size > root->size)
- {
- new_pos = getNextPos(root);
- new_pos->neighbor = neighbor;
- root->size++;
- percolateHeap(new_pos,root);
- }
- else
- {
- ret = GNUNET_NO;
- }
+ if (root->max_size > root->size)
+ {
+ new_pos = getNextPos (root);
+ new_pos->neighbor = neighbor;
+ root->size++;
+ percolateHeap (new_pos, root);
+ }
+ else
+ {
+ ret = GNUNET_NO;
+ }
- return ret;
+ return ret;
}
struct GNUNET_dv_neighbor *
-GNUNET_DV_Heap_removeRoot(struct GNUNET_dv_heap *root)
+GNUNET_DV_Heap_removeRoot (struct GNUNET_dv_heap *root)
{
- struct GNUNET_dv_neighbor *ret;
- struct GNUNET_dv_heap_node *root_node;
- struct GNUNET_dv_heap_node *last;
+ struct GNUNET_dv_neighbor *ret;
+ struct GNUNET_dv_heap_node *root_node;
+ struct GNUNET_dv_heap_node *last;
- root_node = root->root;
- ret = root_node->neighbor;
- last = getPos(root,root->size);
+ root_node = root->root;
+ ret = root_node->neighbor;
+ last = getPos (root, root->size);
- if (last->parent->left_child == last)
- last->parent->left_child = NULL;
- else if (last->parent->right_child == last)
- last->parent->right_child = NULL;
+ if (last->parent->left_child == last)
+ last->parent->left_child = NULL;
+ else if (last->parent->right_child == last)
+ last->parent->right_child = NULL;
- root_node->neighbor = last->neighbor;
+ root_node->neighbor = last->neighbor;
- if (root->traversal_pos == last)
- {
- root->traversal_pos = root->root;
- }
+ if (root->traversal_pos == last)
+ {
+ root->traversal_pos = root->root;
+ }
- GNUNET_free(last);
- root->size--;
- percolateDownHeap(root->root,root);
- return ret;
+ GNUNET_free (last);
+ root->size--;
+ percolateDownHeap (root->root, root);
+ return ret;
}
struct GNUNET_dv_neighbor *
-GNUNET_DV_Heap_removeNode(struct GNUNET_dv_heap *root, struct
GNUNET_dv_neighbor *neighbor)
+GNUNET_DV_Heap_removeNode (struct GNUNET_dv_heap *root,
+ struct GNUNET_dv_neighbor *neighbor)
{
- struct GNUNET_dv_neighbor *ret;
- struct GNUNET_dv_heap_node *del_node;
- struct GNUNET_dv_heap_node *last;
+ struct GNUNET_dv_neighbor *ret;
+ struct GNUNET_dv_heap_node *del_node;
+ struct GNUNET_dv_heap_node *last;
- if (root->type == GNUNET_DV_MAX_HEAP)
- del_node = neighbor->max_loc;
- else if (root->type == GNUNET_DV_MIN_HEAP)
- del_node = neighbor->min_loc;
+ if (root->type == GNUNET_DV_MAX_HEAP)
+ del_node = neighbor->max_loc;
+ else if (root->type == GNUNET_DV_MIN_HEAP)
+ del_node = neighbor->min_loc;
- if (del_node == NULL)
- return NULL;
+ if (del_node == NULL)
+ return NULL;
- ret = del_node->neighbor;
- last = getPos(root,root->size);
- del_node->neighbor = last->neighbor;
+ ret = del_node->neighbor;
+ last = getPos (root, root->size);
+ del_node->neighbor = last->neighbor;
- if (last->parent->left_child == last)
- last->parent->left_child = NULL;
- if (last->parent->right_child == last)
- last->parent->right_child = NULL;
+ if (last->parent->left_child == last)
+ last->parent->left_child = NULL;
+ if (last->parent->right_child == last)
+ last->parent->right_child = NULL;
- if (root->traversal_pos == last)
- {
- root->traversal_pos = root->root;
- }
- GNUNET_free(last);
- root->size--;
+ if (root->traversal_pos == last)
+ {
+ root->traversal_pos = root->root;
+ }
+ GNUNET_free (last);
+ root->size--;
- if (del_node->neighbor->cost > ret->cost)
- {
- if (root->type == GNUNET_DV_MAX_HEAP)
- percolateHeap(del_node, root);
- else if (root->type == GNUNET_DV_MIN_HEAP)
- percolateDownHeap(del_node, root);
- }
- else if (del_node->neighbor->cost < ret->cost)
- {
- if (root->type == GNUNET_DV_MAX_HEAP)
- percolateDownHeap(del_node, root);
- else if (root->type == GNUNET_DV_MIN_HEAP)
- percolateHeap(del_node, root);
- }
+ if (del_node->neighbor->cost > ret->cost)
+ {
+ if (root->type == GNUNET_DV_MAX_HEAP)
+ percolateHeap (del_node, root);
+ else if (root->type == GNUNET_DV_MIN_HEAP)
+ percolateDownHeap (del_node, root);
+ }
+ else if (del_node->neighbor->cost < ret->cost)
+ {
+ if (root->type == GNUNET_DV_MAX_HEAP)
+ percolateDownHeap (del_node, root);
+ else if (root->type == GNUNET_DV_MIN_HEAP)
+ percolateHeap (del_node, root);
+ }
- return ret;
+ return ret;
}
int
-GNUNET_DV_Heap_updateCost(struct GNUNET_dv_heap *root, struct
GNUNET_dv_neighbor *neighbor, unsigned int new_cost)
+GNUNET_DV_Heap_updateCost (struct GNUNET_dv_heap *root,
+ struct GNUNET_dv_neighbor *neighbor,
+ unsigned int new_cost)
{
- int ret = GNUNET_YES;
- neighbor->cost = new_cost;
+ int ret = GNUNET_YES;
+ neighbor->cost = new_cost;
- ret = GNUNET_DV_Heap_updatedCost(root, neighbor);
- return ret;
+ ret = GNUNET_DV_Heap_updatedCost (root, neighbor);
+ return ret;
}
int
-GNUNET_DV_Heap_updatedCost(struct GNUNET_dv_heap *root, struct
GNUNET_dv_neighbor *neighbor)
+GNUNET_DV_Heap_updatedCost (struct GNUNET_dv_heap *root,
+ struct GNUNET_dv_neighbor *neighbor)
{
- struct GNUNET_dv_heap_node *node;
- struct GNUNET_dv_heap_node *parent;
- struct GNUNET_dv_heap_node *left_child;
- struct GNUNET_dv_heap_node *right_child;
+ struct GNUNET_dv_heap_node *node;
+ struct GNUNET_dv_heap_node *parent;
+ struct GNUNET_dv_heap_node *left_child;
+ struct GNUNET_dv_heap_node *right_child;
- if (neighbor == NULL)
- return GNUNET_SYSERR;
+ if (neighbor == NULL)
+ return GNUNET_SYSERR;
- if ((root->type == GNUNET_DV_MAX_HEAP) && (neighbor->max_loc != NULL))
- {
- node = neighbor->max_loc;
- }
- else if ((root->type == GNUNET_DV_MIN_HEAP) && (neighbor->min_loc !=
NULL))
- {
- node = neighbor->min_loc;
- }
- else
- return GNUNET_SYSERR;
+ if ((root->type == GNUNET_DV_MAX_HEAP) && (neighbor->max_loc != NULL))
+ {
+ node = neighbor->max_loc;
+ }
+ else if ((root->type == GNUNET_DV_MIN_HEAP) && (neighbor->min_loc != NULL))
+ {
+ node = neighbor->min_loc;
+ }
+ else
+ return GNUNET_SYSERR;
- parent = node->parent;
+ parent = node->parent;
- if ((root->type == GNUNET_DV_MAX_HEAP) && (parent != NULL) &&
(node->neighbor->cost > parent->neighbor->cost))
- percolateHeap(neighbor->max_loc, root);
- else if ((root->type == GNUNET_DV_MIN_HEAP) && (parent != NULL) &&
(node->neighbor->cost < parent->neighbor->cost))
- percolateHeap(neighbor->min_loc,root);
- else if (root->type == GNUNET_DV_MAX_HEAP)
- percolateDownHeap(neighbor->max_loc, root);
- else if (root->type == GNUNET_DV_MIN_HEAP)
- percolateDownHeap(neighbor->min_loc, root);
+ if ((root->type == GNUNET_DV_MAX_HEAP) && (parent != NULL)
+ && (node->neighbor->cost > parent->neighbor->cost))
+ percolateHeap (neighbor->max_loc, root);
+ else if ((root->type == GNUNET_DV_MIN_HEAP) && (parent != NULL)
+ && (node->neighbor->cost < parent->neighbor->cost))
+ percolateHeap (neighbor->min_loc, root);
+ else if (root->type == GNUNET_DV_MAX_HEAP)
+ percolateDownHeap (neighbor->max_loc, root);
+ else if (root->type == GNUNET_DV_MIN_HEAP)
+ percolateDownHeap (neighbor->min_loc, root);
- return GNUNET_YES;
+ return GNUNET_YES;
}
int
-GNUNET_DV_Heap_delete_matching_referrers(struct GNUNET_dv_heap *root, struct
GNUNET_dv_heap_node *node, GNUNET_PeerIdentity *toMatch)
+GNUNET_DV_Heap_delete_matching_referrers (struct GNUNET_dv_heap *root,
+ struct GNUNET_dv_heap_node *node,
+ GNUNET_PeerIdentity * toMatch)
{
- if (node->left_child != NULL)
- {
- GNUNET_DV_Heap_delete_matching_referrers(root,
node->left_child, toMatch);
- }
- if (node->right_child != NULL)
- {
- GNUNET_DV_Heap_delete_matching_referrers(root,
node->right_child, toMatch);
- }
- if ((node->neighbor != NULL) && (memcmp(node->neighbor, toMatch,
sizeof(struct GNUNET_PeerIdentity)) == 0))
- {
- GNUNET_DV_removeNode(root, node->neighbor);
- }
+ if (node->left_child != NULL)
+ {
+ GNUNET_DV_Heap_delete_matching_referrers (root, node->left_child,
+ toMatch);
+ }
+ if (node->right_child != NULL)
+ {
+ GNUNET_DV_Heap_delete_matching_referrers (root, node->right_child,
+ toMatch);
+ }
+ if ((node->neighbor != NULL)
+ &&
+ (memcmp (node->neighbor, toMatch, sizeof (struct GNUNET_PeerIdentity))
+ == 0))
+ {
+ GNUNET_DV_removeNode (root, node->neighbor);
+ }
}
void
-GNUNET_DV_Heap_Iterator (void (*callee)(struct GNUNET_dv_neighbor *neighbor,
struct GNUNET_dv_heap *root, GNUNET_PeerIdentity *toMatch), struct
GNUNET_dv_heap *root, struct GNUNET_dv_heap_node *node,const
GNUNET_PeerIdentity *toMatch)
+GNUNET_DV_Heap_Iterator (void (*callee)
+ (struct GNUNET_dv_neighbor * neighbor,
+ struct GNUNET_dv_heap * root,
+ GNUNET_PeerIdentity * toMatch),
+ struct GNUNET_dv_heap *root,
+ struct GNUNET_dv_heap_node *node,
+ const GNUNET_PeerIdentity * toMatch)
{
- if (node->left_child != NULL)
- {
- GNUNET_DV_Heap_Iterator(callee, root, node->left_child,
toMatch);
- }
+ if (node->left_child != NULL)
+ {
+ GNUNET_DV_Heap_Iterator (callee, root, node->left_child, toMatch);
+ }
- if (node->right_child != NULL)
- {
- GNUNET_DV_Heap_Iterator(callee, root,
node->right_child,toMatch);
- }
+ if (node->right_child != NULL)
+ {
+ GNUNET_DV_Heap_Iterator (callee, root, node->right_child, toMatch);
+ }
- if (node->neighbor != NULL)
- {
- callee(node->neighbor, root);
- }
+ if (node->neighbor != NULL)
+ {
+ callee (node->neighbor, root);
+ }
}
struct GNUNET_dv_neighbor *
GNUNET_DV_Heap_Walk_getNext (struct GNUNET_dv_heap *root)
{
- unsigned int choice;
- struct GNUNET_dv_neighbor *neighbor;
+ unsigned int choice;
+ struct GNUNET_dv_neighbor *neighbor;
- if ((root->traversal_pos == NULL) && (root->root != NULL))
- {
- root->traversal_pos = root->root;
- }
+ if ((root->traversal_pos == NULL) && (root->root != NULL))
+ {
+ root->traversal_pos = root->root;
+ }
- if (root->traversal_pos == NULL)
- return NULL;
+ if (root->traversal_pos == NULL)
+ return NULL;
- neighbor = root->traversal_pos->neighbor;
+ neighbor = root->traversal_pos->neighbor;
- choice = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 1);
+ choice = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 1);
- switch (choice)
- case 1:
- root->traversal_pos = root->traversal_pos->right_child;
- case 0:
- root->traversal_pos = root->traversal_pos->left_child;
+ switch (choice)
+ case 1:
+ root->traversal_pos = root->traversal_pos->right_child;
+case 0:
+ root->traversal_pos = root->traversal_pos->left_child;
- return neighbor;
+ return neighbor;
}
Modified: GNUnet/src/applications/dv/module/heap.h
===================================================================
--- GNUnet/src/applications/dv/module/heap.h 2008-12-14 00:45:04 UTC (rev
8001)
+++ GNUnet/src/applications/dv/module/heap.h 2008-12-14 01:01:16 UTC (rev
8002)
@@ -45,9 +45,9 @@
*/
struct GNUNET_dv_heap_info
{
- struct GNUNET_dv_heap_node *min_loc;
+ struct GNUNET_dv_heap_node *min_loc;
- struct GNUNET_dv_heap_node *max_loc;
+ struct GNUNET_dv_heap_node *max_loc;
};
@@ -58,15 +58,15 @@
*/
struct GNUNET_dv_heap
{
- unsigned int size;
+ unsigned int size;
- unsigned int max_size;
+ unsigned int max_size;
- GNUNET_DV_HeapType type;
+ GNUNET_DV_HeapType type;
- struct GNUNET_dv_heap_node *root;
+ struct GNUNET_dv_heap_node *root;
- struct GNUNET_dv_heap_node *traversal_pos;
+ struct GNUNET_dv_heap_node *traversal_pos;
};
@@ -76,13 +76,13 @@
*/
struct GNUNET_dv_heap_node
{
- struct GNUNET_dv_heap_node *parent;
+ struct GNUNET_dv_heap_node *parent;
- struct GNUNET_dv_heap_node *left_child;
+ struct GNUNET_dv_heap_node *left_child;
- struct GNUNET_dv_heap_node *right_child;
+ struct GNUNET_dv_heap_node *right_child;
- struct GNUNET_dv_neighbor *neighbor;
+ struct GNUNET_dv_neighbor *neighbor;
};
@@ -114,58 +114,70 @@
* GNUNET_SYSERR if there's a problem
*/
int GNUNET_DV_heap_iterate (const struct GNUNET_dv_heap *heap,
- GNUNET_HeapIterator iterator,
- void *cls);
+ GNUNET_HeapIterator iterator, void *cls);
/**
* Simple stupid tree print. Prints in depth first order.
*/
-void printTree(struct GNUNET_dv_heap_node *root);
+void printTree (struct GNUNET_dv_heap_node *root);
/**
* Inserts a new item into the heap, item is always neighbor now.
*/
int
-GNUNET_DV_Heap_insert(struct GNUNET_dv_heap *root, struct GNUNET_dv_neighbor
*neighbor);
+GNUNET_DV_Heap_insert (struct GNUNET_dv_heap *root,
+ struct GNUNET_dv_neighbor *neighbor);
/**
* Removes root of the tree, is remove max if a max heap and remove min
* if a min heap, returns the data stored at the node.
*/
-struct GNUNET_dv_neighbor *
-GNUNET_DV_Heap_removeRoot(struct GNUNET_dv_heap *root);
+struct GNUNET_dv_neighbor *GNUNET_DV_Heap_removeRoot (struct GNUNET_dv_heap
+ *root);
/**
* Returns data stored at root of tree, doesn't affect anything
*/
-struct GNUNET_dv_neighbor *
-GNUNET_DV_Heap_peekRoot(struct GNUNET_dv_heap *root);
+struct GNUNET_dv_neighbor *GNUNET_DV_Heap_peekRoot (struct GNUNET_dv_heap
+ *root);
/**
* Removes any node from the tree based on the neighbor given, does
* not traverse the tree (backpointers) but may take more time due to
* percolation of nodes.
*/
-struct GNUNET_dv_neighbor *
-GNUNET_DV_Heap_removeNode(struct GNUNET_dv_heap *root, struct
GNUNET_dv_neighbor *neighbor);
+struct GNUNET_dv_neighbor *GNUNET_DV_Heap_removeNode (struct GNUNET_dv_heap
+ *root,
+ struct
+ GNUNET_dv_neighbor
+ *neighbor);
/**
* Updates the cost of any node in the tree
*/
int
-GNUNET_DV_Heap_updateCost(struct GNUNET_dv_heap *root, struct
GNUNET_dv_neighbor *neighbor, unsigned int new_cost);
+GNUNET_DV_Heap_updateCost (struct GNUNET_dv_heap *root,
+ struct GNUNET_dv_neighbor *neighbor,
+ unsigned int new_cost);
/**
* Fixes the tree after a node's cost was externally modified
*/
int
-GNUNET_DV_Heap_updatedCost(struct GNUNET_dv_heap *root, struct
GNUNET_dv_neighbor *neighbor);
+GNUNET_DV_Heap_updatedCost (struct GNUNET_dv_heap *root,
+ struct GNUNET_dv_neighbor *neighbor);
/**
* Iterator to go over all nodes in the tree... Goes from the bottom up
*/
void
-GNUNET_DV_Heap_Iterator (void (*callee)(struct GNUNET_dv_neighbor *neighbor,
struct GNUNET_dv_heap *root, GNUNET_PeerIdentity *toMatch), struct
GNUNET_dv_heap *root, struct GNUNET_dv_heap_node *node,const
GNUNET_PeerIdentity *toMatch);
+GNUNET_DV_Heap_Iterator (void (*callee)
+ (struct GNUNET_dv_neighbor * neighbor,
+ struct GNUNET_dv_heap * root,
+ GNUNET_PeerIdentity * toMatch),
+ struct GNUNET_dv_heap *root,
+ struct GNUNET_dv_heap_node *node,
+ const GNUNET_PeerIdentity * toMatch);
/**
@@ -173,8 +185,8 @@
* in the walk. Calls callee with the data, or NULL if the tree is empty
* or some other problem crops up.
*/
-struct GNUNET_dv_neighbor *
-GNUNET_DV_Heap_Walk_getNext (struct GNUNET_dv_heap *root);
+struct GNUNET_dv_neighbor *GNUNET_DV_Heap_Walk_getNext (struct GNUNET_dv_heap
+ *root);
#endif /* HEAP_H_ */
Modified: GNUnet/src/applications/dv/module/heaptest.c
===================================================================
--- GNUnet/src/applications/dv/module/heaptest.c 2008-12-14 00:45:04 UTC
(rev 8001)
+++ GNUnet/src/applications/dv/module/heaptest.c 2008-12-14 01:01:16 UTC
(rev 8002)
@@ -28,80 +28,83 @@
#include "dv.h"
-void iterator_callback(struct GNUNET_dv_neighbor *neighbor, struct
GNUNET_dv_heap *root)
+void
+iterator_callback (struct GNUNET_dv_neighbor *neighbor,
+ struct GNUNET_dv_heap *root)
{
- fprintf(stdout, "Node is:%d\n", neighbor->cost);
+ fprintf (stdout, "Node is:%d\n", neighbor->cost);
}
-int main(int argc, char **argv)
+int
+main (int argc, char **argv)
{
- struct GNUNET_dv_heap *myHeap;
- struct GNUNET_dv_neighbor *neighbor1;
- struct GNUNET_dv_neighbor *neighbor2;
- struct GNUNET_dv_neighbor *neighbor3;
- struct GNUNET_dv_neighbor *neighbor4;
- struct GNUNET_dv_neighbor *neighbor5;
- struct GNUNET_dv_neighbor *neighbor6;
+ struct GNUNET_dv_heap *myHeap;
+ struct GNUNET_dv_neighbor *neighbor1;
+ struct GNUNET_dv_neighbor *neighbor2;
+ struct GNUNET_dv_neighbor *neighbor3;
+ struct GNUNET_dv_neighbor *neighbor4;
+ struct GNUNET_dv_neighbor *neighbor5;
+ struct GNUNET_dv_neighbor *neighbor6;
- myHeap = malloc(sizeof(struct GNUNET_dv_heap));
- myHeap->type = GNUNET_DV_MAX_HEAP;
- myHeap->max_size = 10;
- myHeap->size = 0;
+ myHeap = malloc (sizeof (struct GNUNET_dv_heap));
+ myHeap->type = GNUNET_DV_MAX_HEAP;
+ myHeap->max_size = 10;
+ myHeap->size = 0;
- neighbor1 = malloc(sizeof(struct GNUNET_dv_neighbor));
- neighbor2 = malloc(sizeof(struct GNUNET_dv_neighbor));
- neighbor3 = malloc(sizeof(struct GNUNET_dv_neighbor));
- neighbor4 = malloc(sizeof(struct GNUNET_dv_neighbor));
- neighbor5 = malloc(sizeof(struct GNUNET_dv_neighbor));
- neighbor6 = malloc(sizeof(struct GNUNET_dv_neighbor));
+ neighbor1 = malloc (sizeof (struct GNUNET_dv_neighbor));
+ neighbor2 = malloc (sizeof (struct GNUNET_dv_neighbor));
+ neighbor3 = malloc (sizeof (struct GNUNET_dv_neighbor));
+ neighbor4 = malloc (sizeof (struct GNUNET_dv_neighbor));
+ neighbor5 = malloc (sizeof (struct GNUNET_dv_neighbor));
+ neighbor6 = malloc (sizeof (struct GNUNET_dv_neighbor));
- neighbor1->cost = 60;
- neighbor2->cost = 50;
- neighbor3->cost = 70;
- neighbor4->cost = 120;
- neighbor5->cost = 100;
- neighbor6->cost = 30;
+ neighbor1->cost = 60;
+ neighbor2->cost = 50;
+ neighbor3->cost = 70;
+ neighbor4->cost = 120;
+ neighbor5->cost = 100;
+ neighbor6->cost = 30;
- fprintf(stdout,"Inserting\n");
- GNUNET_DV_Heap_insert(myHeap,neighbor1);
- printTree(myHeap->root);
+ fprintf (stdout, "Inserting\n");
+ GNUNET_DV_Heap_insert (myHeap, neighbor1);
+ printTree (myHeap->root);
- fprintf(stdout,"Inserting\n");
- GNUNET_DV_Heap_insert(myHeap,neighbor2);
- printTree(myHeap->root);
+ fprintf (stdout, "Inserting\n");
+ GNUNET_DV_Heap_insert (myHeap, neighbor2);
+ printTree (myHeap->root);
- fprintf(stdout,"Inserting\n");
- GNUNET_DV_Heap_insert(myHeap,neighbor3);
- printTree(myHeap->root);
+ fprintf (stdout, "Inserting\n");
+ GNUNET_DV_Heap_insert (myHeap, neighbor3);
+ printTree (myHeap->root);
- fprintf(stdout,"Inserting\n");
- GNUNET_DV_Heap_insert(myHeap,neighbor4);
- printTree(myHeap->root);
+ fprintf (stdout, "Inserting\n");
+ GNUNET_DV_Heap_insert (myHeap, neighbor4);
+ printTree (myHeap->root);
- fprintf(stdout,"Inserting\n");
- GNUNET_DV_Heap_insert(myHeap,neighbor5);
- printTree(myHeap->root);
+ fprintf (stdout, "Inserting\n");
+ GNUNET_DV_Heap_insert (myHeap, neighbor5);
+ printTree (myHeap->root);
- fprintf(stdout,"Inserting\n");
- GNUNET_DV_Heap_insert(myHeap,neighbor6);
- printTree(myHeap->root);
+ fprintf (stdout, "Inserting\n");
+ GNUNET_DV_Heap_insert (myHeap, neighbor6);
+ printTree (myHeap->root);
- fprintf(stdout,"Removing\n");
- GNUNET_DV_Heap_removeNode(myHeap,neighbor5);
- printTree(myHeap->root);
+ fprintf (stdout, "Removing\n");
+ GNUNET_DV_Heap_removeNode (myHeap, neighbor5);
+ printTree (myHeap->root);
- fprintf(stdout,"Removing\n");
- GNUNET_DV_Heap_removeRoot(myHeap);
- printTree(myHeap->root);
+ fprintf (stdout, "Removing\n");
+ GNUNET_DV_Heap_removeRoot (myHeap);
+ printTree (myHeap->root);
- fprintf(stdout,"Updating\n");
- GNUNET_DV_Heap_updateCost(myHeap, neighbor6, 200);
- printTree(myHeap->root);
+ fprintf (stdout, "Updating\n");
+ GNUNET_DV_Heap_updateCost (myHeap, neighbor6, 200);
+ printTree (myHeap->root);
- fprintf(stdout,"Iterating\n");
- GNUNET_DV_Heap_Iterator (iterator_callback, myHeap, myHeap->root);
- return 0;
+ fprintf (stdout, "Iterating\n");
+ GNUNET_DV_Heap_Iterator (iterator_callback, myHeap, myHeap->root);
+ return 0;
}
/* end of heaptest.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8002 - GNUnet/src/applications/dv/module,
gnunet <=