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;
}

View File

@ -39,18 +39,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/* typedefs for glib related types that may still be referenced */
typedef void* gpointer;
typedef const void *gconstpointer;
typedef uint32_t guint;
typedef int gint;
typedef unsigned int guint;
typedef char gchar;
typedef int gboolean;
typedef int (*GCompareFunc)(const void *v1, const void *v2);
typedef void (*GDestroyNotify)(void *data);
uint32_t g_direct_hash(const void *v);
guint g_direct_hash(const void *v);
int g_direct_equal(const void *v1, const void *v2);
uint32_t g_str_hash(const void *v);
guint g_str_hash(const void *v);
int g_str_equal(const void *v1, const void *v2);
uint32_t g_int_hash(const void *v);
guint g_int_hash(const void *v);
int g_int_equal(const void *v1, const void *v2);
typedef struct _GList {
@ -85,7 +86,7 @@ GSList *g_slist_sort(GSList *list, compare_func compare);
GSList *g_slist_find_custom(GSList *list, const void *data, compare_func func);
GSList *g_slist_remove(GSList *list, const void *data);
typedef uint32_t (*GHashFunc)(const void *key);
typedef guint (*GHashFunc)(const void *key);
typedef int (*GEqualFunc)(const void *a, const void *b);
typedef void (*GHFunc)(void* key, void* value, void* user_data);
typedef int (*GHRFunc)(void* key, void* value, void* user_data);
@ -104,7 +105,7 @@ void g_hash_table_remove_all(GHashTable *hash_table);
int g_hash_table_remove(GHashTable *hash_table, const void* key);
void g_hash_table_unref(GHashTable *hash_table);
GHashTable *g_hash_table_ref(GHashTable *hash_table);
uint32_t g_hash_table_size(GHashTable *hash_table);
guint g_hash_table_size(GHashTable *hash_table);
/* replacement for g_malloc dependency */
void *g_malloc(size_t size);

View File

@ -119,7 +119,7 @@ static inline GList *g_list_insert_sorted_merged(GList *list,
return list;
}
static inline int32_t range_compare(gconstpointer a, gconstpointer b)
static inline gint range_compare(gconstpointer a, gconstpointer b)
{
Range *ra = (Range *)a, *rb = (Range *)b;
if (ra->begin == rb->begin && ra->end == rb->end) {

View File

@ -155,7 +155,7 @@ static void count_cpreg(gpointer key, gpointer opaque)
}
}
static int32_t cpreg_key_compare(gconstpointer a, gconstpointer b)
static gint cpreg_key_compare(gconstpointer a, gconstpointer b)
{
uint64_t aidx = cpreg_to_kvm_id(*(uint32_t *)a);
uint64_t bidx = cpreg_to_kvm_id(*(uint32_t *)b);