Added a compare method
This commit is contained in:
parent
c434fbd160
commit
c2f2c0c2da
2 changed files with 19 additions and 0 deletions
|
@ -87,4 +87,6 @@ int multiaddress_get_ip_port(const struct MultiAddress* in);
|
||||||
*/
|
*/
|
||||||
char* multiaddress_get_peer_id(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
|
#endif
|
||||||
|
|
17
multiaddr.c
17
multiaddr.c
|
@ -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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue