From: Nathan S. Evans Date: Fri, 12 Mar 2010 17:32:10 +0000 (+0000) Subject: adding random_heap function definition in case I add it another way X-Git-Tag: initial-import-from-subversion-38251~22483 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5491c6356965f9c20ef64f2c63f7a14989930bf3;p=oweals%2Fgnunet.git adding random_heap function definition in case I add it another way --- diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index 204d3d6ab..bec040596 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h @@ -828,6 +828,21 @@ GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap, void *iterator_cls); +/** + * Return a *uniform* random element from the heap. Choose a random + * number between 0 and heap size and then walk directly to it. + * This cost can be between 0 and n, amortized cost of logN. + * + * @param heap heap to choose random element from + * @param max how many nodes from the heap to choose from + * + * @return data stored at the chosen random node, + * NULL if the heap is empty. + * + */ +void * +GNUNET_CONTAINER_heap_get_random (struct GNUNET_CONTAINER_Heap *heap, uint32_t max); + /** * Perform a random walk of the tree. The walk is biased * towards elements closer to the root of the tree (since