Added twc_hash_tox_id.

This commit is contained in:
Håvard Pettersson 2014-11-22 22:32:16 +01:00
parent 73980b1042
commit a5c4023f9e
2 changed files with 18 additions and 0 deletions

View File

@ -168,3 +168,18 @@ twc_uint32_reverse_bytes(uint32_t num)
return res;
}
/**
* Hash a Tox ID of size TOX_CLIENT_ID_SIZE bytes using a modified djb2 hash.
*/
unsigned long long
twc_hash_tox_id(const uint8_t *tox_id)
{
unsigned long long hash = 5381;
for (size_t i = 0; i < TOX_CLIENT_ID_SIZE; ++i)
hash ^= (hash << 5) + (hash >> 2) + tox_id[i];
return hash;
}

View File

@ -51,5 +51,8 @@ twc_get_friend_id_short(Tox *tox, int32_t friend_number);
uint32_t
twc_uint32_reverse_bytes(uint32_t num);
unsigned long long
twc_hash_tox_id(const uint8_t *tox_id);
#endif // TOX_WEECHAT_UTILS_H