- added path_cmp
authorBart Polot <bart@net.in.tum.de>
Thu, 15 Jan 2015 14:19:55 +0000 (14:19 +0000)
committerBart Polot <bart@net.in.tum.de>
Thu, 15 Jan 2015 14:19:55 +0000 (14:19 +0000)
src/cadet/cadet_path.c
src/cadet/cadet_path.h

index c00e417b1c46ffe3cd7ce5b8c2e2af08b946819c..b09bf0227423773417eeaf392923420af72da8b4 100644 (file)
@@ -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)
 {
index 326626f9d54c7e4bfef18077ab9bd8b3a580ce09..aa951e5c823ddba66c622eecf03c95716f6dc62d 100644 (file)
@@ -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.
  *