summaryrefslogtreecommitdiff
path: root/src/rps/rps-test_util.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2019-04-04 13:41:25 +0200
committerJulius Bünger <buenger@mytum.de>2019-04-04 13:42:57 +0200
commit8c3d9fc59cd5617c4f5b7ea621971bdff25f5353 (patch)
tree910d8bdd653c13d47d943c69b405e2818aac2d14 /src/rps/rps-test_util.c
parenta6f561efa7359dae5af8bfd3763e4f16168030ab (diff)
RPS: Return peers to client after many observed ids
Diffstat (limited to 'src/rps/rps-test_util.c')
-rw-r--r--src/rps/rps-test_util.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index 077750329..fcb4f59a0 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -487,4 +487,42 @@ store_prefix_file_name (const struct GNUNET_PeerIdentity *peer,
return file_name;
}
+
+/**
+ * @brief Factorial
+ *
+ * @param x Number of which to compute the factorial
+ *
+ * @return Factorial of @a x
+ */
+uint32_t fac (uint32_t x)
+{
+ if (1 >= x)
+ {
+ return x;
+ }
+ return x * fac (x - 1);
+}
+
+/**
+ * @brief Binomial coefficient (n choose k)
+ *
+ * @param n
+ * @param k
+ *
+ * @return Binomial coefficient of @a n and @a k
+ */
+uint32_t binom (uint32_t n, uint32_t k)
+{
+ //GNUNET_assert (n >= k);
+ if (k > n) return 0;
+ /* if (0 > n) return 0; - always false */
+ /* if (0 > k) return 0; - always false */
+ if (0 == k) return 1;
+ return fac (n)
+ /
+ fac(k) * fac(n - k);
+}
+
+
/* end of gnunet-service-rps.c */