Beispiel #1
0
symb_data symb_sum(symb_data S1, int del1, symb_data S2, int del2)
{
  symb_data ans={{NULL},errortp}, s1,s2;
  set index1,index2;
    
  if( S1.type==errortp || S2.type==errortp  
    ||S1.type==indextp || S2.type==indextp) return ans; 
 
  if(S1.expr.p==NULL)
  { if(del2) return S2; else return symb_copy(S2);}

  if(S2.expr.p==NULL)
  { if(del1) return S1; else return symb_copy(S1);}

 
  index1= symb_index(S1);
  index2= symb_index(S2); 
  
  if(!set_eq(index1,index2)) 
  {  
      printf("index problem\n");
      set_print(index1);
       set_print(index2);
        return ans;
         
  }

  if(S1.expr.p==S2.expr.p)
  { S2=symb_copy(S2); 
    del1=(del1||del2);
    del2=1;
  }

  if(S1.type<S2.type)
  {  symb_data S=S1;
     int del=del1;
     S1=S2; S2=S;
     del1=del2; del2=del;
  }
  
  if(S1.type>S2.type)                      
  {    
    s2=symb_typeUp(S2,del2,S1.type);
    if(s2.type==errortp) return ans; 
  } else 
  if(del2) s2=S2; else s2=symb_copy(S2);   
  if(del1) s1=S1; else s1=symb_copy(S1); 

  switch(s1.type)
  {      
     case numbertp : 
     case polytp   : sewpoly(&s1.expr.p,&s2.expr.p);   break;         
     case vectortp :
     case tenstp   : sewtens(&s1.expr.t,&s2.expr.t);   break;
     case spintp   : addSpin(&s1.expr.s,s2.expr.s);    break;
     case etenstp  : addEtens(&s1.expr.et,s2.expr.et); break;
   } 
 
   return s1;
}
Beispiel #2
0
void test_set_operations(){
	set_t *even1 = new_set(10);
	set_t *even2 = new_set(10);
	set_t *odd  = new_set(10);
	
	int i;
	for (i=0; i < 10; i++){
		set_put(even1, 2*i);
		set_put(even2, 2*i);
		set_put(odd, 2*i+1);
	}
	
	set_union(even1, odd);
	assert(set_size(even1) == 20);
	
	set_difference(even2, odd);
	assert(set_size(even2) == 10);
	
	set_intersection(even2, odd);
	assert(set_size(even2) == 0);
	
	set_print(even1); printf("\n");
	set_optimize(even1);
	set_print(even1); printf("\n");
	
	set_print(even2); printf("\n");
	set_print(odd); printf("\n");
	
	delete_set(even1);
	delete_set(even2);
	delete_set(odd);
}
int main(void) 
{
  set s1, s2;
  int m = 10;

  s1 = set_init(m);
  set_add(s1, 1);
  set_add(s1, 3);
  set_add(s1, 5);
  s2 = set_init(m + 2);
  set_add(s2, 0);
  set_add(s2, 2);
  set_add(s2, 3);
  set_add(s2, 4);
  set_add(s2, 5);
  set_add(s2, 11);
  set_print(s1);
  printf("\n");
  set_print(s2);
  printf("\nIntersection: ");
  set_print(set_intersection(s1, s2));
  printf("\nUnion: ");
  set_print(set_union(s1, s2));
  printf("\nComplement for s2: ");
  set_print(set_complement(s2));
  printf("\n");  
  return 0;
}
Beispiel #4
0
int main(void) {
	Heap object;
	unsigned int x, y;
	unsigned int value;
	memset(&object,0,sizeof(object));
	x = RUNS;
	construct(Heap,&object,sizeof(x),FREEOBJ);
	set_alloc(Heap,  &object, ckalloc);
	set_dealloc(Heap,  &object, ckfree);
	set_compare(Heap,  &object, intcmp);
	set_print(Heap,  &object, print);
	for(y = 0; y < x; y++) {
		srand((x * y) / (x - y) + (x + y / x));
		switch((rand() % NUMCASES) + BASE) {
			case 0:
				value = rand() % BOUND + 1;
				insert(Heap,&object,&value,STATIC);
				break;
			case 1:
				pop(Heap,&object);
				break;
			default:
				break;
		};
	}
	/*print_all(Heap,&object);
	dump(Heap,&object);*/
	destruct(Heap,&object);
	return EXIT_SUCCESS;
}
Beispiel #5
0
/* SYNTAX: SET [-clear] [<key> [<value>] */
static void cmd_set(char *data)
{
    GHashTable *optlist;
    GSList *sets, *tmp;
    const char *last_section;
    char *key, *value;
    void *free_arg;
    int found, clear;

    if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS,
                        "set", &optlist, &key, &value))
        return;

    clear = g_hash_table_lookup(optlist, "clear") != NULL;

    last_section = "";
    found = 0;
    sets = settings_get_sorted();
    for (tmp = sets; tmp != NULL; tmp = tmp->next) {
        SETTINGS_REC *rec = tmp->data;

        if (((clear || *value != '\0') && g_strcasecmp(rec->key, key) != 0) ||
                (*value == '\0' && *key != '\0' && stristr(rec->key, key) == NULL))
            continue;

        if (strcmp(last_section, rec->section) != 0) {
            /* print section */
            printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%_[ %s ]", rec->section);
            last_section = rec->section;
        }

        if (clear || *value != '\0') {
            /* change the setting */
            switch (rec->type) {
            case SETTING_TYPE_BOOLEAN:
                set_boolean(key, clear ? FALSE : value);
                break;
            case SETTING_TYPE_INT:
                settings_set_int(key, clear ? 0 : atoi(value));
                break;
            case SETTING_TYPE_STRING:
                settings_set_str(key, clear ? "" : value);
                break;
            }
            signal_emit("setup changed", 0);
        }

        set_print(rec);
        found = TRUE;

        if (clear || *value != '\0')
            break;
    }
    g_slist_free(sets);

    if (!found)
        printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown setting %s", key);

    cmd_params_free(free_arg);
}
Beispiel #6
0
/* SYNTAX: TOGGLE <key> [on|off|toggle] */
static void cmd_toggle(const char *data)
{
	char *key, *value;
	void *free_arg;
	int type;

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_STRIP_TRAILING_WS, &key, &value))
		return;

	if (*key == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	type = settings_get_type(key);
	if (type == SETTING_TYPE_ANY)
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_UNKNOWN, key);
	else if (type != SETTING_TYPE_BOOLEAN)
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_NOT_BOOLEAN, key);
	else {
		set_boolean(key, *value != '\0' ? value : "TOGGLE");
		set_print(settings_get_record(key));
		signal_emit("setup changed", 0);
	}

	cmd_params_free(free_arg);
}
Beispiel #7
0
void optionStatus(Option& opt,
                  CmdOptions& opts)
{
  set_print(true);
  opts.time = true;

  if (!opt.val.empty())
    set_status_precision(opt.to<int>());
}
Beispiel #8
0
/*
 * db_seq_print() - This is debug function to print out a simple description of
 *    a sequence.
 * return : error code
 * set(in): sequence descriptor
 */
