c: Implement the C implementation of the bhash module

This commit is contained in:
2021-11-14 09:15:55 +01:00
parent 560db14a85
commit 67ec1180dd
4 changed files with 126 additions and 0 deletions

46
c/bhash/inc/bhash.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef BHASH_H_INCLUDED
#define BHASH_H_INCLUDED
#include <stdint.h>
#define BHASH_MOD32_ERR UINT32_MAX
typedef struct bhash bhash_t;
struct bhash
{
uint8_t *bh_data; /* Current data buffer */
size_t bh_len; /* Data length */
double bh_bits_avail; /* Bits available */
double bh_bits_used; /* Bits used */
};
/*
* Initialize new instance of Bhash
*/
void bhash_init(bhash_t *bh, const void *data, size_t data_len);
/*
* Destroy a bhash object and its associated data
*/
void bhash_fini(bhash_t *bh);
/*
* Perform a divison of the whole bhash data using the 32-bit `mod` variable
* and return the 32-bit reminder.
*
* This function returns BHASH_MOD32_ERR on error.
*/
uint32_t bhash_mod32(bhash_t *bh, uint32_t mod);
/*
* Return the number of total bits available in hash
*/
double bhash_bits_avail(bhash_t *bh);
/*
* Return the number of bits used in bhash
*/
double bhash_bits_used(bhash_t *bh);
#endif /* BHASH_H_INCLUDED */