hash - C - operations on bits representing a structure -
i'm trying write hashset in c, , i've found 1 hash function, hashes according bits in data. have following structure:
struct triple { int a; int b; int c; };
the question - how bit representation object of type struct triple
? let's want xor bits 8-bit integer. how that?
iterate on bytes of struct
, xor each 1 individually, e.g.,
void bytexor(unsigned char xor_byte, void *data, size_t size) { unsigned char *p = data; while (size--) { *p++ ^= xor_byte; } }
usage be:
struct triple my_struct; // ... bytexor(0xff, &my_struct, sizeof my_struct);
(note: answers question of how xor struct
byte. implementing general hash function based on this, may not particularly idea since struct
may have padding, i.e., bytes potentially non-deterministic values unrelated values of actual payload fields.)
Comments
Post a Comment