Added a compare method

master
John Jones 2017-07-26 07:36:45 -05:00
parent c434fbd160
commit c2f2c0c2da
2 changed files with 19 additions and 0 deletions

View File

@ -87,4 +87,6 @@ int multiaddress_get_ip_port(const struct MultiAddress* in);
*/
char* multiaddress_get_peer_id(const struct MultiAddress* in);
int multiaddress_compare(const struct MultiAddress* a, const struct MultiAddress* b);
#endif

View File

@ -347,3 +347,20 @@ int multiaddress_decapsulate(struct MultiAddress * result, char * srci)
}
}
int multiaddress_compare(const struct MultiAddress* a, const struct MultiAddress* b) {
if (a == NULL && b == NULL)
return 0;
if (a == NULL && b != NULL)
return -1;
if (a != NULL && b == NULL)
return 1;
int total = b->bsize - a->bsize;
if (total != 0)
return total;
for(size_t i = 0; i < b->bsize; i++) {
total = b->bytes[i] - a->bytes[i];
if (total != 0)
return total;
}
return 0;
}