Exemple #1
0
int mt_recorder_init(size_t width, int capacity, int max){
  int ret = -1;
  if (_N_TABLES == 0){
	  mtrs = malloc(sizeof(mt_record_struct));
	  if(mtrs != NULL )
		  ret = init_table(_N_TABLES,width,capacity,max);
	  if (ret > -1){
		  _N_TABLES++;
	  }
	  else{
		  printf("\nmt_recorder -> unable to allocate table\n");
		  free(mtrs);
	  }
  }
  else if (_N_TABLES > 0){
    mt_record_struct* temp;
	temp = realloc(mtrs,sizeof(mt_record_struct)*(_N_TABLES+1));
	if (temp == NULL){
		ret= -1;
	}
	else{
		mtrs=temp;
		ret = init_table(_N_TABLES,width,capacity,max);
		if(ret > -1){
			_N_TABLES++;
		}
		else{
			printf("\n Unable to allocate table\n");
		}
	}
  }
  return ret;
}
Exemple #2
0
static double Expectation(DdNode **nodes_ex, int lenNodes) {
  int i;
  double rootProb, CLL = 0;

  for (i = 0; i < lenNodes; i++) {
    if (!Cudd_IsConstant(nodes_ex[i])) {
      nodesB = init_table(boolVars_ex[i]);
      nodesF = init_table(boolVars_ex[i]);

      Forward(nodes_ex[i], i);
      rootProb = GetOutsideExpe(nodes_ex[i], example_prob[i], i);

      if (rootProb <= 0.0)
        CLL = CLL + LOGZERO * example_prob[i];
      else
        CLL = CLL + log(rootProb) * example_prob[i];

      nodes_probs_ex[i] = rootProb;
      destroy_table(nodesB, boolVars_ex[i]);
      destroy_table(nodesF, boolVars_ex[i]);
    } else if (nodes_ex[i] == Cudd_ReadLogicZero(mgr_ex[i])) {
      CLL = CLL + LOGZERO * example_prob[i];
      nodes_probs_ex[i] = 0.0;
    } else
      nodes_probs_ex[i] = 1.0;
  }
  return CLL;
}
void initialize_semantic_tables() {
	
	table_numbers = init_table(table_numbers);
	table_reserved_words = init_table(table_reserved_words);
	table_specials = init_table(table_specials);
	table_symbols = init_table(table_symbols);
	
	/* add reserved words */
	add(&table_reserved_words, "functions");
	add(&table_reserved_words, "int");
	add(&table_reserved_words, "char");
	add(&table_reserved_words, "boolean");
	add(&table_reserved_words, "void");
	add(&table_reserved_words, "main");
	add(&table_reserved_words, "begin");
	add(&table_reserved_words, "return");
	add(&table_reserved_words, "if");
	add(&table_reserved_words, "while");
	add(&table_reserved_words, "scan");
	add(&table_reserved_words, "print");
	add(&table_reserved_words, "else");
	add(&table_reserved_words, "not");
	add(&table_reserved_words, "and");
	add(&table_reserved_words, "or");
	add(&table_reserved_words, "call");
	
}
Exemple #4
0
/************************************************************************
* Function: init_tables													
*																		
* Parameters:															
*	none																
*																		
* Description: Initializing tables with HTTP strings and different HTTP 
* codes.																
*																		
* Returns:																
*	 void																
************************************************************************/
static XINLINE void
init_tables( void )
{
    init_table( Http1xxStr, Http1xxCodes, NUM_1XX_CODES );
    init_table( Http2xxStr, Http2xxCodes, NUM_2XX_CODES );
    init_table( Http3xxStr, Http3xxCodes, NUM_3XX_CODES );
    init_table( Http4xxStr, Http4xxCodes, NUM_4XX_CODES );
    init_table( Http5xxStr, Http5xxCodes, NUM_5XX_CODES );

    gInitialized = TRUE;        // mark only after complete
}
Exemple #5
0
void init_rpn()
{

    ERROUT = 1;
    NCON = 0;
    NFUN = 0;
    NVAR = 0;
    NKernel=0;

    MaxPoints=4000;
    NSYM = STDSYM;
    two_args();
    one_arg();
    add_con("PI", M_PI);

        add_con("I'",0.0);
    /*   This is going to be for interacting with the
         animator */
    SumIndex=NCON-1;
        add_con("mouse_x",0.0);
        add_con("mouse_y",0.0);
        add_con("mouse_vx",0.0);
        add_con("mouse_vy",0.0);

    /* end animator stuff */
    /*  add_con("c___1",0.0);
        add_con("c___2",0.0);
        add_con("c___3",0.0); */

    init_table();
    if (newseed==1) RandSeed=time(0);
    nsrand48(RandSeed);
}
TEST dictionnary_insert_u32()
{
  struct nlist * hashtab[HASHSIZE];
  init_table(hashtab);

  uint32_t testvar = 4294967295;

  install(hashtab, "bar", (void*)(&testvar), ptr_u32);

  // Test installed structure can be retrieved
  struct nlist * np = lookup(hashtab, "bar");
  if(np == NULL)
  {
    FAIL();
  }

  ASSERT_EQ(np->ptr_u32, &testvar);

  ASSERT_EQ(np->ptr_f32, NULL);
  ASSERT_EQ(np->ptr_u8, NULL);
  ASSERT_EQ(np->ptr_u16, NULL);
  ASSERT_EQ(np->ptr_i8, NULL);
  ASSERT_EQ(np->ptr_i16, NULL);
  ASSERT_EQ(np->ptr_i32, NULL);
  ASSERT_EQ(np->ptr_function, NULL);

  ASSERT_EQ(*(np->ptr_u32),testvar);

  PASS();
}
TEST dictionnary_insert_function()
{
  struct nlist * hashtab[HASHSIZE];
  init_table(hashtab);

  install(hashtab, "bar", (void*)(callback), ptr_function);

  // Test installed structure can be retrieved
  struct nlist * np = lookup(hashtab, "bar");
  if(np == NULL)
  {
    FAIL();
  }

  ASSERT_EQ(np->ptr_function, callback);

  ASSERT_EQ(np->ptr_f32, NULL);
  ASSERT_EQ(np->ptr_u8, NULL);
  ASSERT_EQ(np->ptr_u16, NULL);
  ASSERT_EQ(np->ptr_u32, NULL);
  ASSERT_EQ(np->ptr_i8, NULL);
  ASSERT_EQ(np->ptr_i16, NULL);
  ASSERT_EQ(np->ptr_i32, NULL);

  PASS();
}
Exemple #8
0
void init_rpn(void) {
  parser_doubles_init(&constants, 0);
  parser_ufuns_init(&ufuns, 0);
  parser_doubles_init(&variables, 0);
  parser_symbols_init(&my_symb, NUM_BUILTIN_SYMBOLS);
  memcpy(parser_symbols_insert(&my_symb, 0, NUM_BUILTIN_SYMBOLS),
         BUILTIN_SYMBOLS, NUM_BUILTIN_SYMBOLS * sizeof(*BUILTIN_SYMBOLS));

  add_con("PI", M_PI);

  add_con("I'", 0.0);
  SumIndex = constants.len - 1;

  add_con("", 0.0);
  shift_index = constants.len - 1;

  /*   This is going to be for interacting with the
       animator */
  add_con("mouse_x", 0.0);
  add_con("mouse_y", 0.0);
  add_con("mouse_vx", 0.0);
  add_con("mouse_vy", 0.0);

  /* end animator stuff */
  /*  add_con("c___1",0.0);
      add_con("c___2",0.0);
      add_con("c___3",0.0); */

  init_table();
}
Exemple #9
0
int main(int argc, char **argv) {
	int port;
	int length;

	init_table(&user_table);
	
	if (argc < 3) {
		port = 21;
		strcpy(filePath, "./tmp/");
	} else if (argc <= 4) {
		port = str_to_int(argv[2]);
		strcpy(filePath, "./tmp/");
	} else if (argc == 5) {
		port = str_to_int(argv[2]);
		strcpy(filePath, ".");
		if (argv[4][0] != '/') {
			strcat(filePath, "/");
		}
		strcat(filePath, argv[4]);
		length = strlen(filePath);
		if (filePath[length - 1] != '/') {
			strcat(filePath, "/");
		}
	}
	
	printf("port: %d\nroot: %s\n", port, filePath);
	
	if (run_ftp(port, command_handler) == STATUS_ERROR) {
		printf("Error building tcp connection!\n");
	}
	return 0;
}
Exemple #10
0
int main(int argc, char *argv[])
{
    init_table();
    if (argc < 2)
    {
        const char **t;
        for (t = tests; *t; t++)
        {
            char src[32], dst[32];
            snprintf(src, sizeof(src), CURDIR"%s.asm", *t);
            snprintf(dst, sizeof(dst), CURDIR"%s.out", *t);
            exec(src, dst);
        }
    }
    else
    {
        int i;
        for (i = 1; i < argc; i++)
        {
            char dst[256];
            int len = strlen(argv[i]);
            if (4 < len && len < sizeof(dst) && strcmp(argv[i] + len - 4, ".asm") == 0)
            {
                strncpy(dst, argv[i], sizeof(dst));
                dst[len - 4] = 0;
                strncat(dst, ".out", sizeof(dst));
            }
            else
                snprintf(dst, sizeof(dst), "%s.out", argv[i]);
            exec(argv[i], dst);
        }
    }
    return 0;
}
Exemple #11
0
int main(int argc, char* argv[])
{
	int type, n_case;

	init_k_table();
	init_table(N);

	scanf("%d", &n_case);
	while (n_case--) {
		scanf("%d %d", &type, &k);
		ans = INF;

		if (type) {
			ans = k_table[k];
		} else {
			dfs(0, 1, 1);
		}

		if (ans == 0) puts("Illegal\n");
		else if (ans >= INF) puts("INF\n");
		else printf ("%lld\n", ans);
	}

	return 0;
}
int main(void){
  int total = 0;

  init_table();
  
  for(int i = 0; i < 3; i++){
    lock_t *l = (lock_t *) surely_malloc(sizeof(lock_t));
    thread_locks[i] = l;
    results[i] = (int *) surely_malloc (sizeof(int));
    makelock((void *)l);
  }

  for(int i = 0; i < 3; i++){
    int *t = (int *) surely_malloc(sizeof(int));
    *t = i;
    spawn((void *)&f, (void *)t);
  }

  for(int i = 0; i < 3; i++){
    lock_t *l = thread_locks[i];
    acquire(l);
    freelock2(l);
    free(l);
    int *r = results[i];
    int i = *r;
    free(r);
    total += i;
  }

  //total should be equal to 3
}
Exemple #13
0
int main(int argv, char **argc)
{
	FILE *input_file;
	char *filename = argc[1];
	struct dev_set_c *set_info;
 	struct table **table_array; /* table_bdev[bdev_nr]*/
	error_t error_msg;

	if ( !(input_file = fopen(filename, "r")) ) {
			printf("No such file %s\n", filename);
			return -1;
	}

	get_devs_info(argv, argc, &set_info);

	alloc_table_array(set_info, &table_array);

	init_table(set_info, table_array);
	
	if ( map(input_file, set_info, table_array) < 0) {
		printf("[ERROR] : can not do mapping workload to  your device\n");	
		return -1;
	}

	print_devs_info(set_info);

	print_table(set_info, table_array);

	
	//ratio = find_scale_ratio(set_info, &last_blk_info);

	//printf("%lf %u %llu %u %x\n", one_req_info.time, one_req_info.devno, one_req_info.blkno, one_req_info.bcount, one_req_info.is_read);

	return 0;
}
Exemple #14
0
  void extend(table* old) {
    table& old_table = *old;
    std::lock_guard<std::mutex> lock(extend_lock_);
    if (table_.load() != &old_table) { return; }

    std::vector<std::lock_guard<std::mutex>> lock_array;
    for (auto& slot_lock : lock_table_) {
      slot_lock.lock();
    }

    const size_t new_size = old_table.size * 2;
    std::unique_ptr<table> new_table_ptr(init_table(new_size, 0));
    table& new_table = *new_table_ptr;
    for (size_t i = 0; i < old_table.size; ++i) {
      kvp* target = old_table[i];
      while (target != nullptr) {
        const size_t new_hash = MurmurHash2A(&target->key, sizeof(int), 0);
        const size_t slot = new_hash % new_size;
        std::unique_ptr<kvp> entry(new kvp(target->key, target->value));

        kvp* orig = new_table[slot];
        new_table[slot] = entry.get();
        entry->next = orig;
        new_table.add_entry();
        entry.release();

        target = target->next;
      }
    }
    table_.store(new_table_ptr.release());

    for (auto& slot_lock : lock_table_) {
      slot_lock.unlock();
    }
  }
