void packet_handle_std_validate(struct packet_handle_std *handle) { struct packet_fields * pktout_inport, *pktout_metadata; uint32_t in_port; uint64_t metadata; if(handle->valid) return; if (nblink_packet_parse(handle->pkt->buffer,&handle->match.match_fields, handle->proto) < 0) return; handle->valid = true; /* Add in_port value to the hash_map */ pktout_inport = (struct packet_fields*) malloc(sizeof(struct packet_fields)); pktout_inport->header = OXM_OF_IN_PORT; pktout_inport->value = (uint8_t*) malloc(sizeof(uint32_t)); memset(pktout_inport->value,0x0,sizeof(uint32_t)); in_port = htonl(handle->pkt->in_port); memcpy(pktout_inport->value,&in_port,sizeof(uint32_t)); hmap_insert(&handle->match.match_fields, &pktout_inport->hmap_node,hash_int(pktout_inport->header, 0)); /*Add metadata value to the hash_map */ pktout_metadata = (struct packet_fields*) malloc(sizeof(struct packet_fields)); pktout_metadata->header = OXM_OF_METADATA; pktout_metadata->value = (uint8_t*) malloc(sizeof(uint64_t) ); metadata = 0xffffffffffffffff; memcpy(pktout_metadata->value, &metadata, sizeof(uint64_t)); hmap_insert(&handle->match.match_fields, &pktout_metadata->hmap_node,hash_int(pktout_metadata->header, 0)); return; }
static void * search_ccmap(void *aux_) { struct ccmap_aux *aux = aux_; size_t i; if (mutation_frac) { for (i = 0; i < n_elems; i++) { uint32_t hash = hash_int(i, 0); if (random_uint32() < mutation_frac) { ovs_mutex_lock(&aux->mutex); uint32_t count = ccmap_find(aux->ccmap, hash); if (count) { ccmap_dec(aux->ccmap, hash); } ovs_mutex_unlock(&aux->mutex); } else { ignore(ccmap_find(aux->ccmap, hash)); } } } else { for (i = 0; i < n_elems; i++) { ignore(ccmap_find(aux->ccmap, hash_int(i, 0))); } } return NULL; }
int main(int argc, char **argv) { int rc = 1; int key = 0; key = hash_int(input[0]); printf("key=%d\n", key); key = hash_int(input[1]); printf("key=%d\n", key); return rc; }
/* Returns a tag that represents that 'mac' is on an unknown port in 'vlan'. * (When we learn where 'mac' is in 'vlan', this allows flows that were * flooded to be revalidated.) */ static tag_type make_unknown_mac_tag(const struct mac_learning *ml, const uint8_t mac[ETH_ADDR_LEN], uint16_t vlan) { uint32_t h = hash_int(ml->secret, mac_table_hash(mac, vlan)); return tag_create_deterministic(h); }
/* Returns a hash value for pointer P, starting from BASIS. */ unsigned int hash_pointer (const void *p, unsigned int basis) { /* Casting to uintptr_t before casting to int suppresses a GCC warning about on 64-bit platforms. */ return hash_int ((int) (uintptr_t) p, basis); }
void delete_from_set_of_ints(struct SetOfInts *si, int value) { if(search_hash_table(si, value) > 0) { int bucket_id = hash_int(si->num_of_buckets,value); while(si->values[bucket_id]!=value) if (++bucket_id >= si->num_of_buckets) bucket_id = 0; si->values[bucket_id]=EMPTY_BUCKET; if(++bucket_id >= si->num_of_buckets ) bucket_id=0; while(bucket_id < si->num_of_buckets){ if(si->values[bucket_id]!=EMPTY_BUCKET){ rehash(si,si->values[bucket_id],bucket_id); } bucket_id++; } si->num_of_elements--; } else{ fprintf(stderr, "%d does not exist in the set!\n",value); exit(EXIT_FAILURE); } }
/* Has the same effect as discover_numa_and_core(), but instead of reading * sysfs entries, extracts the info from 'dummy_config'. * * 'dummy_config' lists the numa_ids of each CPU separated by a comma, e.g. * - "0,0,0,0": four cores on numa socket 0. * - "0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1": 16 cores on two numa sockets. * - "0,0,0,0,1,1,1,1": 8 cores on two numa sockets. * * The different numa ids must be consecutives or the function will abort. */ static void discover_numa_and_core_dummy(const char *dummy_config) { char *conf = xstrdup(dummy_config); char *id, *saveptr = NULL; unsigned i = 0; long max_numa_id = 0; for (id = strtok_r(conf, ",", &saveptr); id; id = strtok_r(NULL, ",", &saveptr)) { struct hmap_node *hnode; struct numa_node *n; long numa_id; numa_id = strtol(id, NULL, 10); if (numa_id < 0 || numa_id >= MAX_NUMA_NODES) { VLOG_WARN("Invalid numa node %ld", numa_id); continue; } max_numa_id = MAX(max_numa_id, numa_id); hnode = hmap_first_with_hash(&all_numa_nodes, hash_int(numa_id, 0)); if (hnode) { n = CONTAINER_OF(hnode, struct numa_node, hmap_node); } else { n = insert_new_numa_node(numa_id); } insert_new_cpu_core(n, i); i++; }
TEST_F(LruCacheTest, StressTest) { const size_t kCacheSize = 512; LruCache<SimpleKey, StringValue> cache(512); const size_t kNumKeys = 16 * 1024; const size_t kNumIters = 100000; char* strings[kNumKeys]; for (size_t i = 0; i < kNumKeys; i++) { strings[i] = (char *)malloc(16); sprintf(strings[i], "%d", i); } srandom(12345); int hitCount = 0; for (size_t i = 0; i < kNumIters; i++) { int index = random() % kNumKeys; uint32_t key = hash_int(index); const char *val = cache.get(key); if (val != NULL) { EXPECT_EQ(strings[index], val); hitCount++; } else { cache.put(key, strings[index]); } } size_t expectedHitCount = kNumIters * kCacheSize / kNumKeys; EXPECT_LT(int(expectedHitCount * 0.9), hitCount); EXPECT_GT(int(expectedHitCount * 1.1), hitCount); EXPECT_EQ(kCacheSize, cache.size()); for (size_t i = 0; i < kNumKeys; i++) { free((void *)strings[i]); } }
static long hash_calc(const char keytype, void *key) { if (keytype == STRING_KEY) return hash_string((char *)key); if (keytype == INT_KEY) return hash_int((int *)key); }
/* Returns a hash value for IDENTITY. */ unsigned int fn_hash_identity (const struct file_identity *identity) { unsigned int hash = hash_int (identity->device, identity->inode); if (identity->name != NULL) hash = hash_string (identity->name, hash); return hash; }
static void benchmark_ccmap(void) { struct ccmap ccmap; struct timeval start; pthread_t *threads; struct ccmap_aux aux; size_t i; /* Insertions. */ xgettimeofday(&start); ccmap_init(&ccmap); for (i = 0; i < n_elems; i++) { ccmap_inc(&ccmap, hash_int(i, 0)); } printf("ccmap insert: %5d ms\n", elapsed(&start)); /* Search and mutation. */ xgettimeofday(&start); aux.ccmap = &ccmap; ovs_mutex_init(&aux.mutex); threads = xmalloc(n_threads * sizeof *threads); for (i = 0; i < n_threads; i++) { threads[i] = ovs_thread_create("search", search_ccmap, &aux); } for (i = 0; i < n_threads; i++) { xpthread_join(threads[i], NULL); } free(threads); printf("ccmap search: %5d ms\n", elapsed(&start)); /* Destruction. */ xgettimeofday(&start); for (i = 0; i < n_elems; i++) { uint32_t hash = hash_int(i, 0); if (ccmap_find(&ccmap, hash)) { /* Also remove any colliding hashes. */ while (ccmap_dec(&ccmap, hash)) { ; } } } ccmap_destroy(&ccmap); printf("ccmap destroy: %5d ms\n", elapsed(&start)); }
void rehash(struct SetOfInts *si, int value, int bucket_id){ si->values[bucket_id]=EMPTY_BUCKET; int rehashed_bucket_id = hash_int(si->num_of_buckets,value); while (si->values[rehashed_bucket_id] != EMPTY_BUCKET) if (++rehashed_bucket_id >= si->num_of_buckets) rehashed_bucket_id = 0; si->values[rehashed_bucket_id]=value; }
void ofl_structs_match_put16(struct ofl_match *match, uint32_t header, uint16_t value){ struct ofl_match_tlv *m = malloc(sizeof (struct ofl_match_tlv)); int len = sizeof(uint16_t); m->header = header; m->value = malloc(len); memcpy(m->value, &value, len); hmap_insert(&match->match_fields,&m->hmap_node,hash_int(header, 0)); match->header.length += len + 4; }
static struct numa_node * insert_new_numa_node(int numa_id) { struct numa_node *n = xzalloc(sizeof *n); hmap_insert(&all_numa_nodes, &n->hmap_node, hash_int(numa_id, 0)); ovs_list_init(&n->cores); n->numa_id = numa_id; return n; }
void ofl_structs_match_put_eth(struct ofl_match *match, uint32_t header, uint8_t value[ETH_ADDR_LEN]){ struct ofl_match_tlv *m = malloc(sizeof (struct ofl_match_tlv)); int len = ETH_ADDR_LEN; m->header = header; m->value = malloc(len); memcpy(m->value, value, len); hmap_insert(&match->match_fields,&m->hmap_node,hash_int(header, 0)); match->header.length += len + 4; }
void ofl_structs_match_put_ipv6m(struct ofl_match *match, uint32_t header, const struct in6_addr *value, const struct in6_addr *mask){ struct ofl_match_tlv *m = malloc(sizeof (struct ofl_match_tlv)); int len = sizeof(struct in6_addr); m->header = header; m->value = malloc(len*2); memcpy(m->value, &value, len); memcpy(m->value + len, &mask, len); hmap_insert(&match->match_fields,&m->hmap_node,hash_int(header, 0)); match->header.length += len*2 + 4; }
void ofl_structs_match_put_ipv6m(struct ofl_match *match, uint32_t header, uint8_t value[IPv6_ADDR_LEN], uint8_t mask[IPv6_ADDR_LEN]){ struct ofl_match_tlv *m = malloc(sizeof (struct ofl_match_tlv)); int len = IPv6_ADDR_LEN; m->header = header; m->value = malloc(len*2); memcpy(m->value, value, len); memcpy(m->value + len, mask, len); hmap_insert(&match->match_fields,&m->hmap_node,hash_int(header, 0)); match->header.length += len*2 + 4; }
static struct cpu_core * insert_new_cpu_core(struct numa_node *n, unsigned core_id) { struct cpu_core *c = xzalloc(sizeof *c); hmap_insert(&all_cpu_cores, &c->hmap_node, hash_int(core_id, 0)); ovs_list_insert(&n->cores, &c->list_node); c->core_id = core_id; c->numa = n; c->available = true; return c; }
void add_to_set_of_ints(struct SetOfInts *si, int value) { if(search_hash_table(si, value) < 0) { int bucket_id = hash_int(si->num_of_buckets,value); while (si->values[bucket_id] != EMPTY_BUCKET) if (++bucket_id >= si->num_of_buckets) bucket_id = 0; si->values[bucket_id]=value; si->num_of_elements++; } }
int search_hash_table(struct SetOfInts *si, int value) { int bucket_id = hash_int(si->num_of_buckets,value); int value_first_bucket = si->values[bucket_id]; while (si->values[bucket_id] != EMPTY_BUCKET) { if (si->values[bucket_id] == value) return si->values[bucket_id]; else if (++bucket_id >= si->num_of_buckets) bucket_id = 0; if(value_first_bucket == si->values[bucket_id]) break; } return -1; }
static void oxm_init(void) { if (hmap_is_empty(&all_oxm_fields)) { int i; for (i = 0; i < N_OXM_FIELDS; i++) { struct oxm_field *f = &oxm_fields[i]; hmap_insert(&all_oxm_fields, &f->hmap_node, hash_int(f->header, 0)); } /* Verify that the header values are unique (duplicate "case" values * cause a compile error). */ switch (0) { #define DEFINE_FIELD(HEADER, DL_TYPE, NW_PROTO, MASKABLE) \ case OXM_##HEADER: break; #include "oxm-match.def" } } }
void ofl_structs_match_convert_pktf2oflm(struct hmap * hmap_packet_fields, struct hmap * hmap_ofl_match) /* * Used to convert between a hmap of "struct packet_fields" to "struct ofl_match" */ { struct packet_fields *iter; HMAP_FOR_EACH(iter,struct packet_fields, hmap_node, hmap_packet_fields) { struct ofl_match_tlv * new_entry = (struct ofl_match_tlv *) malloc(sizeof(struct ofl_match_tlv)); new_entry->header = iter->header; new_entry->value = (uint8_t *) malloc(OXM_LENGTH(new_entry->header)); memcpy(new_entry->value, iter->value,OXM_LENGTH(new_entry->header)); hmap_insert_fast(hmap_ofl_match, &new_entry->hmap_node, hash_int(new_entry->header, 0)); } }
Object *BlenderSync::sync_object(BL::Object b_parent, int persistent_id[OBJECT_PERSISTENT_ID_SIZE], BL::DupliObject b_dupli_ob, Transform& tfm, uint layer_flag, int motion, bool hide_tris) { BL::Object b_ob = (b_dupli_ob ? b_dupli_ob.object() : b_parent); /* light is handled separately */ if(object_is_light(b_ob)) { /* don't use lamps for excluded layers used as mask layer */ if(!motion && !((layer_flag & render_layer.holdout_layer) && (layer_flag & render_layer.exclude_layer))) sync_light(b_parent, persistent_id, b_ob, tfm); return NULL; } /* only interested in object that we can create meshes from */ if(!object_is_mesh(b_ob)) return NULL; /* key to lookup object */ ObjectKey key(b_parent, persistent_id, b_ob); Object *object; /* motion vector case */ if(motion) { object = object_map.find(key); if(object) { if(tfm != object->tfm) { if(motion == -1) object->motion.pre = tfm; else object->motion.post = tfm; object->use_motion = true; } /* mesh deformation blur not supported yet */ if(!scene->integrator->motion_blur) sync_mesh_motion(b_ob, object->mesh, motion); } return object; } /* test if we need to sync */ bool object_updated = false; if(object_map.sync(&object, b_ob, b_parent, key)) object_updated = true; bool use_holdout = (layer_flag & render_layer.holdout_layer) != 0; /* mesh sync */ object->mesh = sync_mesh(b_ob, object_updated, hide_tris); /* special case not tracked by object update flags */ /* holdout */ if(use_holdout != object->use_holdout) { object->use_holdout = use_holdout; scene->object_manager->tag_update(scene); object_updated = true; } /* visibility flags for both parent and child */ uint visibility = object_ray_visibility(b_ob) & PATH_RAY_ALL_VISIBILITY; if(b_parent.ptr.data != b_ob.ptr.data) { visibility &= object_ray_visibility(b_parent); object->random_id ^= hash_int(hash_string(b_parent.name().c_str())); } /* make holdout objects on excluded layer invisible for non-camera rays */ if(use_holdout && (layer_flag & render_layer.exclude_layer)) visibility &= ~(PATH_RAY_ALL_VISIBILITY - PATH_RAY_CAMERA); /* camera flag is not actually used, instead is tested against render layer * flags */ if(visibility & PATH_RAY_CAMERA) { visibility |= layer_flag << PATH_RAY_LAYER_SHIFT; visibility &= ~PATH_RAY_CAMERA; } if(visibility != object->visibility) { object->visibility = visibility; object_updated = true; } /* object sync * transform comparison should not be needed, but duplis don't work perfect * in the depsgraph and may not signal changes, so this is a workaround */ if(object_updated || (object->mesh && object->mesh->need_update) || tfm != object->tfm) { object->name = b_ob.name().c_str(); object->pass_id = b_ob.pass_index(); object->tfm = tfm; object->motion.pre = tfm; object->motion.post = tfm; object->use_motion = false; /* random number */ object->random_id = hash_string(object->name.c_str()); if(persistent_id) { for(int i = 0; i < OBJECT_PERSISTENT_ID_SIZE; i++) object->random_id = hash_int_2d(object->random_id, persistent_id[i]); } else object->random_id = hash_int_2d(object->random_id, 0); if(b_parent.ptr.data != b_ob.ptr.data) object->random_id ^= hash_int(hash_string(b_parent.name().c_str())); /* dupli texture coordinates */ if (b_dupli_ob) { object->dupli_generated = 0.5f*get_float3(b_dupli_ob.orco()) - make_float3(0.5f, 0.5f, 0.5f); object->dupli_uv = get_float2(b_dupli_ob.uv()); } else { object->dupli_generated = make_float3(0.0f, 0.0f, 0.0f); object->dupli_uv = make_float2(0.0f, 0.0f); } object->tag_update(scene); } return object; }
/* * hash_value - hash a value * * given: * type - hash type (see hash.h) * v - the value * state - the state to hash or NULL * * returns: * the new state */ HASH * hash_value(int type, void *v, HASH *state) { LISTELEM *ep; /* list element pointer */ ASSOCELEM **assochead; /* association chain head */ ASSOCELEM *aep; /* current association value */ ASSOCELEM *nextaep; /* next association value */ VALUE *value = (VALUE *)v; /* v cast to a VALUE */ VALUE *vp; /* pointer to next OBJ table value */ ZVALUE fileval; /* size, position, dev, inode of a file */ int i; /* * initialize if state is NULL */ if (state == NULL) { state = hash_init(type, NULL); } /* * process the value type */ switch (value->v_type) { case V_NULL: (state->chkpt)(state); state->bytes = TRUE; break; case V_INT: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); /* hash as if we have a 64 bit value */ state = hash_int(type, value->v_int, state); break; case V_NUM: /* hash this type */ state = hash_number(type, value->v_num, state); break; case V_COM: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); /* hash this type */ state = hash_complex(type, value->v_com, state); break; case V_ADDR: /* there is nothing to setup, simply hash what we point at */ state = hash_value(type, value->v_addr, state); break; case V_STR: /* strings have no setup */ /* hash this type */ state = hash_STR(type, value->v_str, state); break; case V_MAT: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); state->bytes = TRUE; /* hash all the elements of the matrix */ for (i=0; i < value->v_mat->m_size; ++i) { /* hash the next matrix value */ state = hash_value(type, value->v_mat->m_table+i, state); state->bytes = FALSE; /* as if reading words */ } break; case V_LIST: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); /* hash all the elements of the list */ for (i=0, ep = value->v_list->l_first; ep != NULL && i < value->v_list->l_count; ++i, ep = ep->e_next) { /* hash the next list value */ state = hash_value(type, &ep->e_value, state); state->bytes = FALSE; /* as if reading words */ } break; case V_ASSOC: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); state->bytes = TRUE; /* hash the association */ assochead = value->v_assoc->a_table; for (i = 0; i < value->v_assoc->a_size; i++) { nextaep = *assochead; while (nextaep) { aep = nextaep; nextaep = aep->e_next; /* hash the next association value */ state = hash_value(type, &aep->e_value, state); state->bytes = FALSE; /* as if reading words */ } assochead++; } break; case V_OBJ: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); state->bytes = TRUE; /* reading bytes */ /* hash the object name and then the element values */ state = hash_str(type, objtypename( value->v_obj->o_actions->oa_index), state); (state->chkpt)(state); for (i=value->v_obj->o_actions->oa_count, vp=value->v_obj->o_table; i-- > 0; vp++) { /* hash the next object value */ state = hash_value(type, vp, state); state->bytes = FALSE; /* as if reading words */ } break; case V_FILE: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); /* hash file length if possible */ if (getsize(value->v_file, &fileval) == 0) { state = hash_zvalue(type, fileval, state); zfree(fileval); } else { /* hash -1 for invalid length */ state = hash_long(type, (long)-1, state); } /* hash the file position if possible */ if (getloc(value->v_file, &fileval) == 0) { state = hash_zvalue(type, fileval, state); zfree(fileval); } else { /* hash -1 for invalid location */ state = hash_long(type, (long)-1, state); } /* hash the file device if possible */ if (get_device(value->v_file, &fileval) == 0) { state = hash_zvalue(type, fileval, state); zfree(fileval); } else { /* hash -1 for invalid device */ state = hash_long(type, (long)-1, state); } /* hash the file inode if possible */ if (get_inode(value->v_file, &fileval) == 0) { state = hash_zvalue(type, fileval, state); zfree(fileval); } else { /* hash -1 for invalid inode */ state = hash_long(type, (long)-1, state); } break; case V_RAND: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); /* hash the RAND state */ state = hash_int(type, value->v_rand->seeded, state); state = hash_int(type, value->v_rand->bits, state); (state->update)(state, (USB8 *)value->v_rand->buffer, SLEN*FULL_BITS/8); state = hash_int(type, value->v_rand->j, state); state = hash_int(type, value->v_rand->k, state); state = hash_int(type, value->v_rand->need_to_skip, state); (state->update)(state, (USB8 *)value->v_rand->slot, SCNT*FULL_BITS/8); (state->update)(state, (USB8*)value->v_rand->shuf, SHUFLEN*FULL_BITS/8); state->bytes = FALSE; /* as if reading words */ break; case V_RANDOM: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); /* hash the RANDOM state */ state = hash_int(type, value->v_random->seeded, state); state = hash_int(type, value->v_random->bits, state); (state->update)(state, (USB8 *)&(value->v_random->buffer), BASEB/8); state = hash_zvalue(type, value->v_random->r, state); state = hash_zvalue(type, value->v_random->n, state); state->bytes = FALSE; /* as if reading words */ break; case V_CONFIG: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); /* hash the CONFIG state */ state = hash_int(type, value->v_config->outmode, state); state = hash_int(type, value->v_config->outmode2, state); state = hash_long(type,(long)value->v_config->outdigits, state); state = hash_number(type, value->v_config->epsilon, state); state = hash_long(type, (long)value->v_config->epsilonprec, state); state = hash_flag(type, value->v_config->traceflags, state); state = hash_long(type, (long)value->v_config->maxprint, state); state = hash_len(type, value->v_config->mul2, state); state = hash_len(type, value->v_config->sq2, state); state = hash_len(type, value->v_config->pow2, state); state = hash_len(type, value->v_config->redc2, state); state = hash_bool(type, value->v_config->tilde_ok, state); state = hash_bool(type, value->v_config->tab_ok, state); state = hash_long(type, (long)value->v_config->quomod, state); state = hash_long(type, (long)value->v_config->quo, state); state = hash_long(type, (long)value->v_config->mod, state); state = hash_long(type, (long)value->v_config->sqrt, state); state = hash_long(type, (long)value->v_config->appr, state); state = hash_long(type, (long)value->v_config->cfappr, state); state = hash_long(type, (long)value->v_config->cfsim, state); state = hash_long(type, (long)value->v_config->outround, state); state = hash_long(type, (long)value->v_config->round, state); state = hash_bool(type, value->v_config->leadzero, state); state = hash_bool(type, value->v_config->fullzero, state); state = hash_long(type, (long)value->v_config->maxscancount, state); state = hash_str(type, value->v_config->prompt1, state); state->bytes = FALSE; /* as if just read words */ state = hash_str(type, value->v_config->prompt2, state); state->bytes = FALSE; /* as if just read words */ state = hash_int(type, value->v_config->blkmaxprint, state); state = hash_bool(type, value->v_config->blkverbose, state); state = hash_int(type, value->v_config->blkbase, state); state = hash_int(type, value->v_config->blkfmt, state); state = hash_long(type, (long)value->v_config->resource_debug, state); state = hash_long(type, (long)value->v_config->calc_debug, state); state = hash_long(type, (long)value->v_config->user_debug, state); state = hash_bool(type, value->v_config->verbose_quit, state); state = hash_int(type, value->v_config->ctrl_d, state); state = hash_str(type, value->v_config->program, state); state = hash_str(type, value->v_config->base_name, state); state = hash_bool(type, value->v_config->windows, state); state = hash_bool(type, value->v_config->cygwin, state); state = hash_bool(type, value->v_config->compile_custom, state); if (value->v_config->allow_custom != NULL && *(value->v_config->allow_custom)) { state = hash_bool(type, TRUE, state); } else { state = hash_bool(type, FALSE, state); } state = hash_str(type, value->v_config->version, state); state = hash_int(type, value->v_config->baseb, state); state = hash_bool(type, value->v_config->redecl_warn, state); state = hash_bool(type, value->v_config->dupvar_warn, state); break; case V_HASH: /* setup for the this value type */ (state->chkpt)(state); (state->type)(value->v_type, state); /* hash the HASH state */ state = hash_int(type, value->v_hash->type, state); state = hash_bool(type, value->v_hash->bytes,state); state = hash_int(type, value->v_hash->base, state); state = hash_int(type, value->v_hash->chunksize, state); state = hash_int(type, value->v_hash->unionsize, state); (state->update)(state, value->v_hash->h_union.data, state->unionsize); state->bytes = FALSE; /* as if reading words */ break; case V_BLOCK: /* there is no setup for a BLOCK */ /* hash the octets in the BLOCK */ if (value->v_block->datalen > 0) { state = hash_usb8(type, value->v_block->data, value->v_block->datalen, state); } break; case V_OCTET: /* there is no setup for an OCTET */ /* hash the OCTET */ state = hash_usb8(type, value->v_octet, 1, state); break; case V_NBLOCK: /* there is no setup for a NBLOCK */ /* hash the octets in the NBLOCK */ if (value->v_nblock->blk->datalen > 0) { state = hash_usb8(type, value->v_nblock->blk->data, value->v_nblock->blk->datalen, state); } break; default: math_error("hashing an unknown value"); /*NOTREACHED*/ } return state; }
static size_t good_hash(int value) { return hash_int(value, 0x1234abcd); }
void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene) { if(!need_update) return; device_free(device, dscene); KernelIntegrator *kintegrator = &dscene->data.integrator; /* integrator parameters */ kintegrator->max_bounce = max_bounce + 1; if(probalistic_termination) kintegrator->min_bounce = min_bounce + 1; else kintegrator->min_bounce = kintegrator->max_bounce; kintegrator->max_diffuse_bounce = max_diffuse_bounce + 1; kintegrator->max_glossy_bounce = max_glossy_bounce + 1; kintegrator->max_transmission_bounce = max_transmission_bounce + 1; kintegrator->transparent_max_bounce = transparent_max_bounce + 1; if(transparent_probalistic) kintegrator->transparent_min_bounce = transparent_min_bounce + 1; else kintegrator->transparent_min_bounce = kintegrator->transparent_max_bounce; kintegrator->transparent_shadows = transparent_shadows; kintegrator->no_caustics = no_caustics; kintegrator->filter_glossy = (filter_glossy == 0.0f)? FLT_MAX: 1.0f/filter_glossy; kintegrator->seed = hash_int(seed); kintegrator->layer_flag = layer_flag << PATH_RAY_LAYER_SHIFT; kintegrator->use_ambient_occlusion = ((dscene->data.film.pass_flag & PASS_AO) || dscene->data.background.ao_factor != 0.0f); kintegrator->sample_clamp = (sample_clamp == 0.0f)? FLT_MAX: sample_clamp*3.0f; kintegrator->branched = (method == BRANCHED_PATH); kintegrator->aa_samples = aa_samples; kintegrator->diffuse_samples = diffuse_samples; kintegrator->glossy_samples = glossy_samples; kintegrator->transmission_samples = transmission_samples; kintegrator->ao_samples = ao_samples; kintegrator->mesh_light_samples = mesh_light_samples; kintegrator->subsurface_samples = subsurface_samples; kintegrator->sampling_pattern = sampling_pattern; /* sobol directions table */ int max_samples = 1; if(method == BRANCHED_PATH) { foreach(Light *light, scene->lights) max_samples = max(max_samples, light->samples); max_samples = max(max_samples, max(diffuse_samples, max(glossy_samples, transmission_samples))); max_samples = max(max_samples, max(ao_samples, max(mesh_light_samples, subsurface_samples))); } max_samples *= (max_bounce + transparent_max_bounce + 3); int dimensions = PRNG_BASE_NUM + max_samples*PRNG_BOUNCE_NUM; dimensions = min(dimensions, SOBOL_MAX_DIMENSIONS); uint *directions = dscene->sobol_directions.resize(SOBOL_BITS*dimensions); sobol_generate_direction_vectors((uint(*)[SOBOL_BITS])directions, dimensions); device->tex_alloc("__sobol_directions", dscene->sobol_directions); need_update = false; }
/*If Ethertype is already present we should not insert the next*/ HMAP_FOR_EACH_WITH_HASH(iter, struct packet_fields, hmap_node, hash_int(OXM_OF_ETH_TYPE, 0), pktout) { return 0; } /* Do not insert VLAN ethertypes*/ uint16_t *eth_type = (uint16_t*) malloc(sizeof(uint16_t)); memcpy(eth_type,pktout_field->value, Size); if(*eth_type == ETH_TYPE_VLAN || *eth_type == ETH_TYPE_SVLAN || *eth_type == ETH_TYPE_VLAN_QinQ || *eth_type == ETH_TYPE_VLAN_PBB_B){ return 0; } free(eth_type); } /* Creating new hash map entry */ hmap_insert_fast(pktout, &pktout_field->hmap_node,hash_int(pktout_field->header, 0)); return 0; } int nblink_check_for_entry_on_hmap(struct hmap * pktout ,uint32_t header, struct packet_fields * field) /* * This search for an entry on the hmap and points field to it. * If no entry is found, -1 is returned. */ { struct packet_fields *iter; bool done=0; HMAP_FOR_EACH(iter,struct packet_fields, hmap_node,pktout) { if(iter->header == header)
/* Frame hash function (hashes on frame kernel addr). */ unsigned hash_frame(const struct hash_elem *h, void *aux) { return hash_int((int) get_frame(h)->addr); }
static uint64_t perceived_hash(perceived_t* per) { return hash_int(per->token); }
static int random_value (unsigned int seed, int basis) { return hash_int (seed, basis) & VALUE_MASK; }