int
db_seq_print (DB_SET * set)
{
  CHECK_CONNECT_ERROR ();
  CHECK_1ARG_ERROR (set);

  set_print (set);

  return (NO_ERROR);
}
Beispiel #9
0
/*
 * db_set_print() - This is a debugging function that prints a simple
 *    description of a set. This should be used for information purposes only.
 * return : error code
 * set(in): set descriptor
 */
int
db_set_print (DB_SET * set)
{
  CHECK_CONNECT_ERROR ();
  CHECK_1ARG_ERROR (set);

  /* allow all types */
  set_print (set);

  return (NO_ERROR);
}
Beispiel #10
0
/* Prints values of all options. */
static void
print_options(void)
{
	int i;
	for(i = 0; i < options_count; i++)
	{
		if(options[i].full != NULL)
			continue;
		set_print(&options[i]);
	}
}
Beispiel #11
0
void
set_list(void)
{
	set_t		  *set_p;

	set_p = (set_t *) & g_setlist;
	while ((set_p = (set_t *) queue_next(&g_setlist, &set_p->qn))) {
		(void) printf("$%-8s ", set_p->setname_p);
		set_print(stdout, set_p);
		(void) printf("\n");
	}

}				/* end set_list */
Beispiel #12
0
void
set_test()
{
	printf("SET S: ");
	set* s = set_init();
	set_add(s, (SETDATA*)1);
	set_add(s, (SETDATA*)2);
	set_add(s, (SETDATA*)3);
	set_add(s, (SETDATA*)4);
	set_add(s, (SETDATA*)5);
	set_add(s, (SETDATA*)6);
	set_print(s, set_testcb);

	printf("S \\ 2, 6: ");
	set_remove(s, (SETDATA*)6);
	set_remove(s, (SETDATA*)2);
	set_print(s, set_testcb);
	
	printf("SET T: ");
	set* t = set_init();
	set_add(t, (SETDATA*)1);
	set_add(t, (SETDATA*)2);
	set_add(t, (SETDATA*)9);
	set_add(t, (SETDATA*)4);
	set_print(t, set_testcb);
	
	printf("UNION OF S, T: ");
	set* u = set_init();
	set_union(u, s, t);
	set_print(u, set_testcb);
	
	printf("INTERSECTION OF S, T: ");
	set* i = set_init();
	set_intersection(i, s, t);
	set_print(i, set_testcb);
	
	printf("DIFFERENCE OF S, T: ");
	set* d = set_init();
	set_difference(d, s, t);
	set_print(d, set_testcb);
	
	printf("CLEAR S: ");
	set_clear(s);
	set_print(s, set_testcb);
	
	set_free(s);
	set_free(t);
	set_free(u);
	set_free(i);
	set_free(d);
}
Beispiel #13
0
int main(int argc, char *argv[]) {
    graph_t *g;
    set_t s;

    if (argc!=2) {
        fprintf(stderr,"%s <dimacs_file>\n",argv[0]);
        return 1;
    }
    g=graph_read_dimacs_file(argv[1]);
    if (g==NULL)
        return 1;

    ASSERT(graph_test(g,stderr));

    s=clique_find_single(g,0,0,FALSE,NULL);
    set_print(s);

    return 0;
}
Beispiel #14
0
static void set_print_pattern(const char *pattern)
{
	GSList *sets, *tmp;
	const char *last_section;

	last_section = "";
	sets = settings_get_sorted();
	for (tmp = sets; tmp != NULL; tmp = tmp->next) {
		SETTINGS_REC *rec = tmp->data;

		if (stristr(rec->key, pattern) == NULL)
			continue;
		if (g_strcmp0(last_section, rec->section) != 0) {
			/* print section */
			printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
				    TXT_SET_TITLE, rec->section);
			last_section = rec->section;
		}
		set_print(rec);
	}
	g_slist_free(sets);
}
Beispiel #15
0
/* SYNTAX: TOGGLE <key> [on|off|toggle] */
static void cmd_toggle(const char *data)
{
    char *key, *value;
    void *free_arg;
    int type;

    if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &key, &value))
        return;

    if (*key == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

    type = settings_get_type(key);
    if (type == -1)
        printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown setting %_%s", key);
    else if (type != SETTING_TYPE_BOOLEAN)
        printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Setting %_%s%_ isn't boolean, use /SET", key);
    else {
        set_boolean(key, *value != '\0' ? value : "TOGGLE");
        set_print(settings_get_record(key));
    }

    cmd_params_free(free_arg);
}
Beispiel #16
0
void symbol_print(FILE* fp, const Symbol* sym)
{
   static const char* const type_name[] = { "Error", "Numb", "Strg", "Set", "Var" };
   
   int i;
   
   assert(symbol_is_valid(sym));

   fprintf(fp, "Name  : %s\n", sym->name);
   fprintf(fp, "Type  : %s\n", type_name[sym->type]);

   fprintf(fp, "Index : ");
   set_print(fp, sym->set);
   fprintf(fp, "\nEntries:\n");
   
   for(i = 0; i < sym->used; i++)
   {
      fprintf(fp, "\t%3d: ", i);
      entry_print(fp, sym->entry[i]);
      fprintf(fp, "\n");
   }
   fprintf(fp, "\n");
}
Beispiel #17
0
/* Prints options, which value differs from the default one. */
static void
print_changed_options(void)
{
	int i;
	for(i = 0; i < options_count; i++)
	{
		opt_t *opt = &options[i];

		if(opt->full != NULL)
			continue;

		if(opt->type == OPT_STR || opt->type == OPT_STRLIST)
		{
			if(strcmp(opt->val.str_val, opt->def.str_val) == 0)
				continue;
		}
		else if(opt->val.int_val == opt->def.int_val)
		{
			continue;
		}

		set_print(&options[i]);
	}
}
Beispiel #18
0
int main(int argc, char **argv)
{

    FILE *infile;
    FILE *outfile;

    char *infilename = NULL;
    char *outfilename = NULL;

    serializable input = serializableNIL;
    serializable output = serializableNIL;

    print_state st;

    int option_index = 0;
    int c;

    struct option long_options[] = {
        {"help", 0, 0, 'h'},
        {"version", 0, 0, 'v'},
        {0, 0, 0, 0}
    };

    while ((c = getopt_long(argc, argv, "h?v", long_options, &option_index)) != -1) {
        switch (c) {
            case 0:
                break;
            case 'h':
                usage(stdout);
                return EXIT_SUCCESS;
            case 'v':
                version(stdout);
                return EXIT_SUCCESS;
            default:
                help(stderr);
                return EXIT_FAILURE;
        }
    }

    infile = stdin;
    outfile = stdout;

    if (optind < argc) {
        infilename = strdup(argv[optind++]);
    }
    if (optind < argc) {
        outfilename = strdup(argv[optind++]);
    }

    if (infilename != NULL && 0 != strcmp(infilename, "-")) {
        infile = ckfopen(infilename, "r");
    }
    if (outfilename != NULL) {
        outfile = ckfopen(outfilename, "w");
    }

    init_symtbl();
    if (!fscan_serializable(infile, &input)) {
        fprintf(stderr,
                "Error parsing `%s': %s in line %d.\n",
                infilename,
                errmsg,
                lineno);
        destroy_symtbl();
        return EXIT_FAILURE;
    }
    st = set_print(outfile, 1, 75, 8);
    if (serializableNIL == input) {
        fprint_serializable(st, serializableNIL);
        end_print(st);
        destroy_symtbl();
        return EXIT_SUCCESS;
    }
    if (input->tag != TAGtv_cnf_flat_kb && input->tag != TAGtv_cnf_hierarchy) {
        fprintf(stderr, "Input is not in CNF.\n");
        rfre_serializable(input);
        destroy_symtbl();
        return EXIT_FAILURE;
    }

    cnf2horn_init();
    cnf2horn(input, &output);
    cnf2horn_destroy();
    rfre_serializable(input);

    fprint_serializable(st, output);
    rfre_serializable(output);

    end_print(st);
    destroy_symtbl();

    return EXIT_SUCCESS;
}
Beispiel #19
0
int main() {
  set<int> A,B,C,Acpy;
  aed::set<int> AA,BB,CC,AAcpy;
  int N=1024*256, m=3, M=100;
  double avdepth = 0.0, avdepthlv=0.0;
  for (int k=0; k<M; k++) {
    AA.clear();
    for (int j=0; j<N; j++) {
      int x = irand(m*N);
      AA.insert(x);
    }
    double ad,adlv;
    avheight(AA.tree(),ad,adlv);
    cout << "ad: " << ad << " ,adlv: " << adlv << endl;
    avdepth += ad;
    avdepthlv += adlv;
  }
  cout << "avrg depth: " << avdepth/double(M) << endl;
  cout << "min. avrg depth: " << log2(double(N))-1 << endl;

  cout << "avrg depth leaves: " << avdepthlv/double(M) << endl;
  cout << "min. avrg depth leaves: " << log2(double(N)) << endl;

#if 0
  cout << "insertando ";
  for (int j=0; j<N; j++) {
    int x = irand(m*N);
    cout << x << endl;
    A.insert(x);
    AA.insert(x);
    x = irand(m*N);
    B.insert(x);
    BB.insert(x);
  }
  cout << endl;
  print_tree(AA.tree());

  assert(are_equal(AA,A));
  assert(are_equal(BB,B));

  set_print(A);
  set_print(AA);

#define VER_ABB(T)					\
  cout << #T " is abb: " << abb_p(T.tree()) << endl;	\
  assert(abb_p(T.tree()))

  VER_ABB(AA);
  VER_ABB(BB);

  for (int j=0; j<m*N; j++) {
    bool inA = (A.find(j)!=A.end());
    bool inAA = (AA.find(j)!=AA.end());
    if (inA != inAA) 
      cout << "in A: " << inA 
	   << "in AA: " << inAA << endl;
  }

  Acpy = A;
  AAcpy = AA;
  assert(are_equal(AAcpy,Acpy));
  VER_ABB(AAcpy);

  for (int j=0; j<m*N; j++) {
    A.erase(2*j);
    AA.erase(2*j);
  }
  assert(are_equal(AA,A));

  cout << "Eliminados los elementos pares\n";
  set_print(A);
  set_print(AA);
  VER_ABB(AA);

  A = Acpy;
  AA = AAcpy;

  cout << "Recupera elementos\n";
  set_print(A);
  set_print(AA);
  assert(are_equal(AA,A));
  VER_ABB(AA);

  cout << "B\n";
  set_print(B);
  set_print(BB);
  VER_ABB(BB);

  aed::set_union(AA,BB,CC);
  C.clear();
  set_union(A.begin(),A.end(),
	    B.begin(),B.end(),inserter(C,C.begin()));
  assert(are_equal(CC,C));
  VER_ABB(CC);

  cout << "C = A union B\n";
  set_print(C);
  set_print(CC);

  aed::set_intersection(AA,BB,CC);
  C.clear();
  set_intersection(A.begin(),A.end(),
		   B.begin(),B.end(),inserter(C,C.begin()));
  assert(are_equal(CC,C));
  VER_ABB(CC);

  cout << "C = A intersection B\n";
  set_print(C);
  set_print(CC);

  aed::set_difference(AA,BB,CC);
  C.clear();
  set_difference(A.begin(),A.end(),
		 B.begin(),B.end(),inserter(C,C.begin()));
  assert(are_equal(CC,C));
  VER_ABB(CC);

  cout << "C = A - B\n";
  set_print(C);
  set_print(CC);

  aed::set_difference(BB,AA,CC);
  C.clear();
  set_difference(B.begin(),B.end(),
		 A.begin(),A.end(),inserter(C,C.begin()));
  assert(are_equal(CC,C));
  VER_ABB(CC);

  cout << "C = B - A \n";
  set_print(C);
  set_print(CC);
#endif
}
Beispiel #20
0
void fe_settings_set_print(const char *key)
{
	set_print(settings_get_record(key));
}
Beispiel #21
0
int main(int argc, char **argv)
{
    extern int optind;
    extern char *optarg;

    print_state st;

    serializable input, output;

    char *p = NULL;

    int simplify = 1;
    int verbose = 0;
    int hier = 0;
    int c;

    unsigned int depth = 1;

    while ((c = getopt(argc, argv, "s:h?vVS")) != -1) {
        switch (c) {
            case 0:
                break;
            case 's':
                hier = 1;
                if (NULL == optarg) {
                    fprintf(stderr, "Missing inlining depth. Try `smoothy -h' for more information.\n");
                }
                depth = strtol(optarg, &p, 10);
                if (p == NULL || *p != '\0') {
                    fprintf(stderr, "Bad inlining depth. Try `smoothy -h' for more information.\n");
                }
                break;
            case 'S':
                simplify = 0;
                break;
            case 'V':
                verbose = 1;
                break;
            case '?':
            case 'h':
                usage(stdout);
                return EXIT_FAILURE;
            case 'v':
                version(stdout);
                return EXIT_SUCCESS;
            default:
                fprintf(stderr, "Try `smoothy -h' for more information.\n");
                return EXIT_FAILURE;
        }
    }

    infile = stdin;
    outfile = stdout;

    if (optind < argc) {
        infilename = strdup(argv[optind++]);
    }
    if (optind < argc) {
        outfilename = strdup(argv[optind++]);
    }

    if (infilename != NULL && 0 != strcmp(infilename, "-")) {
        infile = ckfopen(infilename, "r");
    }
    if (outfilename != NULL) {
        outfile = ckfopen(outfilename, "w");
    }

    st = set_print(outfile, 1, 75, 8);

    init_symtbl();
    input = serializableNIL;
    if (!fscan_serializable(infile, &input)) {
        fprintf(stderr, "smoothy: %d: %s\n", lineno, errmsg);
        destroy_symtbl();
        return EXIT_FAILURE;
    }
    output = serializableNIL;

    smoothy_init();
    if (!smoothy(input, hier, depth, verbose, simplify, &output)) {
        destroy_symtbl();
        return EXIT_FAILURE;
    }

    if (verbose) {
        display_stat_items(stderr);
    }
    smoothy_destroy();

    rfre_serializable(input);
    fprint_serializable(st, output);
    rfre_serializable(output);
    end_print(st);
    destroy_symtbl();

    return EXIT_SUCCESS;
}
Beispiel #22
0
/* Calculates the value of FOLLOW for all nonterminals (and terminals
   while we're at it, but they're not useful).  Sets
   symbols[].follow. */
static void
precalc_follow (void)
{
  int i;

  for (i = 0; i < n_symbols; i++)
    set_init (&symbols[i].follow);

  set_add (&find_symbol (G[0].left)->follow, '$');

  for (;;)
    {
      int added = 0;
      
      for (i = 0; i < n_grammar; i++)
	{
	  const struct production *prod;
	  struct symbol *A;
	  int j;

	  prod = &G[i];
	  A = find_symbol (prod->left);
	  for (j = 0; j < prod->n_right - 1; j++)
	    {
	      struct symbol *B;
	      struct set first_Beta;

	      B = find_symbol (prod->right[j]);
	      calc_first (&first_Beta,
			  &prod->right[j + 1], prod->n_right - (j + 1));
	      added |= set_merge (&B->follow, &first_Beta, 0);

	      if (set_contains (&first_Beta, 0))
		added |= set_merge (&B->follow, &A->follow, 1);

	      set_free (&first_Beta);
	    }
	  
	  if (prod->n_right > 0)
	    {
	      struct symbol *B = find_symbol (prod->right[prod->n_right - 1]);
	      added |= set_merge (&B->follow, &A->follow, 1);
	    }
	}

      if (!added)
	break;
    }

  if (debug) 
    {
      printf ("FOLLOW function:\n");
      for (i = 0; i < n_symbols; i++)
	{
	  struct symbol *sym = &symbols[i];

	  if (!sym->nonterminal)
	    continue;
	  printf ("\tFOLLOW(%c) = ", sym->sym);
	  set_print (&sym->follow);
	  putchar ('\n');
	}
    }
}
Beispiel #23
0
/* Calculate the value of FIRST for all grammar symbols.  Sets
   symbol[].first. */
static void
precalc_first (void)
{
  int i;

  for (i = 0; i < n_symbols; i++)
    {
      set_init (&symbols[i].first);

      if (symbols[i].nonterminal)
	{
	  size_t j;

	  for (j = 0; j < n_grammar; j++)
	    if (G[j].left == symbols[i].sym
		&& G[j].n_right == 0)
	      {
		set_add (&symbols[i].first, 0);
		break;
	      }
	}
      else
	set_add (&symbols[i].first, symbols[i].sym);
    }
  
  for (;;)
    {
      int added = 0;

      for (i = 0; i < n_grammar; i++)
	{
	  struct production *prod = &G[i];
	  struct symbol *X = find_symbol (prod->left);
	  int j;

	  for (j = 0; j < prod->n_right; j++)
	    {
	      struct symbol *Y;
	      int k;

	      Y = find_symbol (prod->right[j]);
	      for (k = 0; k < Y->first.n; k++)
		if (Y->first.which[k] != 0)
		  added |= set_add (&X->first, Y->first.which[k]);

	      if (!set_contains (&X->first, 0))
		break;
	    }
	  if (j >= prod->n_right)
	    added |= set_add (&X->first, 0);
	}

      if (!added)
	break;
    }

  if (debug)
    {
      printf ("FIRST function:\n");
      for (i = 0; i < n_symbols; i++)
	{
	  struct symbol *sym = &symbols[i];
	
	  printf ("\tFIRST(%c) = ", sym->sym);
	  set_print (&sym->first);
	  putchar ('\n');
	}
    }
}
int
main(void) {
  QueueVector  object;
  QueueVectorIter *ptr;
  unsigned int x, y;
  unsigned int value;
  memset(&object, 0, sizeof (object));
  x = RUNS;
  construct(QueueVector, &object,sizeof(x),FREEOBJ);
  set_alloc(QueueVector,  &object, ckalloc);
  set_dealloc(QueueVector,  &object, ckfree);
  set_compare(QueueVector,  &object, intcmp);
  set_print(QueueVector,  &object, print);
  for (y = 0; y < x; y++) {
    srand((x * y) / (x - y) + (x + y / x));
    switch ((rand() % NUMCASES) + BASE) {
        case 0:
        case 10:
        case 11:
        case 1:
        case 12:
        case 13:
        case 2:
        case 14:
          value = rand() % BOUND;
          push(QueueVector,  &object, &value, DYNAMIC);
          break;
        case 3:
        case 15:
        case 4:
        case 5:
        case 6:
        case 16:
          pop(QueueVector,  &object);
          break;
        case 7:
        case 17:
        case 8:
        case 9:
          front(QueueVector,  &object);
          break;
        default:
          break;
    };
  }
  destruct(QueueVector,  &object);
  fprintf(stderr, "Now testing the iterators!\n");
  construct_func(QueueVector,&object,sizeof(x),FREEOBJ, ckalloc, ckfree, intcmp, print,
                 memcpy);
  for (x = 0; x < RUNS; x++) {
	  value = rand();
    push(QueueVector,  &object, &value, STATIC);
  }

  ptr = create(QueueVectorIter,  &object);
  head(QueueVectorIter, ptr);
  do {
    value = *(unsigned int *) retrieve(QueueVectorIter, ptr);
  }
  while (!next(QueueVectorIter, ptr));
  assign(QueueVectorIter, ptr, &object);
  tail(QueueVectorIter, ptr);
  do {
    value = *(unsigned int *) retrieve(QueueVectorIter, ptr);
  } while (!prev(QueueVectorIter, ptr));
  for(x = 0; x < RUNS; x++) {
	  switch(rand() % 2) {
		  case 1:
			  next(QueueVectorIter,ptr);
			  break;
		  case 2:
			  prev(QueueVectorIter,ptr);
			  break;
	  }
  }
  destroy(QueueVectorIter, ptr);
  destruct(QueueVector,  &object);
  return EXIT_SUCCESS;
}
Beispiel #25
0
void process_datafile(const char *fname, set_t *set,
	struct cmdline_opt *optvals)
{
	FILE *file;
	char cmd;
	int ret, val;
	int output_flag;

	/* sanity check for pointers */
	assert(set);
	assert(optvals);

	output_flag = optvals->verbose;


	if ((file = fopen(fname, "r")) == NULL) {
		fprintf(stderr,"Error: cannot open file %s.\n",	fname);
		return;
	}

	/* we are assuming a well-formed datafile for this project */
	while (fscanf(file, "%c %d\n", &cmd, &val) > 0) {
		switch (cmd) {
		case 'I':
			/* insert */
			ret = set_insert(set, val);
			if (output_flag) {
				printf("insert:\t%d\t%s\n", val,
					(ret ? "new" : "repeat"));
			}
			break;
		case 'D':
			/* delete */
			ret = set_delete(set, val);
			if (output_flag) {
				printf("delete:\t%d\t%s\n", val,
					(ret ? "removed" : "missing"));
			}
			break;
		case 'S':
			/* search */
			ret = set_search(set, val);
			if (output_flag) {
				printf("search:\t%d\t%s\n", val,
					(ret ? "present" : "absent"));
			}
			break;
		/* define your own commands if it helps with testing */
		case 'P':
			/* print, useful for debugging */
			if (output_flag) {
				set_print(set);
			}
			break;
		default:
			/* ignore any unrecognised commands */
			break;
		}
	}

	fclose(file);
}
Beispiel #26
0
int
main(void) {
  Vector  object;
  Vector *v_copy = NULL;
  VectorIter *ptr;
  unsigned int x, y;
  unsigned int value;
  memset(&object, 0, sizeof (object));
  x = RUNS;
  construct(Vector, &object,sizeof(x),FREEOBJ);
  set_alloc(Vector,  &object, ckalloc);
  set_dealloc(Vector,  &object, ckfree);
  set_compare(Vector,  &object, intcmp);
  set_print(Vector,  &object, print);
  for (y = 0; y < x; y++) {
    srand((x * y) / (x - y) + (x + y / x));
    switch ((rand() % NUMCASES) + BASE) {
        case 0:
        case 10:
        case 11:
        case 1:
        case 12:
        case 13:
        case 2:
        case 14:
        case 3:
        case 15:
        case 4:
          value = rand() % BOUND;
          push_front(Vector,  &object, &value, DYNAMIC);
          break;
          /*pop_front(Vector,  &object);
          break;*/
        case 5:
        case 6:
        case 16:
          /*pop_back(Vector,  &object);
          break;*/
        case 7:
        case 17:
          back(Vector,  &object);
        case 8:
        case 9:
          front(Vector,  &object);
          value = rand() % BOUND;
          push_back(Vector,  &object, &value, DYNAMIC);
          break;
        default:
          break;
    };
  }
  destruct(Vector,  &object);
  fprintf(stderr, "Now testing the iterators!\n");
  construct_func(Vector,&object,sizeof(x),FREEOBJ, ckalloc, ckfree, intcmp,  print,
                 memcpy);
  for (x = 0; x < RUNS; x++) {
	  value = rand() % RUNS;
    push_back(Vector,  &object, &value, STATIC);
  }

  ptr = create(VectorIter,  &object);
  head(VectorIter, ptr);
  /*printf("Head = %d\n",*(unsigned int *)retrieve(VectorIter,ptr));*/
  tail(VectorIter,ptr);
  /*printf("Tail = %d\n",*(unsigned int *)retrieve(VectorIter,ptr));*/
  head(VectorIter,ptr);
  do {
    value = *(unsigned int *) retrieve(VectorIter, ptr);
	/*printf("%d ",value);*/
  }
  while (!next(VectorIter, ptr));
  assign(VectorIter, ptr, &object);
  tail(VectorIter, ptr);
  do {
    value = *(unsigned int *) retrieve(VectorIter, ptr);
  } while (!prev(VectorIter, ptr));
  /*printf("\n");*/
  for(x = 0; x < RUNS; x++) {
	  switch(rand() % 2) {
		  case 1:
			  next(VectorIter,ptr);
			  break;
		  case 2:
			  prev(VectorIter,ptr);
			  break;
	  }
  }
  destroy(VectorIter, ptr);
  v_copy = duplicate(Vector,&object);
  ptr = create(VectorIter,v_copy);
  do{
	  value = *(unsigned int *)retrieve(VectorIter,ptr);
	  /*printf("%d ",value);*/
  }while(!next(VectorIter,ptr));
  /*printf("\n");*/
  destroy(VectorIter,ptr);
  destruct(Vector,v_copy);
  destruct(Vector,&object);
  free(v_copy);
  return EXIT_SUCCESS;
}
Beispiel #27
0
int main(int argc, char **argv)
{
    int c;
    extern int optind;

    int brute_force = 0;
    int verbose = 0;

    serializable input = serializableNIL;
    serializable output = serializableNIL;

    print_state st;

    while ((c = getopt(argc, argv, "Vfh?v")) != -1) {
        switch (c) {
            case 0:
                break;
            case 'V':
                verbose = 1;
                break;
            case 'f':
                brute_force = 1;
                break;
            case '?':
            case 'h':
                usage(stdout);
                return EXIT_SUCCESS;
            case 'v':
                version(stdout);
                return EXIT_SUCCESS;
            default:
                fprintf(stderr, "Try `wff2obdd -h' for more information.\n");
                return EXIT_FAILURE;
        }
    }

    infile = stdin;
    outfile = stdout;

    if (optind < argc) {
        infilename = strdup(argv[optind++]);
    }
    if (optind < argc) {
        outfilename = strdup(argv[optind++]);
    }

    if (infilename != NULL && 0 != strcmp(infilename, "-")) {
        infile = ckfopen(infilename, "r");
    }
    if (outfilename != NULL) {
        outfile = ckfopen(outfilename, "w");
    }

    init_symtbl();
    if (!fscan_serializable(infile, &input)) {
        fprintf(stderr, "wff2obdd: %d: %s\n", lineno, errmsg);
        destroy_symtbl();
        return EXIT_FAILURE;
    }
    st = set_print(outfile, 1, 75, 8);
    if (serializableNIL == input) {
        fprint_serializable(st, serializableNIL);
        destroy_symtbl();
        return EXIT_SUCCESS;
    }
    if (input->tag != TAGtv_wff_flat_kb && input->tag != TAGtv_wff_hierarchy) {
        fprintf(stderr, "wff2obdd: input is not in propositional Wff\n");
        rfre_serializable(input);
        destroy_symtbl();
        return EXIT_FAILURE;
    }

    wff2obdd_init();
    wff2obdd(input, &output, brute_force);

    if (verbose) {
        display_stat_items(stderr);
    }
    wff2obdd_destroy();

    rfre_serializable(input);

    fprint_serializable(st, output);
    rfre_serializable(output);
    end_print(st);
    destroy_symtbl();

    return EXIT_SUCCESS;
}
Beispiel #28
0
int main(int argc, char **argv)
{
    print_state st;
    tv_wff_hierarchy output;
    csp_hierarchy input = csp_hierarchyNIL;

    int c;
    extern int optind;

    while ((c = getopt(argc, argv, "h?v")) != -1) {
        switch (c) {
            case 0:
                break;
            case '?':
            case 'h':
                usage(stdout);
                return EXIT_FAILURE;
            case 'v':
                version(stdout);
                return EXIT_SUCCESS;
            default:
                fprintf(stderr, "Try `lcm2wff -h' for more information.\n");
                return EXIT_FAILURE;
        }
    }

    infile = stdin;
    outfile = stdout;

    if (optind < argc) {
        infilename = strdup(argv[optind++]);
    }
    if (optind < argc) {
        outfilename = strdup(argv[optind++]);
    }

    if (infilename != NULL && 0 != strcmp(infilename, "-")) {
        infile = ckfopen(infilename, "r");
    }
    if (outfilename != NULL) {
        outfile = ckfopen(outfilename, "w");
    }

    init_symtbl();

    if (!fscan_csp_hierarchy(infile, &input)) {
        fprintf(stderr, "lcm2wff: %d: %s\n", lineno, errmsg);
        destroy_symtbl();
        return EXIT_FAILURE;
    }
    if (!lcm2wff(input, &output)) {
        fprintf(stderr, "lcm2wff: Not a propositional model.\n");
        destroy_symtbl();
        return EXIT_FAILURE;
    }

    st = set_print(outfile, 1, 75, 8);
    fprint_tv_wff_hierarchy(st, output);
    end_print(st);

    rfre_tv_wff_hierarchy(output);
    rfre_csp_hierarchy(input);
    destroy_symtbl();

    return EXIT_SUCCESS;
}
Beispiel #29
0
static void
test_set(void) {
    char *keys1[] = {"a", "b", "r", "a", "c", "a", "d", "a", "b", "r", "a"};
    char *keys2[] = {"a", "l", "a", "c", "a", "z", "a", "m"};
    SetObject *a = set_new();
    SetObject *b = set_new();
    set_addfrom(a, (void**)keys1, 11);
    set_addfrom(b, (void**)keys2, 8);
    set_print(a); // { 'c', 'd', 'r', 'a', 'b', }
    set_print(b); // { 'c', 'l', 'm', 'a', 'z', }
    set_print(set_rsub(a, b)); //{ 'd', 'b', 'r', }
    set_print(set_ror(a, b)); //{ 'a', 'b', 'c', 'd', 'l', 'm', 'r', 'z', }
    set_print(set_rand(a, b)); //{ 'c', 'a', }
    set_print(set_rxor(a, b)); //{ 'b', 'd', 'l', 'm', 'r', 'z', }
    set_ior(a, b);
    set_print(a);
    set_isub(a, b);
    set_print(a);
    set_ixor(a, b);
    set_print(a);
    set_iand(a, b);
    set_print(a);
    set_free(a);
    set_free(b);
    char *keys3[] = {"a", "b"};
    char *keys4[] = {"a", "b", "d", "c", "e", "f", "g", "h"};
    SetObject *c = set_new();
    SetObject *d = set_new();
    set_addfrom(c, (void**)keys3, 2);
    set_addfrom(d, (void**)keys4, 8);
    set_print(set_xor(c, d));
    set_print(set_and(c, d));
    set_print(set_sub(c, d));
}
Beispiel #30
0
/* SYNTAX: SET [-clear | -default] [<key> [<value>]] */
static void cmd_set(char *data)
{
        GHashTable *optlist;
	char *key, *value;
	void *free_arg;
	int clear, set_default;
	SETTINGS_REC *rec;

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST |
			    PARAM_FLAG_OPTIONS,
			    "set", &optlist, &key, &value))
		return;

	clear = g_hash_table_lookup(optlist, "clear") != NULL;
	set_default = g_hash_table_lookup(optlist, "default") != NULL;

	if (*key == '\0')
		clear = set_default = FALSE;

	if (!(clear || set_default || *value != '\0'))
		set_print_pattern(key);
	else {
		rec = settings_get_record(key);
		if (rec != NULL) {
			/* change the setting */
			switch (rec->type) {
			case SETTING_TYPE_BOOLEAN:
				if (clear)
					settings_set_bool(key, FALSE);
				else if (set_default)
					settings_set_bool(key, rec->default_value.v_bool);
				else
					set_boolean(key, value);
				break;
			case SETTING_TYPE_INT:
				if (clear)
					settings_set_int(key, 0);
				else if (set_default)
					settings_set_int(key, rec->default_value.v_int);
				else
					set_int(key, value);
				break;
			case SETTING_TYPE_CHOICE:
				if (clear || set_default)
					settings_set_choice(key, rec->choices[rec->default_value.v_int]);
				else
					set_choice(key, value);
				break;
			case SETTING_TYPE_STRING:
				settings_set_str(key, clear ? "" :
						 set_default ? rec->default_value.v_string :
						 value);
				break;
			case SETTING_TYPE_TIME:
				if (!settings_set_time(key, clear ? "0" :
						       set_default ? rec->default_value.v_string : value))
					printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_TIME);
				break;
			case SETTING_TYPE_LEVEL:
				if (!settings_set_level(key, clear ? "" :
							set_default ? rec->default_value.v_string : value))
					printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_LEVEL);
				break;
			case SETTING_TYPE_SIZE:
				if (!settings_set_size(key, clear ? "0" :
						       set_default ? rec->default_value.v_string : value))
					printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_SIZE);
				break;
			case SETTING_TYPE_ANY:
				/* Unpossible! */
				break;
			}
			signal_emit("setup changed", 0);
			printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_SET_TITLE, rec->section);
			set_print(rec);
		} else
			printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_UNKNOWN, key);
	}

	cmd_params_free(free_arg);
}