Exemple #15
0
static struct node *
expand_search(struct map *m,struct key *key)
{	
	int i;
	int s=m->size;
	struct node *old=m->buffer;

	struct node *buffer=(struct node*)memoryAlloc(m->size*2*sizeof(struct node));
	if (buffer==0) {
		return 0;
	}

	m->size*=2;
	m->freenode=0;
	m->buffer=buffer;
	init_table(m);

	for (i=0;i<s;i++) {
		if (old[i].value!=0) {
			map_search(m,old[i].key)->value = old[i].value;
		}
	}

	memoryFree(old);

	return map_search(m,key);
}
Exemple #16
0
void	win_game()
{
	GtkWidget*	table;
	GtkWidget*	window;
	GtkWidget*	vbox;
	char**		map;
	int		player;
	t_pos**		pos;

	player = 1;
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window), "Reversi");
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
	gtk_window_set_default_size(GTK_WINDOW(window), 500, 500);
	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(quit), 0);
	vbox = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(window), vbox);
	create_menu_bar(vbox, window);
	table = gtk_table_new(8, 8, TRUE);
	gtk_container_add(GTK_CONTAINER(vbox), table);
	map = init_table();
	pos = create_pos();
	new_button(table, pos, map, &player);
	gtk_widget_show_all(window);
	gtk_main();
	free_pos(pos);
	free_table(map);
}
Exemple #17
0
/*
 * TODO: output the table (possibly merged), in the input format 
 */
