Example #1
0
static unsigned int
dict_node_hash(const void *key)
{
    const struct gossip_node *node = key;
    if (node == NULL)
       return 0;
    return dictGenHashFunction((unsigned char*)node->dc.data, node->dc.len) +
           dictGenHashFunction((unsigned char*)node->rack.data, node->rack.len) +
           node->token.mag[0];
}
Example #2
0
File: maps.c Project: goodwinos/pcp
static uint64_t
intHashCallBack(const void *key)
{
    const unsigned int	*i = (const unsigned int *)key;

    return dictGenHashFunction(i, sizeof(unsigned int));
}
Example #3
0
unsigned int
dict_string_hash(const void *key)
{
    const struct string *s = key;
    //return dictGenHashFunction((unsigned char*)key, dn_strlen((char*)key));
    if (s == NULL)
        return 0;
    return dictGenHashFunction(s->data, s->len);
}
Example #4
0
/* Functions managing dictionary of callbacks for pub/sub. */
static unsigned int callbackHash(const void *key) {
    robj *o = (robj *) key;

    if (o->encoding == UG_ENCODING_RAW) {
        return dictGenHashFunction(o->ptr, (int)sdslen((sds)o->ptr));
    } else {
        if (o->encoding == UG_ENCODING_INT) {
            char buf[32];
            int len;
            len = ll2string(buf, 32, (long)o->ptr);
            return dictGenHashFunction((unsigned char *)buf, len);
        } else {
            unsigned int hash;

            o = getDecodedObject(o);
            hash = dictGenHashFunction(o->ptr, (int)sdslen((sds)o->ptr));
            decrRefCount(o);
            return hash;
        }
    }
}
Example #5
0
JSObject* HashTable::get(char* key, int keyLength) {

	unsigned int hash = dictGenHashFunction(key, keyLength);
	int index = hash % max_size;
	if (elements[index] != NULL) {
		HashEntry* brother = elements[index];
		do {
			if (strcmp(brother->key, key) == 0) {
				return brother->value;
			}
			brother = brother->next;
		} while (brother != NULL);
	}

	return NULL;
}
Example #6
0
JSObject* HashTable::set(char* key, int keyLength, JSObject* value) {
	HashEntry* element = new HashEntry(); //get from HashEntry pool//to do

	unsigned int hash = dictGenHashFunction(key, keyLength);
	int index = hash % max_size;

	if (elements[index] != NULL) {
		HashEntry* brother = elements[index];
		do {
			if (strcmp(brother->key, key) == 0) {
				//free the old value "brother->value"
				//todo
				JSObject* oldObject = brother->value;
				brother->value = value;
				return oldObject; //replace entry
			}
			brother = brother->next;
		} while (brother != NULL);
	}

	element->key = key;
	element->value = value;
	element->hash = hash;

	if (elements[index] == NULL) {
		elements[index] = element;
	}

	else {
		int level = 1;
		HashEntry* brother = elements[index];
		while (brother->next != NULL) {
			level++;
			brother = brother->next;
		}
		brother->next = element;
		element->level = level;
	}

	this->length++;
	if (this->length > this->threshold) {
		this->resize(); //asynchronous//todo
	}

	return NULL; //new entry
}
Example #7
0
JSObject* HashTable::del(char* key, int keyLength) {
	unsigned int hash = dictGenHashFunction(key, keyLength);
	int index = hash % max_size;
	if (elements[index] != NULL) {
		HashEntry** brother = elements + index;
		do {
			if (strcmp((*brother)->key, key) == 0) {
				HashEntry* old_element = *brother;
				//free the old element, put them into a HashEntry pool to reuse them.
				//todo

				(*brother) = (*brother)->next;
				return old_element->value;
			}
			brother = &((*brother)->next);
		} while ((*brother) != NULL);
	}

	return NULL;
}
Example #8
0
/* Functions managing dictionary of callbacks for pub/sub. */
static unsigned int callbackHash(const void *key) {
    return dictGenHashFunction((unsigned char*)key,sdslen((char*)key));
}
Example #9
0
unsigned int dictHash(const void *key) {
    return dictGenHashFunction((unsigned char*)key, strlen((char*)key));
}
Example #10
0
static unsigned int _dictStringCopyHTHashFunction(const void *key)
{
    return dictGenHashFunction(key, strlen(key));
}
Example #11
0
//该实现中缺少一些指针的检查,所以使用之前要确保指针的正确性
unsigned int strHash(const void *key)
{
	char *str = (char *)key;
	return  dictGenHashFunction((const unsigned char *)str, 
													strlen(str));
}
Example #12
0
File: db.c Project: josephg/sharedb
static unsigned int dict_dstr_hash(const void *key) {
  return dictGenHashFunction((unsigned char*)key, (int)dstr_len((dstr)key));
}
Example #13
0
static unsigned int hash_func(const void * key) {
	return dictGenHashFunction(key, strlen(key));
}
Example #14
0
// dict's callbacks
static unsigned int hash_cb(const void *key) {
  return dictGenHashFunction((unsigned char *)key, strlen((char *)key));
}
Example #15
0
// table from connfd to muxConn
static unsigned int intKeyHash(const void *key) {
  int t = (int)key;
  return dictGenHashFunction(&t, sizeof(t));
}
Example #16
0
File: maps.c Project: goodwinos/pcp
static uint64_t
sdsHashCallBack(const void *key)
{
    return dictGenHashFunction((unsigned char *)key, sdslen((char *)key));
} 
Example #17
0
unsigned int dictLookupHashFunction(const void *key)
{
	lookupKey *lk = (lookupKey*)key;
	unsigned int ret = dictGenHashFunction(lk->name, strlen(lk->name));
	return ret ^ (lk->type);
}
Example #18
0
unsigned int dictStringHash(const void *key) {
    return dictGenHashFunction(key, strlen(key));
}
Example #19
0
/*
 * murmurhash2.
 */
unsigned int myHash(const void *key) {
    unsigned int ret = dictGenHashFunction(key, strlen((char*)key));
    //printf("hash key = %u\n", ret);
    return ret;
}
Example #20
0
unsigned int
dictObjHash(const void *key) {
    const robj *o = key;
    return dictGenHashFunction(o->ptr, sdslen((sds)o->ptr));
}