mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 09:13:55 -06:00
util/uuid: add a hash function
Add hash function to uuid module using the djb2 hash algorithm. Add a couple simple unit tests for the hash function, checking collisions for similar UUIDs. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Albert Esteve <aesteve@redhat.com> Message-Id: <20231002065706.94707-2-aesteve@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
70f88436aa
commit
a6ceee591a
3 changed files with 43 additions and 0 deletions
14
util/uuid.c
14
util/uuid.c
|
@ -116,3 +116,17 @@ QemuUUID qemu_uuid_bswap(QemuUUID uuid)
|
|||
bswap16s(&uuid.fields.time_high_and_version);
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/* djb2 hash algorithm */
|
||||
uint32_t qemu_uuid_hash(const void *uuid)
|
||||
{
|
||||
QemuUUID *qid = (QemuUUID *) uuid;
|
||||
uint32_t h = 5381;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(qid->data); i++) {
|
||||
h = (h << 5) + h + qid->data[i];
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue