/* * hash_number - hash a NUMBER * * given: * type - hash type (see hash.h) * n - the NUMBER * state - the state to hash or NULL * * returns: * the new state */ HASH * hash_number(int type, void *n, HASH *state) { NUMBER *number = (NUMBER *)n; /* n as a NUMBER pointer */ BOOL sign; /* sign of the denominator */ /* * initialize if state is NULL */ if (state == NULL) { state = hash_init(type, NULL); } /* * setup for the NUMBER hash */ (state->chkpt)(state); state->bytes = FALSE; /* * process the numerator */ state = hash_zvalue(type, number->num, state); /* * if the NUMBER is not an integer, process the denominator */ if (qisfrac(number)) { /* note the division */ (state->note)(HASH_DIV(state->base), state); /* hash denominator as positive -- just in case */ sign = number->den.sign; number->den.sign = 0; /* hash the denominator */ state = hash_zvalue(type, number->den, state); /* restore the sign */ number->den.sign = sign; } /* * all done */ return state; }
int main(int a, char **v) { struct hash _calinks, *calinks = &_calinks; const char* bundle = "bundleXXXXXX"; char* tmpfile = 0; if (asprintf(&tmpfile, "%s%s", ETCCERTSDIR, bundle) == -1) return 1; int fd = mkstemp(tmpfile); if (fd == -1) { fprintf(stderr, "Failed to open temporary file %s for ca bundle\n", tmpfile); return 1; } fchmod(fd, 0644); hash_init(calinks); /* Handle global CA certs from config file */ read_global_ca_list(CERTSCONF, calinks, fd); /* Handle local CA certificates */ dir_readfiles(calinks, LOCALCERTSDIR, FILE_REGULAR, &proc_localglobaldir, fd); /* Update etc cert dir for additions and deletions*/ dir_readfiles(calinks, ETCCERTSDIR, FILE_LINK, &proc_etccertsdir, fd); hash_foreach(calinks, update_ca_symlink); /* Update hashes and the bundle */ if (fd != -1) { close(fd); char* newcertname = 0; if (asprintf(&newcertname, "%s%s", ETCCERTSDIR, CERTBUNDLE) != -1) { rename(tmpfile, newcertname); free(newcertname); } } free(tmpfile); /* Execute run-parts */ static const char *run_parts_args[] = { "run-parts", RUNPARTSDIR, 0 }; execve("/usr/bin/run-parts", run_parts_args, NULL); execve("/bin/run-parts", run_parts_args, NULL); perror("run-parts"); return 1; }
int stackdist_process_trace(const uint64_t *p, const uint64_t n, const stackdist_cb fn) { int ret = 0; hash_t *hash = NULL; itree_t *itree = NULL; hash = hash_init(); if (hash == NULL) { goto out; } for(uint64_t i = 0; i < n; i++) { const uint64_t addr = p[i]; /* Search. */ uint64_t last; if ((ret = hash_insert(hash, addr, i, &last)) != 0) { goto out; } if (last == HASH_NOT_FOUND) { fn(i, STACKDIST_INFINITE); continue; } uint64_t holes; if ((ret = itree_insert(last, &itree, &holes)) != 0) { goto out; } const uint64_t dist = i - last - holes - 1; fn(i, dist); } out: if (hash != NULL) { hash_free(hash); } if (itree != NULL) { itree_free(itree); } return ret; }
void simpletest (void) { int counter; struct hashtable *table; table = hash_init (1024); /* Insert some numbers and read them back. */ for (counter=0; test_1[counter].key != 0; counter++) { hash_insert (table, test_1[counter].key, test_1[counter].value); } for (counter=0; test_1[counter].key != 0; counter++) { assert (hash_lookup (table, test_1[counter].key) == test_1[counter].value); } hash_free (table); }
static int calculate_x(mpz_t result, SRP_HashAlgorithm alg, const unsigned char *salt, size_t salt_len, const char *username, const unsigned char *password, size_t password_len) { unsigned char ucp_hash[SHA512_DIGEST_LENGTH]; HashCTX ctx; hash_init(alg, &ctx); srp_dbg_data((char*) username, strlen(username), "Username for x: "); srp_dbg_data((char*) password, password_len, "Password for x: "); hash_update(alg, &ctx, username, strlen(username)); hash_update(alg, &ctx, ":", 1); hash_update(alg, &ctx, password, password_len); hash_final(alg, &ctx, ucp_hash); return H_ns(result, alg, salt, salt_len, ucp_hash, hash_length(alg)); }
NEOERR* ltpl_init(HASH **tplh) { HASH *ltplh = NULL; NEOERR *err; *tplh = NULL; err = hash_init(<plh, hash_str_hash, hash_str_comp); if (err != STATUS_OK) return nerr_pass(err); err = ltpl_parse_dir(PATH_TPL, ltplh); if (err != STATUS_OK) return nerr_pass_ctx(err, "pase dir %s", PATH_TPL); *tplh = ltplh; return STATUS_OK; }
//--------------------------------------------------------------------------------------------------------------------- int pmip_cache_init(void) { int ret; if (pthread_rwlock_init(&pmip_lock, NULL)) { return -1; } pthread_rwlock_wrlock(&pmip_lock); ret = hash_init(&g_pmip_hash, DOUBLE_ADDR, PMIP_CACHE_BUCKETS); pthread_rwlock_unlock(&pmip_lock); #ifdef ENABLE_VT if (ret < 0) return ret; ret = vt_pbc_init(); #endif return ret; }
void history_set_mode( const wchar_t *name ) { if( !mode_table ) { mode_table = malloc( sizeof(hash_table_t )); hash_init( mode_table, &hash_wcs_func, &hash_wcs_cmp ); } current_mode = (history_mode_t *)hash_get( mode_table, name ); if( !current_mode ) { current_mode = history_create_mode( name ); hash_put( mode_table, name, current_mode ); } }
static void rebuild_hash_table(Hash *hash) { int i, j; HashNode **old_node=hash->node; hash_init(hash, hash->size<<1, hash->hash_func); for (i=0; i<hash->size>>1; i++) { HashNode *n=old_node[i]; if (n) { for (j=old_node[i]->count-1; j>0; j--) { hash_set(hash, old_node[i]->entry[j].key, old_node[i]->entry[j].data); } FREE_H(n, sizeof(HashNode)+(old_node[i]->count-1)*sizeof(n->entry[0])); } } }
void init_register_table(void) { HashFunctions f; erts_smp_rwmtx_opt_t rwmtx_opt = ERTS_SMP_RWMTX_OPT_DEFAULT_INITER; rwmtx_opt.type = ERTS_SMP_RWMTX_TYPE_FREQUENT_READ; rwmtx_opt.lived = ERTS_SMP_RWMTX_LONG_LIVED; erts_smp_rwmtx_init_opt(®tab_rwmtx, &rwmtx_opt, "reg_tab"); f.hash = (H_FUN) reg_hash; f.cmp = (HCMP_FUN) reg_cmp; f.alloc = (HALLOC_FUN) reg_alloc; f.free = (HFREE_FUN) reg_free; hash_init(ERTS_ALC_T_REG_TABLE, &process_reg, "process_reg", PREG_HASH_SIZE, f); }
void erts_init_fun_table(void) { HashFunctions f; erts_smp_rwmtx_opt_t rwmtx_opt = ERTS_SMP_RWMTX_OPT_DEFAULT_INITER; rwmtx_opt.type = ERTS_SMP_RWMTX_TYPE_FREQUENT_READ; rwmtx_opt.lived = ERTS_SMP_RWMTX_LONG_LIVED; erts_smp_rwmtx_init_opt(&erts_fun_table_lock, &rwmtx_opt, "fun_tab"); f.hash = (H_FUN) fun_hash; f.cmp = (HCMP_FUN) fun_cmp; f.alloc = (HALLOC_FUN) fun_alloc; f.free = (HFREE_FUN) fun_free; hash_init(ERTS_ALC_T_FUN_TABLE, &erts_fun_table, "fun_table", 16, f); }
hash_t *config_get_feeds(storage_handle_t *handle) { storage_stmt_t *stmt = storage_query(handle, "SELECT * FROM feeds"); hash_t *row, *ret = hash_init(); while (storage_step(stmt, &row) == SQLITE_ROW) { feed_t *feed = feed_create(hash_get(row, "url")); feed->f_name = hash_get_string(row, "name"); feed->f_description = hash_get_string(row, "description"); feed->f_last_update = hash_get_int(row, "updated"); hash_set(ret, xstrdup(hash_get(row, "name")), feed, TRUE); hash_free(row, FALSE, FALSE); } storage_finalize(stmt); return ret; }
EC_API ec_hash ec_hash_create( EcUInt minSize, EcUInt loLoad, EcUInt hiLoad, ec_hash_def *def ) { ec_hash table; ENTERF; table = hash_alloc(); if (table) { if (! hash_init( table, minSize, loLoad, hiLoad, def )) { hash_free( table ); return NULL; } } return table; }
int main(int argc, char *argv[]) { int in_data,addr; int choose, loopflag=1; hash_init(); while(loopflag) { printf("雜湊表內容(e表空格):"); PrintTable(table); printf("\n(1)加入資料\n(2)搜尋資料\n(0)結束=>"); scanf("%d",&choose); switch(choose) { case 0: loopflag=0; /*結束程式*/ break; case 1: if(is_full()) printf("陣列已滿\n"); else { printf("請輸入欲加入之資料=>"); scanf("%d",&in_data); hash_insert(in_data); } break; case 2: printf("請輸入欲搜尋之資料=>"); scanf("%d",&in_data); if((addr=hash_srch(in_data)) == -1) printf("找不到資料\n"); else printf("資料 %d 位於表格第 %d 個位置(由0算起)\n",in_data,addr); break; default: printf("Wrong Input !!!! \n"); } } system("PAUSE"); return 0; }
int main() { uint32_t a[6]; int flag; int n; hash_init(); scanf("%d", &n); flag = 0; while(n--) { scanf("%lu %lu %lu %lu %lu %lu", a, a + 1, a + 2, a + 3, a + 4, a + 5); if(flag == 0) flag = hash_find(a); } printf("%s\n", flag ? "Twin snowflakes found." : "No two snowflakes are alike."); return 0; }
static int add_drivers() { int size; int n = 0; /* initialize hash table */ if (getcfg(cfg_file, "device_driver_table_size", &size, GETCFG_INT32) != 0) size = DRIVER_TABLE_SIZE; driver_table = hash_init(size, hash_func_driver); if (driver_table == NULL) return -1; /* load device drivers into hash table */ char path[PATH_MAX], prefix[32]; getcfg(cfg_file, "device_lib_path", path, GETCFG_STR); getcfg(cfg_file, "device_lib_name_prefix", prefix, GETCFG_STR); char *names = lookup_so(path, prefix); if (names == NULL) { syslog(LOG_ERR, "nono driver found"); return -1; } buf_t *pb = openbuf(names, strlen(names)); if (pb == NULL) { free(names); return -1; } char *line; while ((line = readbuf(pb, "\n")) != NULL) { if (add_driver(line) == 0) n++; } closebuf(pb); free(names); if (n == 0) { syslog(LOG_ERR, "none driver loaded"); return -1; } return 0; }
bool servers_init(bool dont_read_servers_table) { THD *thd; bool return_val= FALSE; DBUG_ENTER("servers_init"); /* init the mutex */ if (my_rwlock_init(&THR_LOCK_servers, NULL)) DBUG_RETURN(TRUE); /* initialise our servers cache */ if (hash_init(&servers_cache, system_charset_info, 32, 0, 0, (hash_get_key) servers_cache_get_key, 0, 0)) { return_val= TRUE; /* we failed, out of memory? */ goto end; } /* Initialize the mem root for data */ init_alloc_root(&mem, ACL_ALLOC_BLOCK_SIZE, 0); if (dont_read_servers_table) goto end; /* To be able to run this from boot, we allocate a temporary THD */ if (!(thd=new THD)) DBUG_RETURN(TRUE); thd->thread_stack= (char*) &thd; thd->store_globals(); lex_start(thd); /* It is safe to call servers_reload() since servers_* arrays and hashes which will be freed there are global static objects and thus are initialized by zeros at startup. */ return_val= servers_reload(thd); delete thd; /* Remember that we don't have a THD */ my_pthread_setspecific_ptr(THR_THD, 0); end: DBUG_RETURN(return_val); }
/** Test if the specified script returns zero. The result is cached, so that if multiple completions use the same condition, it needs only be evaluated once. condition_cache_clear must be called after a completion run to make sure that there are no stale completions. */ static int condition_test( const wchar_t *condition ) { const void *test_res; if( !condition || !wcslen(condition) ) { // fwprintf( stderr, L"No condition specified\n" ); return 1; } if( !condition_cache ) { condition_cache = malloc( sizeof( hash_table_t ) ); if( !condition_cache ) { DIE_MEM(); } hash_init( condition_cache, &hash_wcs_func, &hash_wcs_cmp ); } test_res = hash_get( condition_cache, condition ); if (test_res == CC_NOT_TESTED ) { test_res = exec_subshell( condition, 0 )?CC_FALSE:CC_TRUE; hash_put( condition_cache, condition, test_res ); /* Restore previous status information */ } if( wcscmp( test_res, CC_TRUE ) == 0 ) { return 1; } return 0; }
hcfg_t *hcfg_alloc(void) { hcfg_t *retval; retval = (hcfg_t *) malloc(sizeof(struct hcfg)); if (retval == NULL) return NULL; retval->count = 0; retval->logsize = CONFIG_INITIAL_LOGSIZE; retval->hash = hash_init(CONFIG_INITIAL_LOGSIZE); if (retval->hash == NULL) { free(retval); return NULL; } return retval; }
NEOERR* ltpl_init(HASH **tplh, char *path) { HASH *ltplh = NULL; NEOERR *err; *tplh = NULL; path = path ? path: PATH_TPL"config/run/"; err = hash_init(<plh, hash_str_hash, hash_str_comp); if (err != STATUS_OK) return nerr_pass(err); err = ltpl_parse_dir(path, ltplh); if (err != STATUS_OK) return nerr_pass_ctx(err, "pase dir %s", path); *tplh = ltplh; return STATUS_OK; }
int main(int argc, char **argv) { gtk_test_init(&argc, &argv); hash_init(); resources_register_resource(); gui_init(); list_init(); // Ignore user input during testing gtk_widget_set_sensitive(GTK_WIDGET(gui.window), false); gdk_threads_add_idle((GSourceFunc)test_run, NULL); gui_run(); g_assert_not_reached(); return EXIT_FAILURE; }
/* Initializes the frame table. */ void frame_init() { hash_init(&frame_table, hash_frame, cmp_frame, NULL); random_init(0); lock_init(&ft_lock); /* Used by clock. */ lock_init(&clocklock); list_init(&clocklist); cond_init(&clockwaiting); lock_init(&clockcondlock); cond_init(&clockwaiting); clockrecieved = true; clockwaiters = 0; clockmodified = true; #ifdef CLOCK thread_create("clock.d", PRI_DEFAULT, clock_daemon, NULL); #endif }
void version_sorter_sort(char **list, size_t list_len) { int i; StringLinkedList *sll; ht = hash_init(list_len); for (i = 0; i < list_len; i++) { sll = string_linked_list_init(); parse_version_word(list[i], sll); hash_put(ht, list[i], (void *) sll); } longest_string_len = 0; hash_foreach(ht, &foreach_longest_string_callback, NULL); qsort((void *) list, list_len, sizeof(char *), &compare_by_version); }
/** * Init the global type table * * @param name * @return */ int revm_type_hashcreate(char *name) { char hashname[BUFSIZ]; hash_t *newhash; aspectype_t *type; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); /* Create the hash table for objects of that type */ type = aspect_type_get_by_name(name); if (!type) PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Type subject does not exist", -1); snprintf(hashname, sizeof(hashname), "type_%s", name); XALLOC(__FILE__, __FUNCTION__, __LINE__, newhash, sizeof(hash_t), -1); hash_init(newhash, strdup(hashname), 11, type->type); PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); }
void texcache_init(void) { if (!texcache.index) texcache.filehandle = -1; texcache_closefiles(); texcache_clearmemcache(); texcache_freeptrs(); texcache.currentindex = texcache.firstindex = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex)); texcache.numentries = 0; // Bmemset(&firstcacheindex, 0, sizeof(texcacheindex)); // Bmemset(&cacheptrs[0], 0, sizeof(cacheptrs)); texcache.hashes.size = TEXCACHEHASHSIZE; hash_init(&texcache.hashes); }
NEOERR* base_info_init(struct base_info **binfo) { NEOERR *err; MCS_NOT_NULLA(binfo); if (!*binfo) { struct base_info *linfo = calloc(1, sizeof(struct base_info)); if (!linfo) return nerr_raise(NERR_NOMEM, "alloc base failure"); linfo->usernum = 0; err = hash_init(&linfo->userh, hash_str_hash, hash_str_comp, NULL); if (err != STATUS_OK) return nerr_pass(err); *binfo = linfo; } return STATUS_OK; }
int get_pic(int fd, int which, unsigned char *pic, int low_res) { unsigned char buf[1024]; int n = (low_res) ? 61 : 122; int i; pic_pck[3] = (unsigned char)which; if (send_pck(fd, pic_pck) == -1) { if (!quiet) fprintf(stderr, "%s: get_pic: error: send_pck returned -1\n", __progname); return -1; } printf("Get image #%d: ", which); hash_init(); for (i = 0; i < n; i++) { hash_mark(i, n - 1, 40); if (read_data(fd, buf, 1024) == -1) { if (!quiet) fprintf(stderr, "%s: get_pic: error: read_data returned -1\n", __progname); return -1; } #ifdef DC25 /* * If this is the first row, byte 4 tells us if this is * a low or hi-res image */ if ( i == 0 ) { if ( buf[4] == 0 ) { n=122; } else { n=61; } } #endif memcpy((char *)&pic[i*1024], buf, 1024); } printf("\n"); return end_of_data(fd); }
/* * hash_long - note a long value * * given: * type - hash type (see hash.h) * longval - a long value * state - the state to hash * * returns: * the new state * * This function will hash a long value as if it were a 64 bit value. * The input is a long. If a long is smaller than 64 bits, we will * hash a final 32 bits of zeros. * * This function is OK to hash BOOL's, unslogned long's, unsigned int's * signed int's as well as FLAG's and LEN's. */ HASH * hash_long(int type, long longval, HASH *state) { long lval[64/LONG_BITS]; /* 64 bits of longs */ /* * initialize if state is NULL */ if (state == NULL) { state = hash_init(type, NULL); } /* * setup for the hash_long */ (state->chkpt)(state); state->bytes = FALSE; /* data to be read as words */ /* * catch the zero numeric value special case */ if (longval == 0) { /* note a zero numeric value and return */ (state->note)(HASH_ZERO(state->base), state); return state; } /* * prep for a long value hash */ (state->note)(state->base, state); /* * hash as if we have a 64 bit value */ memset((char *)lval, 0, sizeof(lval)); lval[0] = longval; (state->update)(state, (USB8 *)lval, sizeof(lval)); /* * all done */ return state; }
amqp_rpc_t * amqp_rpc_new(char *exchange, char *routing_key, char *reply_to) { amqp_rpc_t *rpc; assert(routing_key != NULL); if ((rpc = malloc(sizeof(amqp_rpc_t))) == NULL) { FAIL("malloc"); } if (exchange != NULL) { if ((rpc->exchange = strdup(exchange)) == NULL) { FAIL("strdup"); } } else { if ((rpc->exchange = strdup("")) == NULL) { FAIL("strdup"); } } if((rpc->routing_key = strdup(routing_key)) == NULL) { FAIL("strdup"); } if (reply_to != NULL) { rpc->reply_to = bytes_new_from_str(reply_to); BYTES_INCREF(rpc->reply_to); } else { rpc->reply_to = NULL; } rpc->chan = NULL; rpc->cons = NULL; hash_init(&rpc->calls, 101, (hash_hashfn_t)bytes_hash, (hash_item_comparator_t)bytes_cmp, (hash_item_finalizer_t)rpc_call_item_fini); rpc->next_id = 0ll; rpc->cccb = NULL; rpc->clcb = NULL; return rpc; }
int mdb_init ( size_t size ) { enum hashfunc_type hash_type = JENKINS_HASH; bool preallocate = false; bool start_lru_crawler = true; process_started = time (0); settings_init (size); init_lru_crawler (); init_lru_maintainer (); setbuf (stderr, NULL); if ( hash_init (hash_type) != 0 ) { fprintf (stderr, "Failed to initialize hash_algorithm!\n"); return - 1; } assoc_init (settings.hashpower_init); if ( enable_large_pages () == 0 ) { preallocate = true; } slabs_init (settings.maxbytes, settings.factor, preallocate); memcached_thread_init (); if ( start_assoc_maintenance_thread () == - 1 ) { return - 1; } if ( start_lru_crawler && start_lru_maintainer_thread () != 0 ) { fprintf (stderr, "Failed to enable LRU maintainer thread\n"); return - 1; } if ( settings.slab_reassign && start_slab_maintenance_thread () == - 1 ) { return - 1; } return 0; }