Add hashing.
This commit is contained in:
parent
6f0f55365b
commit
0ed91e92d1
7 changed files with 109 additions and 4 deletions
19
src/array.c
19
src/array.c
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "object.h"
|
||||
#include "array.h"
|
||||
#include "hash.h"
|
||||
|
||||
struct CFWArray {
|
||||
CFWObject obj;
|
||||
|
@ -88,6 +89,23 @@ equal(void *ptr1, void *ptr2)
|
|||
return true;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
hash(void *ptr)
|
||||
{
|
||||
CFWArray *array = ptr;
|
||||
size_t i;
|
||||
uint32_t hash;
|
||||
|
||||
CFW_HASH_INIT(hash);
|
||||
|
||||
for (i = 0; i < array->size; i++)
|
||||
CFW_HASH_ADD_HASH(hash, cfw_hash(array->data[i]));
|
||||
|
||||
CFW_HASH_FINALIZE(hash);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
static void*
|
||||
copy(void *ptr)
|
||||
{
|
||||
|
@ -258,6 +276,7 @@ static CFWClass class = {
|
|||
.ctor = ctor,
|
||||
.dtor = dtor,
|
||||
.equal = equal,
|
||||
.hash = hash,
|
||||
.copy = copy
|
||||
};
|
||||
CFWClass *cfw_array = &class;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue