summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorKarsten Loesing <karsten.loesing@gmx.net>2009-07-13 22:43:06 +0200
committerKarsten Loesing <karsten.loesing@gmx.net>2009-07-13 22:43:06 +0200
commit8f1a973669284e5662bd6f23bc96ecfafa57c554 (patch)
treef8145dc47dee99bc85814d3bac2056a8c134e51a /src/common/util.c
parent707a44a7b0e12f9aef541dd69b356e2f123bcda8 (diff)
downloadtor-8f1a973669284e5662bd6f23bc96ecfafa57c554.tar.gz
tor-8f1a973669284e5662bd6f23bc96ecfafa57c554.zip
Two tweaks to exit-port statistics.
Add two functions for round_to_next_multiple_of() for uint32_t and uint64_t. Avoid division in every step of the loop over all ports.
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 7b9e5eb562..0e7f59e620 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -345,6 +345,36 @@ round_to_power_of_2(uint64_t u64)
return low;
}
+/** Return the lowest x such that x is at least <b>number</b>, and x modulo
+ * <b>divisor</b> == 0. */
+unsigned
+round_to_next_multiple_of(unsigned number, unsigned divisor)
+{
+ number += divisor - 1;
+ number -= number % divisor;
+ return number;
+}
+
+/** Return the lowest x such that x is at least <b>number</b>, and x modulo
+ * <b>divisor</b> == 0. */
+uint32_t
+round_uint32_to_next_multiple_of(uint32_t number, uint32_t divisor)
+{
+ number += divisor - 1;
+ number -= number % divisor;
+ return number;
+}
+
+/** Return the lowest x such that x is at least <b>number</b>, and x modulo
+ * <b>divisor</b> == 0. */
+uint64_t
+round_uint64_to_next_multiple_of(uint64_t number, uint64_t divisor)
+{
+ number += divisor - 1;
+ number -= number % divisor;
+ return number;
+}
+
/* =====
* String manipulation
* ===== */