static void test_hash_int (void) { int a, b; a = 1; b = 2; assert (int_hash (&a) != int_hash (&b)); a = 2; b = 2; assert (int_hash (&a) == int_hash (&b)); }
size_t hash() const { std::hash<int> int_hash; std::hash<std::string> string_hash; switch(state) { case State::Int: return int_hash(integerValue); case State::String: return string_hash(stringValue); default: throw std::exception(); } };
static void add_forkserv_pages(L4_Word_t start, L4_Word_t end) { for(L4_Word_t addr = start & ~PAGE_MASK; addr <= (end | PAGE_MASK); addr += PAGE_SIZE) { size_t hash = int_hash(addr); void *ptr = htable_get(&forkserv_pages, hash, &forkserv_page_cmp, &addr); if(ptr == NULL) { struct forkserv_page *p = malloc(sizeof(*p)); p->address = addr; if(!htable_add(&forkserv_pages, hash, p)) { fprintf(stderr, "htable_add() failed\n"); abort(); } } } }
/* NOTE: @it only becomes valid if the return value is not 0. */ static uint32_t ref_first( uint32_t *aux_p, struct ref_iter *it, struct map_group *g, int ix) { if(MG_N_ALLOC_LOG2(g) == 0) return 0; it->ix = ix; it->mask = (1 << MG_N_ALLOC_LOG2(g)) - 1; it->pos = int_hash(ix) & it->mask; it->lim = it->pos + min(1 << MG_N_ALLOC_LOG2(g), MAX_PROBE_DEPTH); uint32_t c = g->children[it->pos]; if(IS_BUCKET(c)) ref_enter_bucket(it, g, c); else { it->b_cs = NULL; it->b_aux = NULL; if(IS_REF(c) && AUX_INDEX(*aux_p = g->c_aux[it->pos]) == ix) return c; } return ref_next(aux_p, it, g); }
/* Hashes a int for a larger hash table. */ unsigned bignumhash(int i) { return int_hash(i, BIGHASHSIZE); }
/* Hashes a int. */ unsigned numhash(int i) { return int_hash(i, HASHSIZE); }
static size_t hash_forkserv_page(const void *key, void *priv) { return int_hash(((struct forkserv_page *)key)->address); }