示例#1
0
int gentbl(struct ffi_instruction_obj *ops, struct offset_table **table){
    struct offset_table *result;
    struct offset_table *temp;
    struct offset_table *temp2;
    struct offset_stack *ostack;
    struct ffi_instruction cur;
    int i;

    if (table_init(&result) != 0)
        return 1;

    if(stack_init(&ostack) != 0)
        return 1;

    table_init(&temp);
    push(temp, ostack);
    
    for (i=0; i<ops->instruction_count; cur = ops->instructions[i++]){
        switch (cur.operation){
            case START_STRUCT_PTR:
#ifdef DEBUG
                printf("gentbl(): PTR\n");
#endif
                table_init(&temp);
                push(temp, ostack);
                break;
            case END_STRUCT_PTR:
#ifdef DEBUG
                printf("gentbl(): END-STRUPTR\n");
#endif
                pop(&temp, ostack);
                top(&temp2, ostack);
                add_to_table_otable(temp, temp2);
                break;

            case MEMBER:
#ifdef DEBUG
                printf("gentbl(): MMEMBER\n");
#endif
                top(&temp2, ostack);
                add_to_table(&cur, temp2);
                break;
            case MEMBER_PTR:
#ifdef DEBUG
                printf("gentbl(): MEMBER-PTR\n");
#endif
                top(&temp2, ostack);
                add_to_table_sptr(temp2, &cur);
                break;
        }
    }

    top(&result, ostack);
    *table = result;

    return 0;
}
示例#2
0
int main(int argc, char *argv[])
{
    int ret;

    ret = open_File(argc, argv);
    if (ret != 0)
        return E_INTERN;

    //init symbol table
    symbol_table = table_init(DEFAULT_TABLE_SIZE);
    if (symbol_table == NULL) {
        close_File();
        return E_INTERN;
    }

    //init token (init string in token)
    ret = stringInit(&token.attr.lit_string_or_id);
    if (ret != STR_OPERATION_OK) {
        close_File();
        table_destroy(symbol_table);
        return E_INTERN;
    }

    //init instruction list
    instr_list_init(&instruction_list);

    //call parser
    ret = parse();
    if (ret != E_OK) {
#ifdef DEBUG
        fprintf(stderr, "PARSE ERROR %d\n", ret);
#endif
        instr_list_dispose(&instruction_list);
        stringFree(&token.attr.lit_string_or_id);
        table_destroy(symbol_table);
        close_File();
        return ret;
    }
#ifdef DEBUG
    fprintf(stderr, "PARSE OK\n");
#endif
    
    //call interpreter
    ret = interpret();
    if (ret != E_OK) {
#ifdef DEBUG
        fprintf(stderr, "INTERPRET ERROR %d\n", ret);
#endif
    } else {
#ifdef DEBUG
        fprintf(stderr, "INTERPRET OK\n");
#endif
    }
    
    instr_list_dispose(&instruction_list);
    stringFree(&token.attr.lit_string_or_id);
    table_destroy(symbol_table);
    close_File();
    return ret;
}
示例#3
0
static void* table_thread(void* p) {
        
    eng_ctx_t* eng_ctx = eng_context_init(p);
    while (is_thread_run) {
        eng_context_config(eng_ctx);
        eng_ctx->table = p;  // FIXME, to avoid abort in mysql command       
     
        table_t* ptable;
        int ret = mysql_create_table(eng_ctx);
        if (0 == ret) {
            ptable = table_init(eng_ctx->table_name, eng_ctx->table_schema);
            table_set_add(ptable);
            has_first_table = true;
        } 
        eng_context_free_rwservers(eng_ctx);

        time_t remaining_time = end_time - duration;
        if (remaining_time < TABLE_THREAD_SLEEP) {
            sleep(remaining_time);
        } else {
            sleep(TABLE_THREAD_SLEEP);
        }
    }
   
    eng_context_destroy(eng_ctx);

    return NULL;
}
示例#4
0
void builtins_init()
{
    assign_global_builtins(builtin_info);
    stringfuncs_init();
    table_init();
    iostream_init();
}
示例#5
0
文件: clip_fb.c 项目: dmedine/timelab
void setup_this(void){

   lookup = (t_lookup *)lookup_init(1);
   table = (t_table *)table_init(1000, 1);

   rk_clipper = (t_rk_mother *)rk_mother_init(&rk_clipper_func,
					       1,
					       0,
					       1,
					       1);

   install_obj(&lookup->od);
   install_obj(&table->od);
   install_obj(&rk_clipper->od);

   c_sig_freq  = init_lin_ctl(0, CTL_T_LIN, 1);
   c_sig_level = init_lin_ctl(1, CTL_T_LIN, 1);
   c_out_level = init_lin_ctl(2, CTL_T_LIN, 1);
   c_fb_in     = init_lin_ctl(3, CTL_T_LIN, 1);
   c_fb_out    = init_lin_ctl(4, CTL_T_LIN, 1);
   c_clip_gain = init_lin_ctl(5, CTL_T_LIN, 1);

   level_lin_ctl(c_sig_freq, sig_freq);
   level_lin_ctl(c_sig_level, sig_level);
   level_lin_ctl(c_out_level, out_level);
   level_lin_ctl(c_fb_in, fb_in);
   level_lin_ctl(c_fb_out, fb_out);
   level_lin_ctl(c_clip_gain, clip_gain);

}
示例#6
0
/*
 * First add a set of points to the gen_pts struct.
 *
 * Then these points are added into the gen table in the
 * database. The operation is timed.
 * We then convert the gen_pts to penta_pts and add these
 * points to the penta table in the DB. This is also timed.
 *
 * The second part is to query the two tables and time how
 * long it takes to complete each query
 */
