aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2018-07-12 21:02:20 +0000
committerFranklin Wei <me@fwei.tk>2018-07-12 21:02:20 +0000
commit00e5cc796efc779288f7418eb7f7211e2b1023a7 (patch)
treea3856ae91ef0a07e15f9302c8409a17682b5089e
parentbe0d0fac2fad4ade1a1f81f34644e84042f2578d (diff)
downloadcsaa-00e5cc796efc779288f7418eb7f7211e2b1023a7.zip
csaa-00e5cc796efc779288f7418eb7f7211e2b1023a7.tar.gz
csaa-00e5cc796efc779288f7418eb7f7211e2b1023a7.tar.bz2
csaa-00e5cc796efc779288f7418eb7f7211e2b1023a7.tar.xz
Inline bintree_sibling() and bintree_parent()
No point in incurring a function call overhead for such simple functions.
-rw-r--r--crypto.c12
-rw-r--r--crypto.h12
2 files changed, 12 insertions, 12 deletions
diff --git a/crypto.c b/crypto.c
index db25779..0bef799 100644
--- a/crypto.c
+++ b/crypto.c
@@ -111,18 +111,6 @@ hash_t merkle_compute(hash_t node, const hash_t *comp, const int *orders, size_t
return parent;
}
-/* Given a node's index, return the index of the parent in an array
- * representation of a binary tree. */
-uint64_t bintree_parent(uint64_t idx)
-{
- return (idx - 1) / 2;
-}
-
-uint64_t bintree_sibling(uint64_t idx)
-{
- return idx + ((idx & 1) ? 1 : -1);
-}
-
/* Calculate the indicies of the complementary nodes to a
* leaf. `leafidx' is 0 for the rightmost leaf node. This function
* will return an array with a length equal to the number of levels in
diff --git a/crypto.h b/crypto.h
index ca45247..ae5c958 100644
--- a/crypto.h
+++ b/crypto.h
@@ -48,6 +48,18 @@ int *bintree_complement_ordersonly(uint64_t leafidx, int logleaves);
* given leaf node. Will be ordered from nearest relative to root. */
uint64_t *bintree_ancestors(uint64_t leafidx, int logleaves);
+/* Given a node's index, return the index of the parent in an array
+ * representation of a binary tree. */
+static inline uint64_t bintree_parent(uint64_t idx)
+{
+ return (idx - 1) / 2;
+}
+
+static inline uint64_t bintree_sibling(uint64_t idx)
+{
+ return idx + ((idx & 1) ? 1 : -1);
+}
+
uint64_t bintree_parent(uint64_t idx);
uint64_t bintree_sibling(uint64_t idx);