From a5806d420808546c4dd4bf47b9017572d79fe799 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Thu, 15 Jan 2015 14:19:55 +0000 Subject: [PATCH] - added path_cmp --- src/cadet/cadet_path.c | 23 +++++++++++++++++++++++ src/cadet/cadet_path.h | 13 +++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/cadet/cadet_path.c b/src/cadet/cadet_path.c index c00e417b1..b09bf0227 100644 --- a/src/cadet/cadet_path.c +++ b/src/cadet/cadet_path.c @@ -294,6 +294,29 @@ path_destroy (struct CadetPeerPath *p) } +/** + * Compare two paths. + * + * @param p1 First path. + * @param p2 Second path. + * + * @return > 0 if p1 is longer, or the first differing PEER_Id is higher on p1. + * < 0 if p2 is longer, or the first differing PEER_Id is higher on p2. + * 0 if they are identical. + */ +int +path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2) +{ + if (p1->length > p2->length) + return 1; + + if (p1->length < p2->length) + return -1; + + return memcmp (p1->peers, p2->peers, sizeof (GNUNET_PEER_Id) * p1->length); +} + + char * path_2s (struct CadetPeerPath *p) { diff --git a/src/cadet/cadet_path.h b/src/cadet/cadet_path.h index 326626f9d..aa951e5c8 100644 --- a/src/cadet/cadet_path.h +++ b/src/cadet/cadet_path.h @@ -171,6 +171,19 @@ path_is_valid (const struct CadetPeerPath *path); int path_destroy (struct CadetPeerPath *p); +/** + * Compare two paths. + * + * @param p1 First path. + * @param p2 Second path. + * + * @return > 0 if p1 is longer, or the first differing PEER_Id is higher on p1. + * < 0 if p2 is longer, or the first differing PEER_Id is higher on p2. + * 0 if they are identical. + */ +int +path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2); + /** * Builds a path from a PeerIdentity array. * -- 2.25.1