int main(int argc, char **argv)
{
  MYSQL dbase;
  int r, i;

  /* connect to DB */
  if (dbinit(&dbase, "localhost", "ashwink",
	     "", "2d") < 0) {
    printf("Error connecting to database\n");
    return -1;
  }

#ifdef TABLE_INIT
  /* table init */
  r = table_init(&dbase);
  if (r < 0) {
    printf("table_init failed\n");
    return -1;
  }

  /* time the adding of points */
  if (time_fills(&dbase) < 0) {
    return -1;
  }
#endif

  /* time the queries */
  if (time_query(&dbase, MIN_P, MAX_P) < 0) {
    return -1;
  }

  return 0;  
}
示例#7
0
void setup_this(void){

   lookup = (t_lookup *)lookup_init(1);
   table = (t_table *)table_init(1000, 1);
   diff = (t_diff *)diff_init(1, 1);

   rk_circuit = (t_rk_circuit *)rk_mother_init(&rk_circuit_func,
					       2,
					       0,
					       1,
					       1);

   install_obj(&lookup->od);
   install_obj(&table->od);
   install_obj(&rk_circuit->od);
   install_obj(&diff->od);

   c_sig_freq  = init_lin_ctl(0, CTL_T_LIN, 1);
   c_sig_level = init_lin_ctl(1, CTL_T_LIN, 1);
   c_out_level = init_lin_ctl(2, CTL_T_LIN, 1);
   c_fb_in     = init_lin_ctl(3, CTL_T_LIN, 1);
   c_fb_out    = init_lin_ctl(4, CTL_T_LIN, 1);

   level_lin_ctl(c_sig_freq, sig_freq);
   level_lin_ctl(c_sig_level, sig_level);
   level_lin_ctl(c_out_level, out_level);
   level_lin_ctl(c_fb_in, fb_in);
   level_lin_ctl(c_fb_in, fb_out);

}
示例#8
0
QueryEngine::QueryEngine(const char * filepath) : decoder(filepath){
    
    //Create filepaths
    std::string basepath(filepath);
    std::string path_to_hashtable = basepath + "/probing_hash.dat";
    std::string path_to_data_bin = basepath + "/binfile.dat";
    std::string path_to_source_vocabid = basepath + "/source_vocabids";

    ///Source phrase vocabids
    read_map(&source_vocabids, path_to_source_vocabid.c_str());

    //Target phrase vocabIDs
    vocabids = decoder.get_target_lookup_map();

    //Read config file
    std::string line;
    std::ifstream config ((basepath + "/config").c_str());
    getline(config, line);
    int tablesize = atoi(line.c_str()); //Get tablesize.
    config.close();

    //Mmap binary table
    struct stat filestatus;
    stat(path_to_data_bin.c_str(), &filestatus);
    binary_filesize = filestatus.st_size;
    binary_mmaped = read_binary_file(path_to_data_bin.c_str(), binary_filesize);

    //Read hashtable
    size_t table_filesize = Table::Size(tablesize, 1.2);
    mem = readTable(path_to_hashtable.c_str(), table_filesize);
    Table table_init(mem, table_filesize);
    table = table_init;

    std::cerr << "Initialized successfully! " << std::endl;
}
示例#9
0
QueryEngine::QueryEngine(const char * filepath){
	
	//Create filepaths
	std::string basepath(filepath);
	std::string path_to_hashtable = basepath + "/probing_hash.dat";
	std::string path_to_data_bin = basepath + "/binfile.dat";
	std::string path_to_vocabid = basepath + "/vocabid.dat";

	//Read config file
	std::string line;
	std::ifstream config ((basepath + "/config").c_str());
	getline(config, line);
	int tablesize = atoi(line.c_str()); //Get tablesize.

	getline(config, line);
	largest_entry = atoi(line.c_str()); //Set largest_entry.
	config.close();

	//Mmap binary table
	struct stat filestatus;
	stat(path_to_data_bin.c_str(), &filestatus);
	binary_filesize = filestatus.st_size;
	binary_mmaped = read_binary_file(path_to_data_bin.c_str(), binary_filesize);

	//Read hashtable
	size_t table_filesize = Table::Size(tablesize, 1.2);
	mem = readTable(path_to_hashtable.c_str(), table_filesize);
	Table table_init(mem, table_filesize);
	table = table_init;

	//Read vocabid
	read_map(&vocabids, path_to_vocabid.c_str());

	std::cout << "Initialized successfully! " << std::endl;
}
示例#10
0
文件: table.c 项目: towry/automata
int main()
{
	table_t table;
	table_init(&table);

	assert(table.len == 10);

	return(0);
}
示例#11
0
文件: top.c 项目: Hilx/SynADT
int CHashTable(data_t *SlaveAXI, data_t *Master2Mem, data_t *Master2SysAlloc, data_t in_size, data_t in_case){

	#pragma HLS INTERFACE s_axilite port=in_size bundle=SlavePort	
	#pragma HLS INTERFACE s_axilite port=in_case bundle=SlavePort
	#pragma HLS INTERFACE s_axilite port=SlaveAXI bundle=SlavePort
	#pragma HLS INTERFACE s_axilite port=return   bundle=SlavePort
	#pragma HLS INTERFACE m_axi depth=1 port=Master2Mem offset=off
	#pragma HLS INTERFACE m_axi depth=1 port=Master2SysAlloc offset=off

	/* -- Control -- */ 
	TestCase = in_case;
	int log2size = in_size;
	
	/* -- init -- */
	table_init(log2size);
	
	ptr_t hdTable = NULL_PTR;
	ptr_t hdTable_old;
	
	Master2SysAlloc[(COUNTER_BASE)/4 + 1] = C_START;
	hdTable_old = hdTable;
	hdTable = PM_1_INSERTION(Master2Mem, Master2SysAlloc, log2size);
	if(hdTable != hdTable_old){
		Master2SysAlloc[(COUNTER_BASE)/4 + 1] = C_STOP;
		hdTable--;
	}
	
	Master2SysAlloc[(COUNTER_BASE)/4 + 2] = C_START;
	hdTable_old = hdTable;
	hdTable = PM_2_CHECK_INSERTION(Master2Mem, Master2SysAlloc, hdTable, log2size);
	if(hdTable != hdTable_old){
		Master2SysAlloc[(COUNTER_BASE)/4 + 2] = C_STOP;
		hdTable--;
	}
	
	Master2SysAlloc[(COUNTER_BASE)/4 + 3] = C_START;
	hdTable_old = hdTable;
	hdTable = PM_3_UPDATE(Master2Mem, Master2SysAlloc, hdTable, log2size);
	if(hdTable != hdTable_old){
		Master2SysAlloc[(COUNTER_BASE)/4 + 3] = C_STOP;
		hdTable--;
	}	
	
	Master2SysAlloc[(COUNTER_BASE)/4 + 4] = C_START;
	hdTable_old = hdTable;
	hdTable = PM_4_DELETION(Master2Mem, Master2SysAlloc, hdTable);
	if(hdTable != hdTable_old){
		Master2SysAlloc[(COUNTER_BASE)/4 + 4] = C_STOP;
		hdTable--;
	}
	
	return hdTable;
}
示例#12
0
文件: mark.c 项目: willsure/netsukuku
/*
 * Takes committed rules and copies them
 * to structs. This is usefule to delete
 * the rules on exit, even if netfilter
 * was modified before the deletion/
 * Returns:
 * 	0
 * 	-1
 */