int 
main (int argc, char* argv [])
{
	init_table ();
	if (argc == 2) {
		/* useful to get a new file when some opcodes are added: looses the comments, though */
		load_file (argv [1]);
		dump ();
	} else if (argc < 4) {
		g_print ("Usage: genmdesc arguments\n");
		g_print ("\tgenmdesc desc     Output to stdout the description file.\n");
		g_print ("\tgenmdesc [--nacl] output name desc [desc1...]\n"
			"                     Write to output the description in a table named 'name',\n"
			"                     use --nacl to generate Google NativeClient code\n");
		return 1;
	} else {
		int i = 3;
		if (strcmp (argv [1], "--nacl") == 0) {
			nacl = 1;
			i++;
		}
		
		for (; i < argc; ++i)
			load_file (argv [i]);
		
		build_table (argv [1 + nacl], argv [2 + nacl]);
	}
	return 0;
}
Exemple #18
0
void init_count(Sentence sent)
{
	if (NULL == sent->count_ctxt)
		sent->count_ctxt = (count_context_t *) malloc (sizeof(count_context_t));
	memset(sent->count_ctxt, 0, sizeof(count_context_t));

	init_table(sent);
}
Exemple #19
0
void
gnc_search_core_initialize (void)
{
    g_return_if_fail (typeTable == NULL);

    typeTable = g_hash_table_new (g_str_hash, g_str_equal);
    init_table ();
}
Exemple #20
0
static u16
init_unknown_script(struct nouveau_bios *bios)
{
	u16 len, data = init_table(bios, &len);
	if (data && len >= 16)
		return nv_ro16(bios, data + 14);
	return 0x0000;
}
Exemple #21
0
Trie *init_trie(CalcPrefixFunc addPrefixFunc, CalcPrefixFunc findPrefixFunc) {
	Trie *trie = alloc_trie();
	trie->root = alloc_trie_node();
	trie->table = init_table();
	trie->addPrefixFunc = addPrefixFunc;
	trie->findPrefixFunc = findPrefixFunc;
	return trie;
}
Exemple #22
0
int init_int()
{
	Global = init_table("Global");
	//add_to_table( Global , new_var_t( "^_^" , NULL ));	//Dummy varialbe
	Strings = init_element_table("String");
	//add_to_table( Strings , new_var_t( "^_^" , NULL ));	//Dummy string
	return 0;
}
Exemple #23
0
/* sent_length is used only as a hint for the hash table size ... */
count_context_t * alloc_count_context(size_t sent_length)
{
	count_context_t *ctxt = (count_context_t *) xalloc (sizeof(count_context_t));
	memset(ctxt, 0, sizeof(count_context_t));

	init_table(ctxt, sent_length);
	return ctxt;
}
Exemple #24
0
void bfsFindExit(Maze &M)
{
	queue <Position> Q;
	
	vector<vector<Position> > pred;
	init_table(pred, M.size, NULLPOS);
	Position current, nbr;
	stack<Position> path;
	current = M.start;
	M.visit(current);
	Q.push(current);
	
	while (true)
	{
		/* First condition if the current position is the exit*/
		if (current == M.exitpos)
		{
			cout << endl;
			printPath(pred, current);
			return;

		}
		/* Checking if current is a wall*/
		if (current == NULLPOS)
		{
			cout << "Now way out" << endl;
			return;

		}
		/* Getting the first open neighbor */
		nbr = M.getOpenNeighbor(current);
		/* If neighbor is a wall*/
		if (nbr == NULLPOS)
		{
			Q.pop();
			current = Q.front();
			
			continue;
		}
		/* Otherwise set entry and visit neighbor*/
		else
		{
			setEntry(pred, nbr, current);
			M.visit(nbr);
			current = nbr;
			Q.push(nbr);
		}

		
		

	}
	
	
	system("PAUSE");

}
Exemple #25
0
int main(int argc, char *argv[])
// arg1: serial device file
// arg2: optional timeout in seconds, default 60
// arg3: optional 'nolog' to carry on when filesystem full
{
    int commfd = 0;
	int option;                             // command line processing
	int baud = 9600;
	char * cp;
	char table[128];
	int flags = CS8 | CLOCAL | CREAD;
	
    char * serialName = SERIALNAME;
	
	memset(table, 0, 128);
	// Command line arguments
	
	init_table(table);
	opterr = 0;
	while ((option = getopt(argc, argv, "b:dVcs:?")) != -1) {
		DEBUG fprintf(stderr, "Option %c ", option);
		switch (option) {
			case 'b': baud = atoi(optarg); break;
			case 'c': flags |= CRTSCTS; break;
			case '?': usage(); exit(1);
			case 's': serialName = optarg; break;
			case 'd': debug++; break;
			case 'V': printf("Version: %s\n", VERSION); exit(0);
		}
	}
	
	// Open serial port
#ifdef DEBUGCOMMS
	commfd = 0;
#else
	if ((commfd = openSerial(serialName, baud, 0, flags, 1)) < 0) {
		fprintf(stderr, "ERROR 7seg Failed to open %s at %d: %s", serialName, baud, strerror(errno));
		exit(1);
	}
	
#endif
	DEBUG2 fprintf(stderr, "Serial port %s open ...", serialName);
	
	// Send data
	while (optind < argc) {		// remainder of command line must be bytes
		for (cp = argv[optind]; *cp; cp++) {
				DEBUG fprintf(stderr, "'%c' [%02x] ", *cp, table[*cp]);
			sendSerial(commfd, table[*cp]);
		}
		optind++;
	}
	DEBUG fprintf(stderr, "\n");
	
	closeSerial(commfd);
	
	return 0;
}
/*-------------------------------------------------------------------------
 * Function:    init_objs
 *
 * Purpose:     Initialize tables for groups, datasets & named datatypes
 *
 * Return:      Success:    SUCCEED
 *
 *              Failure:    FAIL
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t
init_objs(hid_t fid, find_objs_t *info, table_t **group_table,
    table_t **dset_table, table_t **type_table)
{
    /* Initialize the tables */
    init_table(group_table);
    init_table(dset_table);
    init_table(type_table);

    /* Init the find_objs_t */
    info->fid = fid;
    info->group_table = *group_table;
    info->type_table = *type_table;
    info->dset_table = *dset_table;

    /* Find all shared objects */
    return(h5trav_visit(fid, "/", TRUE, TRUE, find_objs_cb, NULL, info));
}
Exemple #27
0
Table *new_table(size_t entry_size)
{
     Table *t;
     
     t = wtmalloc(sizeof(Table));
     init_table(t, entry_size);

     return t;
}
Exemple #28
0
int game( void ) {


    init_table();


    print_table();
    
    return 0;
}
Exemple #29
0
remember_table::remember_table(unsigned s, unsigned as, unsigned strat)
  : max_assoc_size(as), remember_strategy(strat)
{
	// we keep max_assoc_size and remember_strategy if we need to clear
	// all entries
	
	// use some power of 2 next to s
	table_size = 1 << log2(s);
	init_table();
}
void init_layer12_stuff(mpg123_handle *fr, real* (*init_table)(mpg123_handle *fr, real *table, double m))
{
	int k;
	real *table;
	for(k=0;k<27;k++)
	{
		table = init_table(fr, fr->muls[k], mulmul[k]);
		*table++ = 0.0;
	}
}