stick to gint/guint rather than int32_t/uint32_t

This commit is contained in:
Chris Eagle
2016-12-19 09:43:35 -08:00
parent 5690b7b68f
commit 71bda8e012
4 changed files with 20 additions and 19 deletions

View File

@ -65,14 +65,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
This may be marginally better than what glib does in their direct_hash
but someone with some chops in this space should fix if it needs improving
*/
uint32_t g_direct_hash(const void *v) {
guint g_direct_hash(const void *v) {
#ifdef __HAVE_64_BIT_PTRS
uint64_t hash = (uint64_t)v;
hash = (hash >> 4) | (hash << 60);
hash = hash ^ (hash >> 32);
return (uint32_t)hash;
return (guint)hash;
#else
uint32_t hash = (uint32_t)v;
guint hash = (guint)v;
hash = (hash >> 3) | (hash << 29);
return hash;
#endif
@ -86,9 +86,9 @@ int g_direct_equal(const void *v1, const void *v2) {
djb2+ string hashing
see: http://www.cse.yorku.ca/~oz/hash.html
*/
uint32_t g_str_hash(const void *v) {
guint g_str_hash(const void *v) {
const char *s = (const char*)v;
uint32_t hash = 5381;
guint hash = 5381;
while (*s) {
hash = ((hash << 5) + hash) ^ (int)*s;
s++;
@ -104,8 +104,8 @@ int g_str_equal(const void *v1, const void *v2) {
Bob Jenkins integer hash algorithm
see: http://burtleburtle.net/bob/hash/integer.html
*/
uint32_t g_int_hash(const void *v) {
uint32_t hash = *(const uint32_t*)v;
guint g_int_hash(const void *v) {
guint hash = *(const guint*)v;
hash = (hash + 0x7ed55d16) + (hash << 12);
hash = (hash ^ 0xc761c23c) ^ (hash >> 19);
hash = (hash + 0x165667b1) + (hash << 5);
@ -407,7 +407,7 @@ void g_hash_table_foreach(GHashTable *hash_table, GHFunc func, void* user_data)
int g_hash_table_insert(GHashTable *hash_table, void* key, void* value) {
if (hash_table == NULL) return 1;
GSList *lp;
uint32_t hash = (*hash_table->hash_func)(key);
guint hash = (*hash_table->hash_func)(key);
int bnum = hash % hash_table->size;
for (lp = hash_table->buckets[bnum]; lp; lp = lp->next) {
KeyValue *kv = (KeyValue*)(lp->data);
@ -431,7 +431,7 @@ int g_hash_table_insert(GHashTable *hash_table, void* key, void* value) {
void* g_hash_table_lookup(GHashTable *hash_table, const void* key) {
if (hash_table == NULL) return NULL;
GSList *lp;
uint32_t hash = (*hash_table->hash_func)(key);
guint hash = (*hash_table->hash_func)(key);
int bnum = hash % hash_table->size;
for (lp = hash_table->buckets[bnum]; lp; lp = lp->next) {
KeyValue *kv = (KeyValue*)(lp->data);
@ -481,7 +481,7 @@ void g_hash_table_remove_all(GHashTable *hash_table) {
int g_hash_table_remove(GHashTable *hash_table, const void* key) {
GSList *lp, *prev = NULL;
if (hash_table == NULL) return 0;
uint32_t hash = (*hash_table->hash_func)(key);
guint hash = (*hash_table->hash_func)(key);
int bnum = hash % hash_table->size;
for (lp = hash_table->buckets[bnum]; lp; lp = lp->next) {
KeyValue *kv = (KeyValue*)(lp->data);
@ -519,7 +519,7 @@ GHashTable *g_hash_table_ref(GHashTable *hash_table) {
return hash_table;
}
uint32_t g_hash_table_size(GHashTable *hash_table) {
guint g_hash_table_size(GHashTable *hash_table) {
return hash_table ? hash_table->num_entries : 0;
}