int
store_rules()
{
	int res;
	iptc_handle_t t;
	struct ipt_entry *r, *f, *d;

	res = table_init(MANGLE_TABLE, &t);
	if (res) {
		error(err_str);
		err_ret(ERR_NETSTO, -1);
	}
	r = (struct ipt_entry *) iptc_first_rule(CHAIN_OUTPUT, &t);
	f = (struct ipt_entry *) iptc_first_rule(CHAIN_POSTROUTING, &t);
	/* Not elegant style, but faster */
	if (death_loop_rule) {
		d = (struct ipt_entry *) iptc_first_rule(CHAIN_PREROUTING, &t);
		if (r && f && d) {
			rr.sz = RESTORE_OUTPUT_RULE_SZ;
			memcpy(rr.e, r, rr.sz);
			rr.chain = CHAIN_OUTPUT;
			fr.sz = NTK_FORWARD_RULE_SZ;
			memcpy(fr.e, f, fr.sz);
			fr.chain = CHAIN_POSTROUTING;
			dr.sz = IGW_FILTER_RULE_SZ;
			memcpy(dr.e, d, dr.sz);
			dr.chain = CHAIN_PREROUTING;
			error("This is store_rules, And the value of t is: %p", t);
			commit_rules(&t);
			return 0;
		} else {

			error("This is store_rules else, And the value of t is: %p",
				  t);
			commit_rules(&t);
			error("In store_rules: %s.", iptc_strerror(errno));
			err_ret(ERR_NETSTO, -1);
		}
	}
	if (r && f) {
		rr.sz = RESTORE_OUTPUT_RULE_SZ;
		memcpy(rr.e, r, rr.sz);
		rr.chain = CHAIN_OUTPUT;
		fr.sz = NTK_FORWARD_RULE_SZ;
		memcpy(fr.e, f, fr.sz);
		fr.chain = CHAIN_POSTROUTING;
		commit_rules(&t);
		return 0;
	}
	commit_rules(&t);
	err_ret(ERR_NETSTO, -1);
}
示例#13
0
static obj * create_call_block(char t, call_block * next){
    obj * o = init_obj();

    call_block * block = malloc(sizeof(call_block));
    MEM_ERROR_CHECK(block)
    block->type = t;
    block->names = table_init(64);
    block->next = next;

    o->type = 'b';
    o->data = block;
    return o;
}
示例#14
0
conv_8_F (unsigned char *src, unsigned char *dst, long samples)
{
  long n = samples;

  if (!table_inited)
    table_init ();
  while (n--)
    {
      (*(float *) dst) = table_8_F[*(unsigned char *) src];
      dst             += 4;
      src             += 1;
    }
  return samples;
}
示例#15
0
文件: gggl-table.c 项目: GNOME/babl
static long
conv_F_16 (unsigned char *src, unsigned char *dst, long samples)
{
    long n = samples;

    if (!table_inited)
        table_init ();
    while (n--)
    {
        register float f = (*(float *) src);
        *(unsigned short *) dst = table_F_16[gggl_float_to_index16 (f)];
        dst                    += 2;
        src                    += 4;
    }
    return samples;
}
示例#16
0
void
ecc_mul_a (const struct ecc_curve *ecc,
	   int initial, mp_limb_t *r,
	   const mp_limb_t *np, const mp_limb_t *p,
	   mp_limb_t *scratch)
{
#define tp scratch
#define table (scratch + 3*ecc->size)
  mp_limb_t *scratch_out = table + (3*ecc->size << ECC_MUL_A_WBITS);
  int is_zero = 0;

  /* Avoid the mp_bitcnt_t type for compatibility with older GMP
     versions. */
  unsigned blocks = (ecc->bit_size + ECC_MUL_A_WBITS - 1) / ECC_MUL_A_WBITS;
  unsigned bit_index = (blocks-1) * ECC_MUL_A_WBITS;

  mp_size_t limb_index = bit_index / GMP_NUMB_BITS;
  unsigned shift = bit_index % GMP_NUMB_BITS;
  mp_limb_t w, bits;

  table_init (ecc, table, ECC_MUL_A_WBITS, initial, p, scratch_out);

  w = np[limb_index];
  bits = w >> shift;
  if (limb_index < ecc->size - 1)
    bits |= np[limb_index + 1] << (GMP_NUMB_BITS - shift);

  assert (bits < TABLE_SIZE);

  sec_tabselect (r, 3*ecc->size, table, TABLE_SIZE, bits);
  is_zero = (bits == 0);

  for (;;)
    {
      unsigned j;
      if (shift >= ECC_MUL_A_WBITS)
	{
	  shift -= ECC_MUL_A_WBITS;
	  bits = w >> shift;
	}
      else
	{
	  if (limb_index == 0)
示例#17
0
char *
dec_ctx_init(struct dec_ctx *ctx, struct membuf *inbuf, struct membuf *outbuf)
{
    char *encoding;
    ctx->bits_read = 0;

    ctx->inbuf = membuf_get(inbuf);
    ctx->inend = membuf_memlen(inbuf);
    ctx->inpos = 0;

    ctx->outbuf = outbuf;

    /* init bitbuf */
    ctx->bitbuf = get_byte(ctx);

    /* init tables */
    table_init(ctx, ctx->t);
    encoding = table_dump(ctx->t);
    return encoding;
}
示例#18
0
文件: main.c 项目: Surogate/epi-phil
int		main()
{
  int		err;
  int		i;
  pthread_t	thd[NB_PHIL];
  t_table	table;

  i = 0;
  table_init(&table);
  table_display(&table);
  err = phil_creat(thd, &table);
  if (err == EXIT_FAILURE)
    {
      perror("phil_creat fail");
      exit(EXIT_FAILURE);
    }
  while(i < NB_PHIL && !pthread_join(thd[i], NULL))
    i++;
  table_display(&table);
  pthread_exit(NULL);
}
示例#19
0
文件: mark.c 项目: willsure/netsukuku
int
mark_close()
{
	iptc_handle_t t;
	int res;

	if (!clean_on_exit) {
		debug(DBG_NORMAL, "mark_close: cleaning is not my task.");
		return 0;
	}
	load_dump_rules();
	res = table_init(MANGLE_TABLE, &t);
	if (res)
		goto reset_error;
	res = 0;
	res += delete_rule(&rr, &t);
	res += delete_rule(&fr, &t);
	if (death_loop_rule) {
		debug(DBG_INSANE,
			  "In mark_close: I'm an IGW: deleting death loop rule.");
		res += delete_rule(&dr, &t);
	}
	if (res)
		goto reset_error;
	res = delete_ntk_forward_chain(&t);
	if (res)
		goto reset_error;
	res = commit_rules(&t);
	if (res)
		goto reset_error;
	debug(DBG_NORMAL, "Netfilter completely restored.");
	return 0;
  reset_error:
	error(err_str);
	loginfo("Netfilter was not restored. To clean, run:\n"
			"\tiptables -t mangle -F\n"
			"\tiptables -t mangle -X %s", NTK_MARK_CHAIN);
	err_ret(ERR_NETRST, -1);
}
示例#20
0
文件: mark.c 项目: willsure/netsukuku
/*
 * This function build the rules:
 *
 * -A ntk_mark_chain -o ntk_tunl<m>
 *  -j CONNMARK --set-mark m
 *
 * If:
 *
 * s= n-number_of_rules_present
 * then:
 * 	if s>0, will be created s rules,
 * else:
 * 	nothing.
 *
 * Returns:
 * 	0
 * 	-1
 */
int
create_mark_rules(int n)
{
	int nchain;
	int res, i;
	char rule[MARK_RULE_SZ];
	iptc_handle_t t;

	res = table_init(MANGLE_TABLE, &t);
	if (res) {
		error(err_str);
		err_ret(ERR_NETRUL, -1);
	}
	nchain = count_ntk_mark_chain(&t);
	if (nchain == -1) {
		error("In create_mark_rules: can not read ntk_mark_chain.");
		err_ret(ERR_NETRUL, -1);
	}
	if (nchain >= n) {
		debug(DBG_NORMAL, "In create_mark_rules: rules present yet.");
		return 0;
	}
	for (i = nchain; i < n; i++) {
		mark_rule_init(rule, NTK_TUNL_PREFIX, i);
		res = append_rule(rule, &t, NTK_MARK_CHAIN);
		if (res) {
			error(err_str);
			err_ret(ERR_NETRUL, -1);
		}
	}
	res = commit_rules(&t);
	if (res) {
		error(err_str);
		err_ret(ERR_NETRUL, -1);
	}
	debug(DBG_NORMAL, "Created %d marking rules.", n - nchain);
	return 0;
}
示例#21
0
static adlb_code
build_worker2host(const struct xlb_hostnames *hostnames,
      const xlb_layout *layout, int my_workers,
      int **worker2host, int *host_count)
{
  *worker2host = malloc(sizeof((*worker2host)[0]) *
                              (size_t)my_workers);
  ADLB_MALLOC_CHECK(*worker2host);

  struct table host_name_idx_map;
  bool ok = table_init(&host_name_idx_map, 128);
  CHECK_MSG(ok, "Table init failed");

  *host_count = 0;
  for (int i = 0; i < my_workers; i++)
  {
    int rank = xlb_rank_from_my_worker_idx(layout, i);
    const char *host_name = xlb_hostnames_lookup(hostnames, rank);
    CHECK_MSG(host_name != NULL, "Unexpected error looking up host for "
              "rank %i", rank);

    unsigned long host_idx;
    if (!table_search(&host_name_idx_map, host_name, (void**)&host_idx))
    {
      host_idx = (unsigned long)(*host_count)++;
      ok = table_add(&host_name_idx_map, host_name, (void*)host_idx);
      CHECK_MSG(ok, "Table add failed");
    }
    (*worker2host)[i] = (int)host_idx;
    DEBUG("host_name_idx_map: my worker %i (rank %i) -> host %i (%s)",
          i, xlb_rank_from_my_worker_idx(layout, i), (int)host_idx,
          host_name);
  }

  table_free_callback(&host_name_idx_map, false, NULL);

  return ADLB_SUCCESS;
}
示例#22
0
文件: gggl-table.c 项目: GNOME/babl
static long
conv_rgb8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
    long n = samples;

    if (!table_inited)
        table_init ();
    while (n--)
    {
        (*(uint32_t *) dst) = table_8_F_int[*(unsigned char *) src];
        dst             += 4;
        src             += 1;
        (*(uint32_t *) dst) = table_8_F_int[*(unsigned char *) src];
        dst             += 4;
        src             += 1;
        (*(uint32_t *) dst) = table_8_F_int[*(unsigned char *) src];
        dst             += 4;
        src             += 1;
        (*(float    *) dst) = 1.0;
        dst             += 4;
    }
    return samples;
}
示例#23
0
void init_predictor ()
{
    table_init();
}
示例#24
0
int
main(int argc, char *argv[])
{
	FILE *fp;
	char buffer[512];
	size_t i, j, r;
	unsigned int d = 0;
	uint64_t s, e, a, ri, si, ai, sr, rg, sg, ag, sd, ng;
	char **t;
	struct ck_ht_stat st;

	r = 20;
	s = 8;
	srand(time(NULL));

	if (argc < 2) {
		ck_error("Usage: ck_ht <dictionary> [<repetitions> <initial size>]\n");
	}

	if (argc >= 3)
		r = atoi(argv[2]);

	if (argc >= 4)
		s = (uint64_t)atoi(argv[3]);

	keys = malloc(sizeof(char *) * keys_capacity);
	assert(keys != NULL);

	fp = fopen(argv[1], "r");
	assert(fp != NULL);

	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
		buffer[strlen(buffer) - 1] = '\0';
		keys[keys_length++] = strdup(buffer);
		assert(keys[keys_length - 1] != NULL);

		if (keys_length == keys_capacity) {
			t = realloc(keys, sizeof(char *) * (keys_capacity *= 2));
			assert(t != NULL);
			keys = t;
		}
	}

	t = realloc(keys, sizeof(char *) * keys_length);
	assert(t != NULL);
	keys = t;

	table_init();

	for (i = 0; i < keys_length; i++)
		d += table_insert(keys[i]) == false;
	ck_ht_stat(&ht, &st);

	fprintf(stderr, "# %zu entries stored, %u duplicates, %" PRIu64 " probe.\n",
	    table_count(), d, st.probe_maximum);

	fprintf(stderr, "#    reverse_insertion serial_insertion random_insertion serial_replace reverse_get serial_get random_get serial_remove negative_get\n\n");

	a = 0;
	for (j = 0; j < r; j++) {
		if (table_reset() == false) {
			ck_error("ERROR: Failed to reset hash table.\n");
		}

		s = rdtsc();
		for (i = keys_length; i > 0; i--)
			d += table_insert(keys[i - 1]) == false;
		e = rdtsc();
		a += e - s;
	}
	ri = a / (r * keys_length);

	a = 0;
	for (j = 0; j < r; j++) {
		if (table_reset() == false) {
			ck_error("ERROR: Failed to reset hash table.\n");
		}

		s = rdtsc();
		for (i = 0; i < keys_length; i++)
			d += table_insert(keys[i]) == false;
		e = rdtsc();
		a += e - s;
	}
	si = a / (r * keys_length);

	a = 0;
	for (j = 0; j < r; j++) {
		keys_shuffle(keys);

		if (table_reset() == false) {
			ck_error("ERROR: Failed to reset hash table.\n");
		}

		s = rdtsc();
		for (i = 0; i < keys_length; i++)
			d += table_insert(keys[i]) == false;
		e = rdtsc();
		a += e - s;
	}
	ai = a / (r * keys_length);

	a = 0;
	for (j = 0; j < r; j++) {
		s = rdtsc();
		for (i = 0; i < keys_length; i++)
			table_replace(keys[i]);
		e = rdtsc();
		a += e - s;
	}
	sr = a / (r * keys_length);

	table_reset();
	for (i = 0; i < keys_length; i++)
		table_insert(keys[i]);

	a = 0;
	for (j = 0; j < r; j++) {
		s = rdtsc();
		for (i = keys_length; i > 0; i--) {
			if (table_get(keys[i - 1]) == NULL) {
				ck_error("ERROR: Unexpected NULL value.\n");
			}
		}
		e = rdtsc();
		a += e - s;
	}
	rg = a / (r * keys_length);

	a = 0;
	for (j = 0; j < r; j++) {
		s = rdtsc();
		for (i = 0; i < keys_length; i++) {
			if (table_get(keys[i]) == NULL) {
				ck_error("ERROR: Unexpected NULL value.\n");
			}
		}
		e = rdtsc();
		a += e - s;
	}
	sg = a / (r * keys_length);

	a = 0;
	for (j = 0; j < r; j++) {
		keys_shuffle(keys);

		s = rdtsc();
		for (i = 0; i < keys_length; i++) {
			if (table_get(keys[i]) == NULL) {
				ck_error("ERROR: Unexpected NULL value.\n");
			}
		}
		e = rdtsc();
		a += e - s;
	}
	ag = a / (r * keys_length);

	a = 0;
	for (j = 0; j < r; j++) {
		s = rdtsc();
		for (i = 0; i < keys_length; i++)
			table_remove(keys[i]);
		e = rdtsc();
		a += e - s;

		for (i = 0; i < keys_length; i++)
			table_insert(keys[i]);
	}
	sd = a / (r * keys_length);

	a = 0;
	for (j = 0; j < r; j++) {
		s = rdtsc();
		for (i = 0; i < keys_length; i++) {
			table_get("\x50\x03\x04\x05\x06\x10");
		}
		e = rdtsc();
		a += e - s;
	}
	ng = a / (r * keys_length);

	printf("%zu "
	    "%" PRIu64 " "
	    "%" PRIu64 " "
	    "%" PRIu64 " "
	    "%" PRIu64 " "
	    "%" PRIu64 " "
	    "%" PRIu64 " "
	    "%" PRIu64 " "
	    "%" PRIu64 " "
	    "%" PRIu64 "\n",
	    keys_length, ri, si, ai, sr, rg, sg, ag, sd, ng);

	return 0;
}
示例#25
0
void worker(int len, int output_options, char* filename)
{
	FILE* table=table_init(filename, 1);    // init orange
	int i;
	gem** pool=malloc(len*sizeof(gem*));    // if not malloc-ed 690k is the limit
	int* pool_length=malloc(len*sizeof(int));
	pool[0]=malloc(sizeof(gem));
	gem_init(pool[0],1,1);
	pool_length[0]=1;
	
	int prevmax=pool_from_table(pool, pool_length, len, table);   // pool filling
	if (prevmax+1==len) {
		fclose(table);       // close
		for (i=0;i<len;++i) free(pool[i]);   // free
		free(pool);          // free
		free(pool_length);   // free
		printf("Table is longer than %d, no need to do anything\n\n",prevmax+1);
		exit(1);
	}
	table=freopen(filename,"a", table);  // append -> updating possible

	for (i=prevmax+1; i<len; ++i) {      // more building
		int j,k,h;
		const int eoc=(i+1)/ (1+1);       // end of combining
		const int j0 =(i+1)/(10+1);       // value ratio < 10
		int comb_tot=0;

		const int grade_max=(int)(log2(i+1)+1);  // gems with max grade cannot be destroyed, so this is a max, not a sup
		gem temp_array[grade_max-1];             // this will have all the grades
		for (j=0; j<grade_max-1; ++j) temp_array[j]=(gem){0};

		for (j=j0; j<eoc; ++j) {          // combine gems and put them in temp array
			for (k=0; k< pool_length[j]; ++k) {
				int g1=(pool[j]+k)->grade;
				for (h=0; h< pool_length[i-1-j]; ++h) {
					int delta=g1 - (pool[i-1-j]+h)->grade;
					if (abs(delta)<=2) {        // grade difference <= 2
						comb_tot++;
						gem temp;
						gem_combine(pool[j]+k, pool[i-1-j]+h, &temp);
						int grd=temp.grade-2;
						if (gem_better(temp, temp_array[grd])) {
							temp_array[grd]=temp;
						}
					}
				}
			}
		}
		int gemNum=0;
		for (j=0; j<grade_max-1; ++j) if (temp_array[j].grade!=0) gemNum++;
		pool_length[i]=gemNum;
		pool[i]=malloc(pool_length[i]*sizeof(gem));
		
		int place=0;
		for (j=0; j<grade_max-1; ++j) {     // copying to pool
			if (temp_array[j].grade!=0) {
				pool[i][place]=temp_array[j];
				place++;
			}
		}
		
		if (!(output_options & mask_quiet)) {
			printf("Value:\t%d\n",i+1);
			if (output_options & mask_debug) {
				printf("Raw:\t%d\n",comb_tot);
				printf("Pool:\t%d\n\n",pool_length[i]);
			}
		}
		table_write_iteration(pool, pool_length, i, table);    // write on file
	}
	
	fclose(table);      // close
	for (i=0;i<len;++i) free(pool[i]);   // free
	free(pool);         // free
	free(pool_length);  // free
}
示例#26
0
void worker(int len, int output_options, char* filename)
{
	FILE* table=table_init(filename, 1);		// init killgem
	int i;
	gem** pool=malloc(len*sizeof(gem*));		// win 262k
	int* pool_length=malloc(len*sizeof(int));
	pool[0]=malloc(sizeof(gem));
	pool_length[0]=1;
	gem_init(pool[0],1,1,1,1);		// grade damage crit bbound
	
	int prevmax=pool_from_table(pool, pool_length, len, table);		// pool filling
	if (prevmax+1==len) {
		fclose(table);
		for (i=0;i<len;++i) free(pool[i]);		// free
		printf("Table is longer than %d, no need to do anything\n\n",prevmax+1);
		exit(1);
	}
	table=freopen(filename,"a", table);		// append -> updating possible

	for (i=prevmax+1; i<len; ++i) {
		int j,k,h;
		const int eoc=(i+1)/ (1+1);       // end of combining
		const int j0 =(i+1)/(10+1);       // value ratio < 10
		int comb_tot=0;

		const int ngrades=(int)log2(i+1);
		const int temp_length=nchecks*ngrades;
		gem temp_array[temp_length];      // this will have all the grades
		for (j=0; j<temp_length; ++j) temp_array[j]=(gem){0};
		double pow_array[temp_length];    // this will have all the powers
		for (j=0; j<temp_length; ++j) pow_array[j]=0;

		for (j=j0; j<eoc; ++j) {          // combine gems and put them in temp array
			for (k=0; k< pool_length[j]; ++k) {
				int g1=(pool[j]+k)->grade;
				for (h=0; h< pool_length[i-1-j]; ++h) {
					int delta=g1 - (pool[i-1-j]+h)->grade;
					if (abs(delta)<=2) {     // grade difference <= 2
						comb_tot++;
						gem temp;
						gem_combine(pool[j]+k, pool[i-1-j]+h, &temp);
						int grd=temp.grade-2;
						int p0 = grd*nchecks;
						
						if      ( gem_rk511(temp) >= pow_array[p0] ) {			// rk511 check
							pow_array[p0]=gem_rk511(temp);
							temp_array[p0]=temp;
						}
						else if ( gem_power(temp) >= pow_array[p0+1] ) {		// rk211 check
							pow_array[p0+1]=gem_power(temp);
							temp_array[p0+1]=temp;
						}
						else if ( gem_rk411(temp) >= pow_array[p0+2] ) {		// rk411 check
							pow_array[p0+2]=gem_rk411(temp);
							temp_array[p0+2]=temp;
						}
						else if ( gem_rk311(temp) >= pow_array[p0+3] ) {		// rk311 check
							pow_array[p0+3]=gem_rk311(temp);
							temp_array[p0+3]=temp;
						}
						else if ( gem_power(temp) >= pow_array[p0+4] ) {		// rk211 check
							pow_array[p0+4]=gem_power(temp);
							temp_array[p0+4]=temp;
						}
						else if ( gem_power(temp) >= pow_array[p0+5] ) {		// rk211 check
							pow_array[p0+5]=gem_power(temp);
							temp_array[p0+5]=temp;
						}
					}
				}
			}
		}
		int gemNum=0;
		for (j=0; j<temp_length; ++j) if (temp_array[j].grade!=0) gemNum++;
		pool_length[i]=gemNum;
		pool[i]=malloc(pool_length[i]*sizeof(gem));
		
		int place=0;
		for (j=0; j<temp_length; ++j) {				// copying to pool
			if (temp_array[j].grade!=0) {
				pool[i][place]=temp_array[j];
				place++;
			}
		}
		
		if (!(output_options & mask_quiet)) {
			printf("Value:\t%d\n",i+1);
			if (output_options & mask_debug) {
				printf("Raw:\t%d\n",comb_tot);
				printf("Pool:\t%d\n\n",pool_length[i]);
			}
		}
		table_write_iteration(pool, pool_length, i, table);			// write on file
	}
	
	fclose(table);      // close
	for (i=0;i<len;++i) free(pool[i]);   // free
	free(pool);         // free
	free(pool_length);  // free
}
示例#27
0
/* Convert table into a grided form, taking into account symmetries
 *
 * table must have at least 3 columns
 * n number of points on circle for ecliptic longitude
 * m number of points on circle for hour angle
 */
int grid_transform(Table *table, size_t n, size_t m, const char *sym)
{
	Table tab; // working table for grided data
	size_t i;
	size_t j;
	size_t r;
	size_t nr = n + 1; // extra rows for hour angles
	size_t nc = m + 1; // extra cols for eclip longs
	double el_step = 360./n; // ecliptic longitude grid step
	double ha_step = 360./m; // hour angle grid step

	int east_only = !strcmp(sym, "E");

	if (table_init(&tab, nr, nc))
		return -1;

	// Setting values for grid axes
	tab.v[0][0] = 0.; // top left point not used
	for (i=1; i<nr; i++)
		tab.v[i][0] = -180.0 + (i-1)*el_step;
	for (j=1; j<nc; j++)
		tab.v[0][j] = -180.0 +(j-1)*ha_step;

	// Some positions don't get written to below.  Initialising the table so
	// that these values end up as zero.
	for (i=1; i<nr; i++)
		for (j=1; j<nc; j++)
			tab.v[i][j] = 0.;
	
	for (r=0; r<table->nr; r++) {
		double el = table->v[r][0];
		double ha = table->v[r][1];
		double val = table->v[r][2];
		size_t i = (size_t) roundf((180. + el)/el_step) % n;
		size_t j = (size_t) roundf((180. + ha)/ha_step) % m;

		// direct
		tab.v[i+1][j+1] = val; // direct

		// spring-autumn
		size_t i_sa = (3*n/2 - i) % n;
		tab.v[i_sa+1][j+1] = val;

		// day-night
		size_t i_dn = (n - i) % n;
		size_t j_dn = (3*m/2 - j) % m;
		tab.v[i_dn+1][j_dn+1] = -val;
		size_t i_sadn = (n - i_sa) % n;
		tab.v[i_sadn+1][j_dn+1] = -val;

		// east-west
		if (east_only) {
			size_t j_ew = (m - j) % m;
			tab.v[i+1][j_ew+1] = val;
			tab.v[i_sa+1][j_ew+1] = val;
			size_t j_ewdn = (3*m/2 - j_ew) % m;
			tab.v[i_dn+1][j_ewdn+1] = -val;
			tab.v[i_sadn+1][j_ewdn+1] = -val;
		}
	}

	table_free(table);
	*table = tab;
	return 0;
}
示例#28
0
void createObjects()
//
//  Input:   none
//  Output:  none
//  Purpose: allocates memory for project's objects.
//
//  NOTE: number of each type of object has already been determined in
//        project_readInput().
//
{
    int j, k;

    // --- allocate memory for each category of object
    if ( ErrorCode ) return;
    Gage     = (TGage *)     calloc(Nobjects[GAGE],     sizeof(TGage));
    Subcatch = (TSubcatch *) calloc(Nobjects[SUBCATCH], sizeof(TSubcatch));
    Node     = (TNode *)     calloc(Nobjects[NODE],     sizeof(TNode));
    Outfall  = (TOutfall *)  calloc(Nnodes[OUTFALL],    sizeof(TOutfall));
    Divider  = (TDivider *)  calloc(Nnodes[DIVIDER],    sizeof(TDivider));
    Storage  = (TStorage *)  calloc(Nnodes[STORAGE],    sizeof(TStorage));
    Link     = (TLink *)     calloc(Nobjects[LINK],     sizeof(TLink));
    Conduit  = (TConduit *)  calloc(Nlinks[CONDUIT],    sizeof(TConduit));
    Pump     = (TPump *)     calloc(Nlinks[PUMP],       sizeof(TPump));
    Orifice  = (TOrifice *)  calloc(Nlinks[ORIFICE],    sizeof(TOrifice));
    Weir     = (TWeir *)     calloc(Nlinks[WEIR],       sizeof(TWeir));
    Outlet   = (TOutlet *)   calloc(Nlinks[OUTLET],     sizeof(TOutlet));
    Pollut   = (TPollut *)   calloc(Nobjects[POLLUT],   sizeof(TPollut));
    Landuse  = (TLanduse *)  calloc(Nobjects[LANDUSE],  sizeof(TLanduse));
    Pattern  = (TPattern *)  calloc(Nobjects[TIMEPATTERN],  sizeof(TPattern));
    Curve    = (TTable *)    calloc(Nobjects[CURVE],    sizeof(TTable));
    Tseries  = (TTable *)    calloc(Nobjects[TSERIES],  sizeof(TTable));
    Aquifer  = (TAquifer *)  calloc(Nobjects[AQUIFER],  sizeof(TAquifer));
    UnitHyd  = (TUnitHyd *)  calloc(Nobjects[UNITHYD],  sizeof(TUnitHyd));
    Snowmelt = (TSnowmelt *) calloc(Nobjects[SNOWMELT], sizeof(TSnowmelt));
    Shape    = (TShape *)    calloc(Nobjects[SHAPE],    sizeof(TShape));

    // --- create LID objects
    lid_create(Nobjects[LID], Nobjects[SUBCATCH]);

    // --- create control rules
    ErrorCode = controls_create(Nobjects[CONTROL]);
    if ( ErrorCode ) return;

    // --- create cross section transects
    ErrorCode = transect_create(Nobjects[TRANSECT]);
    if ( ErrorCode ) return;

    // --- allocate memory for infiltration data
    infil_create(Nobjects[SUBCATCH], InfilModel);

    // --- allocate memory for water quality state variables
    for (j = 0; j < Nobjects[SUBCATCH]; j++)
    {
        Subcatch[j].initBuildup =
                              (double *) calloc(Nobjects[POLLUT], sizeof(double));
        Subcatch[j].oldQual = (double *) calloc(Nobjects[POLLUT], sizeof(double));
        Subcatch[j].newQual = (double *) calloc(Nobjects[POLLUT], sizeof(double));
        Subcatch[j].pondedQual = (double *) calloc(Nobjects[POLLUT], sizeof(double));
        Subcatch[j].totalLoad  = (double *) calloc(Nobjects[POLLUT], sizeof(double));
    }
    for (j = 0; j < Nobjects[NODE]; j++)
    {
        Node[j].oldQual = (double *) calloc(Nobjects[POLLUT], sizeof(double));
        Node[j].newQual = (double *) calloc(Nobjects[POLLUT], sizeof(double));
        Node[j].extInflow = NULL;
        Node[j].dwfInflow = NULL;
        Node[j].rdiiInflow = NULL;
        Node[j].treatment = NULL;
    }
    for (j = 0; j < Nobjects[LINK]; j++)
    {
        Link[j].oldQual = (double *) calloc(Nobjects[POLLUT], sizeof(double));
        Link[j].newQual = (double *) calloc(Nobjects[POLLUT], sizeof(double));
	    Link[j].totalLoad = (double *) calloc(Nobjects[POLLUT], sizeof(double));
    }

    // --- allocate memory for land use buildup/washoff functions
    for (j = 0; j < Nobjects[LANDUSE]; j++)
    {
        Landuse[j].buildupFunc =
            (TBuildup *) calloc(Nobjects[POLLUT], sizeof(TBuildup));
        Landuse[j].washoffFunc =
            (TWashoff *) calloc(Nobjects[POLLUT], sizeof(TWashoff));
    }

    // --- allocate memory for subcatchment landuse factors
    for (j = 0; j < Nobjects[SUBCATCH]; j++)
    {
        Subcatch[j].landFactor =
            (TLandFactor *) calloc(Nobjects[LANDUSE], sizeof(TLandFactor));
        for (k = 0; k < Nobjects[LANDUSE]; k++)
        {
            Subcatch[j].landFactor[k].buildup =
                (double *) calloc(Nobjects[POLLUT], sizeof(double));
        }
    }

    // --- initialize buildup & washoff functions
    for (j = 0; j < Nobjects[LANDUSE]; j++)
    {
        for (k = 0; k < Nobjects[POLLUT]; k++)
        {
            Landuse[j].buildupFunc[k].funcType = NO_BUILDUP;
            Landuse[j].buildupFunc[k].normalizer = PER_AREA;
            Landuse[j].washoffFunc[k].funcType = NO_WASHOFF;
        }
    }

    // --- initialize rain gage properties
    for (j = 0; j < Nobjects[GAGE]; j++)
    {
        Gage[j].tSeries = -1;
        strcpy(Gage[j].fname, "");
    }

    // --- initialize subcatchment properties
    for (j = 0; j < Nobjects[SUBCATCH]; j++)
    {
        Subcatch[j].outSubcatch = -1;
        Subcatch[j].outNode     = -1;
        Subcatch[j].infil       = -1;
        Subcatch[j].groundwater = NULL;
	    Subcatch[j].gwLatFlowExpr = NULL;                                      //(5.1.007)
        Subcatch[j].gwDeepFlowExpr = NULL;                                     //(5.1.007)
        Subcatch[j].snowpack    = NULL;
        Subcatch[j].lidArea     = 0.0;
        for (k = 0; k < Nobjects[POLLUT]; k++)
        {
            Subcatch[j].initBuildup[k] = 0.0;
        }
    }

    // --- initialize RDII unit hydrograph properties
    for ( j = 0; j < Nobjects[UNITHYD]; j++ ) rdii_initUnitHyd(j);

    // --- initialize snowmelt properties
    for ( j = 0; j < Nobjects[SNOWMELT]; j++ ) snow_initSnowmelt(j);

    // --- initialize storage node exfiltration                                //(5.1.007)
    for (j = 0; j < Nnodes[STORAGE]; j++) Storage[j].exfil = NULL;             //(5.1.007)

    // --- initialize link properties
    for (j = 0; j < Nobjects[LINK]; j++)
    {
        Link[j].xsect.type   = -1;
        Link[j].cLossInlet   = 0.0;
        Link[j].cLossOutlet  = 0.0;
        Link[j].cLossAvg     = 0.0;
        Link[j].hasFlapGate  = FALSE;
    }
    for (j = 0; j < Nlinks[PUMP]; j++) Pump[j].pumpCurve  = -1;

    // --- initialize reporting flags
    for (j = 0; j < Nobjects[SUBCATCH]; j++) Subcatch[j].rptFlag = FALSE;
    for (j = 0; j < Nobjects[NODE]; j++) Node[j].rptFlag = FALSE;
    for (j = 0; j < Nobjects[LINK]; j++) Link[j].rptFlag = FALSE;

    //  --- initialize curves, time series, and time patterns
    for (j = 0; j < Nobjects[CURVE]; j++)   table_init(&Curve[j]);
    for (j = 0; j < Nobjects[TSERIES]; j++) table_init(&Tseries[j]);
    for (j = 0; j < Nobjects[TIMEPATTERN]; j++) inflow_initDwfPattern(j);
}
示例#29
0
int main(int argc, char* argv[]) {

    table_data_t*   ptable_data;
    schema_t*       pschema_key;
    schema_t*       pschema_val;
    table_schema_t* ptable_schema;
    table_t*        ptable;

    srand((int)(time(0)));
    schema_set_init();
    table_set_init();

    // loop begin
    pschema_key = schema_init();
    pschema_val = schema_init();

    ptable_data = table_data_init("col1", BIGINT, 0);
    schema_add(pschema_key, ptable_data);

    ptable_data = table_data_init("col2", VARCHAR, 10);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col3", VARCHAR, 11);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col4", VARCHAR, 12);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col5", VARCHAR, 13);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col6", VARCHAR, 14);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col7", VARCHAR, 15);
    schema_add(pschema_val, ptable_data);

    ptable_schema = table_schema_init(pschema_key, pschema_val);

    schema_set_add(ptable_schema);
    // loop end

    // loop begin
    pschema_key = schema_init();
    pschema_val = schema_init();

    ptable_data = table_data_init("t2col1", BIGINT, 0);
    schema_add(pschema_key, ptable_data);

    ptable_data = table_data_init("t2col2", VARCHAR, 10);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("t2col3", VARCHAR, 11);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("t2col4", VARCHAR, 12);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("t2col5", VARCHAR, 13);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("t2col6", VARCHAR, 14);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("t2col7", VARCHAR, 15);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("t2col8", VARCHAR, 15);
    schema_add(pschema_val, ptable_data);

    ptable_schema = table_schema_init(pschema_key, pschema_val);

    schema_set_add(ptable_schema);
    // loop end

    // loop begin
    pschema_key = schema_init();
    pschema_val = schema_init();

    ptable_data = table_data_init("col1", BIGINT, 0);
    schema_add(pschema_key, ptable_data);

    ptable_data = table_data_init("col2", VARCHAR, 10);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col3", VARCHAR, 11);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col4", VARCHAR, 12);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col5", VARCHAR, 13);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col6", VARCHAR, 14);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col7", VARCHAR, 15);
    schema_add(pschema_val, ptable_data);

    ptable_schema = table_schema_init(pschema_key, pschema_val);

    schema_set_add(ptable_schema);
    // loop end

    // loop begin
    pschema_key = schema_init();
    pschema_val = schema_init();

    ptable_data = table_data_init("col1", BIGINT, 0);
    schema_add(pschema_key, ptable_data);

    ptable_data = table_data_init("col2", VARCHAR, 10);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col3", VARCHAR, 11);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col4", VARCHAR, 12);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col5", VARCHAR, 13);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col6", VARCHAR, 14);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col7", VARCHAR, 15);
    schema_add(pschema_val, ptable_data);

    ptable_schema = table_schema_init(pschema_key, pschema_val);

    schema_set_add(ptable_schema);
    // loop end

    // loop begin
    pschema_key = schema_init();
    pschema_val = schema_init();

    ptable_data = table_data_init("col1", BIGINT, 0);
    schema_add(pschema_key, ptable_data);

    ptable_data = table_data_init("col2", BIGINT, 0);
    schema_add(pschema_key, ptable_data);

    ptable_data = table_data_init("col3", VARCHAR, 11);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col4", VARCHAR, 12);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col5", VARCHAR, 13);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col6", VARCHAR, 14);
    schema_add(pschema_val, ptable_data);

    ptable_data = table_data_init("col7", VARCHAR, 15);
    schema_add(pschema_val, ptable_data);

    ptable_schema = table_schema_init(pschema_key, pschema_val);

    schema_set_add(ptable_schema);
    // loop end

    ptable = table_init("test_mysql_cmd", ptable_schema);
    table_set_add(ptable);

    char* sql = my_malloc((size_t)1024000);
    memset(sql, 0, sizeof(sql));

    eng_ctx_t* eng_ctx = my_malloc(sizeof(eng_ctx_t));
    memset(eng_ctx, 0, sizeof(eng_ctx_t));
    eng_ctx->sql = sql;
    eng_ctx->table = ptable;
    eng_ctx->table_schema = ptable_schema;

    sql_gen(eng_ctx, INSERT);
    sql_gen(eng_ctx, UPDATE);
    sql_gen(eng_ctx, DELETE);
    sql_gen(eng_ctx, SELECT);
    sql_gen(eng_ctx, CREATE);

    my_free(sql);
    my_free(eng_ctx);

    schema_set_destroy();
    table_set_destroy();

    return 0;
}
示例#30
0
void worker(int len, int output_options, int pool_zero, char* filename)
{
	FILE* table=table_init(filename, pool_zero);		// init killgem
	int i;
	int size;
	gem* pool[len];
	int pool_length[len];
	pool[0]=malloc(pool_zero*sizeof(gem));
	pool_length[0]=pool_zero;

	if (pool_zero==1) {					// combine
		gem_init(pool[0],1,1,1,1);		// start gem does not matter
		size=1000;							// reasonable comb sizing
	}
	else {									// spec
		gem_init(pool[0]  ,1,1.000000,1,0);
		gem_init(pool[0]+1,1,1.186168,0,1);		// BB has more dmg
		size=20000;							// reasonable spec sizing
	}
	
	int prevmax=pool_from_table(pool, pool_length, len, table);		// pool filling
	if (prevmax+1==len) {
		fclose(table);
		for (i=0;i<len;++i) free(pool[i]);		// free
		printf("Table is longer than %d, no need to do anything\n\n",prevmax+1);
		exit(1);
	}
	table=freopen(filename,"a", table);		// append -> updating possible

	for (i=prevmax+1; i<len; ++i) {
		int j,k,h,l;
		const int eoc=(i+1)/ (1+1);      // end of combining
		const int j0 =(i+1)/(10+1);      // value ratio < 10
		int comb_tot=0;

		int grade_max=(int)(log2(i+1)+1);          // gems with max grade cannot be destroyed, so this is a max, not a sup
		gem* temp_pools[grade_max-1];              // get the temp pools for every grade
		int  temp_index[grade_max-1];              // index of work point in temp pools
		gem* subpools[grade_max-1];                // get subpools for every grade
		int  subpools_length[grade_max-1];
		for (j=0; j<grade_max-1; ++j) {            // init everything
			temp_pools[j]=malloc(size*sizeof(gem));
			temp_index[j]=0;
			subpools[j]=NULL;                       // just to be able to free it
			subpools_length[j]=0;
		}

		for (j=j0; j<eoc; ++j) {         // combine gems and put them in temp array
			for (k=0; k< pool_length[j]; ++k) {
				int g1=(pool[j]+k)->grade;
				for (h=0; h< pool_length[i-1-j]; ++h) {
					int delta=g1 - (pool[i-1-j]+h)->grade;
					if (abs(delta)<=2) {        // grade difference <= 2
						comb_tot++;
						gem temp;
						gem_combine(pool[j]+k, pool[i-1-j]+h, &temp);
						int grd=temp.grade-2;
						temp_pools[grd][temp_index[grd]]=temp;
						temp_index[grd]++;
						if (temp_index[grd]==size) {							// let's skim a pool
							int length=size+subpools_length[grd];
							gem* temp_array=malloc(length*sizeof(gem));
							int index=0;
							for (l=0; l<size; ++l) {							// copy new gems
								temp_array[index]=temp_pools[grd][l];
								index++;
							}
							temp_index[grd]=0;			// temp index reset
							for (l=0; l<subpools_length[grd]; ++l) {		// copy old gems
								temp_array[index]=subpools[grd][l];
								index++;
							}
							free(subpools[grd]);		// free
							
							gem_sort_crit(temp_array,length);				// work starts
							float lastcrit=-1;
							int tree_cell=0;
							for (int l=0; l<length; ++l) {
								if (temp_array[l].crit == lastcrit) temp_array[l].place=tree_cell-1;
								else {
									temp_array[l].place=tree_cell++;
									lastcrit = temp_array[l].crit;
								}
							}
							gem_sort_exact(temp_array,length);
							int broken=0;
							int tree_length= 1 << (int)ceil(log2(tree_cell));			// this is pow(2, ceil()) bitwise for speed improvement
							float* tree=malloc((tree_length*2)*sizeof(float));
							for (l=0; l<tree_length*2; ++l) tree[l]=-1;					// init also tree[0], it's faster
							for (l=length-1;l>=0;--l) {										// start from large z
								gem* p_gem=temp_array+l;
								if (ftree_check_after(tree, tree_length, p_gem->place, p_gem->bbound)) {
									ftree_add_element(tree, tree_length, p_gem->place, p_gem->bbound);
								}
								else {
									p_gem->grade=0;
									broken++;
								}
							}												// all unnecessary gems destroyed
							free(tree);									// free
							subpools_length[grd]=length-broken;
							subpools[grd]=malloc(subpools_length[grd]*sizeof(gem));	// pool init via broken
							
							index=0;
							for (l=0; l<length; ++l) {			// copying to subpool
								if (temp_array[l].grade!=0) {
									subpools[grd][index]=temp_array[l];
									index++;
								}   
							}
							free(temp_array);			// free
						}									// rebuilt subpool[grd], work restarts
					}
				}
			}
		}
		int grd;
		for (grd=0; grd<grade_max-1; ++grd) {					// let's put remaining gems on
			if (temp_index[grd] != 0) {
				int length=temp_index[grd]+subpools_length[grd];
				gem* temp_array=malloc(length*sizeof(gem));
				int index=0;
				for (l=0; l<temp_index[grd]; ++l) {				// copy new gems
					temp_array[index]=temp_pools[grd][l];
					index++;
				}
				for (l=0; l<subpools_length[grd]; ++l) {		// copy old gems
					temp_array[index]=subpools[grd][l];
					index++;
				}
				free(subpools[grd]);		// free
				
				gem_sort_crit(temp_array,length);				// work starts
				float lastcrit=-1;
				int tree_cell=0;
				for (int l=0; l<length; ++l) {
					if (temp_array[l].crit == lastcrit) temp_array[l].place=tree_cell-1;
					else {
						temp_array[l].place=tree_cell++;
						lastcrit = temp_array[l].crit;
					}
				}
				gem_sort_exact(temp_array,length);
				int broken=0;
				int tree_length= 1 << (int)ceil(log2(tree_cell));			// this is pow(2, ceil()) bitwise for speed improvement
				float* tree=malloc((tree_length*2)*sizeof(float));
				for (l=0; l<tree_length*2; ++l) tree[l]=-1;					// init also tree[0], it's faster
				for (l=length-1;l>=0;--l) {										// start from large z
					gem* p_gem=temp_array+l;
					if (ftree_check_after(tree, tree_length, p_gem->place, p_gem->bbound)) {
						ftree_add_element(tree, tree_length, p_gem->place, p_gem->bbound);
					}
					else {
						p_gem->grade=0;
						broken++;
					}
				}												// all unnecessary gems destroyed
				free(tree);									// free
				subpools_length[grd]=length-broken;
				subpools[grd]=malloc(subpools_length[grd]*sizeof(gem));		// pool init via broken
				index=0;
				for (l=0; l<length; ++l) {			// copying to subpool
					if (temp_array[l].grade!=0) {
						subpools[grd][index]=temp_array[l];
						index++;
					}   
				}
				free(temp_array);			// free
			}									// subpool[grd] is now full
		}
		pool_length[i]=0;
		for (grd=0; grd<grade_max-1; ++grd) pool_length[i]+=subpools_length[grd];
		pool[i]=malloc(pool_length[i]*sizeof(gem));
		
		int place=0;
		for (grd=0;grd<grade_max-1;++grd) {			// copying to pool
			for (j=0; j<subpools_length[grd]; ++j) {
				pool[i][place]=subpools[grd][j];
				place++;
			}   
		}
		for (grd=0;grd<grade_max-1;++grd) {			// free
			free(temp_pools[grd]);
			free(subpools[grd]);
		}

		if (!(output_options & mask_quiet)) {
			printf("Value:\t%d\n",i+1);
			if (output_options & mask_debug) {
				printf("Raw:\t%d\n",comb_tot);
				printf("Pool:\t%d\n\n",pool_length[i]);
			}
		}
		table_write_iteration(pool, pool_length, i, table);			// write on file
	}
	
	fclose(table);			// close
	for (i=0;i<len;++i) free(pool[i]);		// free
}