Esempio n. 1
0
struct fuse *
fuse_new(struct fuse_chan *fc, unused struct fuse_args *args,
    const struct fuse_operations *ops, unused size_t size,
    unused void *userdata)
{
	struct fuse *fuse;
	struct fuse_vnode *root;

	if ((fuse = calloc(1, sizeof(*fuse))) == NULL)
		return (NULL);

	/* copy fuse ops to their own structure */
	memcpy(&fuse->op, ops, sizeof(fuse->op));

	fuse->fc = fc;
	fuse->max_ino = FUSE_ROOT_INO;
	fuse->se.args = fuse;
	fuse->private_data = userdata;

	if ((root = alloc_vn(fuse, "/", FUSE_ROOT_INO, 0)) == NULL) {
		free(fuse);
		return (NULL);
	}

	tree_init(&fuse->vnode_tree);
	tree_init(&fuse->name_tree);
	if (!set_vn(fuse, root)) {
		free(fuse);
		return (NULL);
	}

	return (fuse);
}
Esempio n. 2
0
int
control(void)
{
	struct passwd		*pw;

	purge_config(PURGE_EVERYTHING);

	if ((pw = getpwnam(SMTPD_USER)) == NULL)
		fatalx("unknown user " SMTPD_USER);

	stat_backend = env->sc_stat;
	stat_backend->init();

	if (chroot(PATH_CHROOT) == -1)
		fatal("control: chroot");
	if (chdir("/") == -1)
		fatal("control: chdir(\"/\")");

	config_process(PROC_CONTROL);

	if (setgroups(1, &pw->pw_gid) ||
	    setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
	    setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
		fatal("control: cannot drop privileges");

	imsg_callback = control_imsg;
	event_init();

	signal(SIGINT, SIG_IGN);
	signal(SIGTERM, SIG_IGN);
	signal(SIGPIPE, SIG_IGN);
	signal(SIGHUP, SIG_IGN);

	tree_init(&ctl_conns);
	tree_init(&ctl_count);

	memset(&digest, 0, sizeof digest);
	digest.startup = time(NULL);

	config_peer(PROC_SCHEDULER);
	config_peer(PROC_QUEUE);
	config_peer(PROC_PARENT);
	config_peer(PROC_LKA);
	config_peer(PROC_PONY);
	config_peer(PROC_CA);

	control_listen();

	if (pledge("stdio unix recvfd sendfd", NULL) == -1)
		err(1, "pledge");

	event_dispatch();
	fatalx("exited event loop");

	return (0);
}
Esempio n. 3
0
static void
mta_session_init(void)
{
	static int init = 0;

	if (!init) {
		tree_init(&wait_helo);
		tree_init(&wait_ptr);
		tree_init(&wait_fd);
		tree_init(&wait_ssl_init);
		tree_init(&wait_ssl_verify);
		runq_init(&hangon, mta_on_timeout);
		init = 1;
	}
}
Esempio n. 4
0
File: map.c Progetto: kshmir/so-2011
// Starts the map and stores the cloner and comparer
map map_init(comparer comp, cloner clon_function) {
	map m = (map) malloc(sizeof(struct map));
	tree t = tree_init(compare_data);
	m->t = t;
	m->comparer_index = comparers;
	m->mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
	pthread_mutex_init(m->mutex, NULL);
	// The map copies the keys if it has a function to do so
	if (clon_function != NULL)
		m->clon_function = clon_function;
	else {
		m->clon_function = NULL;
	}
	// Builds the comparer array for each new map.
	// It could have a threshold...
	if (comparer_storage == NULL) {
		comparer_storage = (comparer*)malloc(sizeof(comparer));
		*comparer_storage = comp;
	} else {
		comparer * old = comparer_storage;
		comparer_storage = (comparer*) malloc(sizeof(comparer) * (comparers + 1));
		int i = 0;
		for (; i < comparers; i++) {
			comparer_storage[i] = old[i];
		}
		free(old);
		comparer_storage[i] = comp;
	}
	comparers++;

	return m;
}
Esempio n. 5
0
u64 *problem_solve(problem_t *p) {
	bool_t result;
    tree_t root = NULL;
    size_t i = 0;
    u64 *solution = NULL;

    if (p == NULL)
        return NULL;

    root = tree_init();
	for (; i < p->n_vars; i++) {
		result = problem_alloc(p, root, p->vars[i]);
	}


	if (root->n_children == 0) {
		printf("pas de solution");
	}
	else {
			affichage(root);
	}


	return solution;
}
Esempio n. 6
0
static void
filter_api_init(void)
{
	extern const char *__progname;
	struct passwd  *pw;
	static int	init = 0;

	if (init)
		return;

	init = 1;

	pw = getpwnam(SMTPD_USER);
	if (pw == NULL)
		err(1, "getpwnam");

	smtpd_process = PROC_FILTER;
	filter_name = __progname;

	tree_init(&queries);
	event_init();

	bzero(&fi, sizeof(fi));
	fi.p.proc = PROC_MFA;
	fi.p.name = "filter";
	fi.p.handler = filter_dispatch;
	fi.uid = pw->pw_uid;
	fi.gid = pw->pw_gid;
	fi.rootpath = PATH_CHROOT;
	
	mproc_init(&fi.p, 0);
}
Esempio n. 7
0
/*
	params: file f, tree nP
		(up to the caller to specify where
		to start reading f from)
	reads: a space-separated file f
	writes: a tree nP that contains the integers
		read from file
	notes: file may contain up to 4 ints per line
		if more, they are ignored
*/		
int tree_finsert (FILE* f, node** nP) { 

	// 4 nums/ line =>
	// worst case length po 2 = (2^(ceil(log(12*4+4)/log(2))) = 64
	char buf[64];
	int buf2int[4], numel = 0;
	short int how_many,  first_time = 0; // was last sscanf successful?, tree init flag
	
	while ( fgets( buf, 64, f) != NULL ) {

		how_many = 0;
		how_many += (sscanf(buf, "%d %d %d %d", 
			&buf2int[0],  &buf2int[1],  &buf2int[2],  &buf2int[3]) == 4) * 4;
		how_many += (sscanf(buf, "%d %d %d", 
			&buf2int[0],  &buf2int[1],  &buf2int[2] ) == 3 && how_many == 0) * 3;
		how_many += (sscanf(buf, "%d %d", 
			&buf2int[0],  &buf2int[1]  ) == 2 && how_many == 0 ) * 2;
		how_many += (sscanf(buf, "%d", 
			&buf2int[0]) == 1  &&  how_many == 0);
		
		if ( (++first_time -1 ) == 0 )
			tree_init(nP, buf2int[0]);
		else
		{
			for (int i = 0 + (first_time == 1); i < how_many; i++)
				tree_insert(nP, buf2int[i]);
		}
		
	}
}
Esempio n. 8
0
/* A list is a sequence of one or more AND-OR-lists separated by the
 * operators
 *
 *       ;    &
 *
 * and optionally terminated by
 *
 *       ;    &    <newline>
 *
 * ----------------------------------------------------------------------- */
union node *parse_list(struct parser *p) {
    union node   *list;
    union node  **nptr;
    enum tok_flag tok;

    /* keep looking for and-or lists */
    tree_init(list, nptr);

    while((*nptr = parse_and_or(p))) {
        tok = parse_gettok(p, P_DEFAULT);

        /* <newline> terminates the list and eats the token */
        if(tok & T_NL)
            return list;

        /* there must be & or ; after the and-or list,
           otherwise the list will be terminated */
        if(!(tok & (T_SEMI | T_BGND))) {
            p->pushback++;
            break;
        }

        /* & causes async exec of preceding and-or list */
        if(tok & T_BGND)
            (*nptr)->nlist.bgnd = 1;

        /* now check for another and-or list */
        tree_next(nptr);
    }

    return list;
}
Esempio n. 9
0
port_state_t* port_new(HANDLE* iocp_out) {
  port_state_t* port_state;
  HANDLE iocp;

  port_state = port__alloc();
  if (port_state == NULL)
    goto err1;

  iocp = port__create_iocp();
  if (iocp == NULL)
    goto err2;

  memset(port_state, 0, sizeof *port_state);

  port_state->iocp = iocp;
  tree_init(&port_state->sock_tree);
  queue_init(&port_state->sock_update_queue);
  queue_init(&port_state->sock_deleted_queue);
  queue_init(&port_state->poll_group_queue);
  ts_tree_node_init(&port_state->handle_tree_node);
  InitializeCriticalSection(&port_state->lock);

  *iocp_out = iocp;
  return port_state;

err2:
  port__free(port_state);
err1:
  return NULL;
}
Esempio n. 10
0
 void auto_test_create(int n, double results[], test_set set[]) {
  //o, hai.
  struct timespec begin, end;
  int *array[TESTS], i; 
  results[0]=results[1]=results[2]=0;

  for (i = 0; i < TESTS; ++i)
  {
    printf("test #%d\n",i);
    array[i] = generate_unique_array(n, 1);
    clock_gettime(CLOCK_REALTIME, &begin);
    set[i].list = list_init_from_array(n/10, array[i]);
    clock_gettime(CLOCK_REALTIME, &end);
    results[0] += timespec_to_miliseconds(&begin, &end);

    clock_gettime(CLOCK_REALTIME, &begin);
    set[i].bst = tree_init(array[i], n);
    clock_gettime(CLOCK_REALTIME, &end);
    results[1] += timespec_to_miliseconds(&begin, &end);

    clock_gettime(CLOCK_REALTIME, &begin);
    set[i].avl = tree_avl_init(array[i], n, 1);
    clock_gettime(CLOCK_REALTIME, &end);
    results[2] += timespec_to_miliseconds(&begin, &end);

    free(array[i]);
  }

  for (i = 0; i < 3; ++i)
    results[i]/=TESTS;


  return;
}
Esempio n. 11
0
int main(void) {

	/*
	 * Array or hash table would be faster.
	 */
	tree_t * tree = tree_init();
	tree->root = init_char_node('Z',0);

	char * str = "ajdklfdfsf7a89345jrdfka345789dfjakfsdfasd78934rfjasdf";
	char * sptr = str;

	while(*sptr) 
		inc_char_cnt(tree, *(sptr++));

	sptr = str;
	
	while(*sptr) {
		if (get_char_cnt(tree, *(sptr)) == 1) 
			printf("First non repeated character: %c\n", *sptr);

		sptr++;
	}


	return 0;
}
Esempio n. 12
0
int
main(int argc, char **argv)
{
   char *fnm1, *fnm2;
   const char *survey = NULL;

   msg_init(argv);

   cmdline_set_syntax_message(/*FILE1 FILE2 [THRESHOLD]*/218,
			      /*FILE1 and FILE2 can be .pos or .3d files\nTHRESHOLD is the max. ignorable change along any axis in metres (default %s)*/255,
			      STRING(DFLT_MAX_THRESHOLD));
   cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 2, 3);
   while (1) {
      int opt = cmdline_getopt();
      if (opt == EOF) break;
      if (opt == 's') survey = optarg;
   }
   fnm1 = argv[optind++];
   fnm2 = argv[optind++];
   if (argv[optind]) {
      optarg = argv[optind];
      threshold = cmdline_double_arg();
   }

   tree_init();

   old_separator = parse_file(fnm1, survey, tree_insert);

   new_separator = parse_file(fnm2, survey, tree_remove);

   return tree_check() ? EXIT_FAILURE : EXIT_SUCCESS;
}
Esempio n. 13
0
void
lka_session(uint64_t id, struct envelope *envelope)
{
	struct lka_session	*lks;
	struct expandnode	 xn;

	if (init == 0) {
		init = 1;
		tree_init(&sessions);
	}

	lks = xcalloc(1, sizeof(*lks), "lka_session");
	lks->id = id;
	RB_INIT(&lks->expand.tree);
	TAILQ_INIT(&lks->deliverylist);
	tree_xset(&sessions, lks->id, lks);

	lks->envelope = *envelope;

	TAILQ_INIT(&lks->nodes);
	bzero(&xn, sizeof xn);
	xn.type = EXPAND_ADDRESS;
	xn.u.mailaddr = lks->envelope.rcpt;
	lks->expand.rule = NULL;
	lks->expand.queue = &lks->nodes;
	expand_insert(&lks->expand, &xn);
	lka_resume(lks);
}
Esempio n. 14
0
/* parse a compound list
 * 
 * The term compound-list is derived from the grammar in 3.10; it is
 * equivalent to a sequence of lists, separated by <newline>s, that 
 * can be preceded or followed by an arbitrary number of <newline>s.
 * ----------------------------------------------------------------------- */
union node *parse_compound_list(struct parser *p) {
  union node *list;
  union node **nptr;

  tree_init(list, nptr);

  /* skip arbitrary newlines */
  while(parse_gettok(p, P_DEFAULT) & T_NL);
  p->pushback++;

  for(;;) {
    /* try to parse a list */
    *nptr = parse_list(p);

    /* skip arbitrary newlines */
    while(p->tok & T_NL) parse_gettok(p, P_DEFAULT);
    p->pushback++;

    /* no more lists */
    if(*nptr == NULL)
      break;

    /* parse_list already returns a list, so we
       must skip over it to get &lastnode->next */
    while(*nptr)
      tree_next(nptr);
  }

  return list;
}
Esempio n. 15
0
/* 3.9.4.1 parse a grouping compound
 * 
 * The format for grouping commands is a s follows:
 * 
 *  (compound-list)       Execute compound-list in a subshell environment;
 *                        Variable assignments and built-in commands that
 *                        affect the environment shall not remain in effect
 *                        after the list finishes.
 * 
 *  { compound-list;}     Execute compound-list in the current process
 *                        environment.
 * 
 * ----------------------------------------------------------------------- */
union node *parse_grouping(struct parser *p) {
  enum tok_flag tok;
  union node  **rptr;
  union node   *grouping;
  union node   *compound_list;

  /* return NULL on empty compound */
  grouping = NULL;
  
  if(!(tok = parse_expect(p, P_DEFAULT, T_BEGIN|T_LP, NULL)))
    return NULL;
  
  /* parse compound content and create a 
     compound node if there are commands */
  if((compound_list = parse_compound_list(p))) {
    grouping = tree_newnode(tok == T_BEGIN ? N_CMDLIST : N_SUBSHELL);
    grouping->ngrp.cmds = compound_list;
  }

  /* expect the appropriate ending token */
  if(!parse_expect(p, P_DEFAULT, tok << 1, grouping))
    return NULL;

  if(grouping) {
    tree_init(grouping->ngrp.rdir, rptr);

    /* now any redirections may follow */
    while(parse_gettok(p, P_DEFAULT) & T_REDIR)
      tree_move(p->tree, rptr);

    p->pushback++;
  }

  return grouping;
}
Esempio n. 16
0
int main()
{
	/* открываем файл */
	char line[LINELENGTH];
	FILE *fp;
    printf("введите имя файла:");
    scanf("%s", line);
    if((fp = fopen(line,"r")) == NULL){
        fprintf(stderr, "Нет такого файла\n");
        return 1;
    }
	/* считываем строку */
    fgets (line, LINELENGTH, fp);
	fclose(fp);
	

	/* cоздаем новое дерево */
	struct tree *thetree = NULL;
	thetree = tree_init();
	
	/* преобразуем */
	thetree = infixtotree(line, thetree);

	/* рекурсивная печать дерева*/	
	//reptree(thetree);
	/* нерекурсивная печать дерева */
	nonreptree(thetree);
	return 0;

}
Esempio n. 17
0
int main(void){

	char c;
	int i=0, j=0, k=0;
	
	PQueue *min = pq_init();	
	char array[MAX_UNIQUE_CHARS];
	char freq[MAX_UNIQUE_CHARS];
	char path[MAX_LENGTH];
	
	gets(array);
	gets(freq);
	gets(path);
	
	int r=0;
	while(array[r]!=NULL){
		Tree *node= tree_init(freq[r]-'0', array[r]);
		pq_enqueue(min, node, freq[r]-'0');
		r+=2;		
	}
	
	while(min->size > 1){
		Tree *left=pq_dequeue(min);
		Tree *right=pq_dequeue(min);
		Tree *node=tree_merge(left, right);	
		pq_enqueue(min, node, node->root->freq);		
	}

	List *l=init_list(9);
	Stack *s=init_stack();
	
	l=recursive_Encoding(min->data[0]->root, s, l);
	
	read_path(min->data[0]->root, path);
}
Esempio n. 18
0
int main(int argc, char* argv[])
{
	//要求:对第i的页面的访问概率正比于1/sqrt(i+1)
	const int count = 30;
	const int tests = 10;
	TreeKeyType* sum = new TreeKeyType[count];
	sum[0] = 1;
	//sum[0]=1
	//sum[1]=sum[0]+1/sqrt(2)
	//sum[2]=sum[1]+1/sqrt(3)
	//...
	//sum[n-1]=sum[n-2]+1/sqrt(n)
	for (int i = 1; i < count; i++)
	{
		sum[i] = sum[i - 1] + (double)(1 / sqrt(i + 1));
	}
	TreeKeyType MaxRandValue = sum[count - 1] - 0.00001;
	tree_node* search_node = tree_init(sum, count, 0);
	printf("Search node size: %d\n", tree_size(search_node) * sizeof(search_node));
	printf("========== tree ==========\n");
	tree_print(search_node);
	printf("========== find ==========\n");
	srand((unsigned int)time(NULL));
	for (int i = 0; i < tests; i++)
	{
		TreeKeyType rnd = rand() / double(RAND_MAX) * MaxRandValue;
		printf("key: %f, val: %d\n", rnd, tree_find(search_node, rnd));
	}
	delete[] (sum);
	return 0;
}
Esempio n. 19
0
int main(int argc, char*argv[]) {
    int h = (int)(log(NUM_THREADS)/log(2));
    int numtasks, rank, rc;
    int ecart[h];
    int sender[h];
    int numb_msg[h];
    int i;

    tree_init(h,ecart,sender,numb_msg);
    rc = MPI_Init(&argc,&argv);
    if(rc != MPI_SUCCESS){
        printf("Error starting MPI Program. Terminating.\n");
        MPI_Abort(MPI_COMM_WORLD,rc);
    }

    MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);

    /*******TEST :  global_achievement_time *******/
    double global_achievement_time = 0;
    double global_arrival_time = 0;
    double global_wake_up_time = 0;
    double local_achievement_time = 0;
    double local_arrival_time = 0;
    double local_wake_up_time = 0;
    double t_start,t_end;
    int j=0;

    t_start = MPI_Wtime();
    //printf("Hello world from thread %d BEFORE barrier\n",rank);

    for(i=0;i<NUM_BARRIERS;i++) {
        tour(rank,h,ecart,sender,numb_msg,&local_arrival_time, &local_wake_up_time);
        //printf("Hello world from thread %d AFTER barrier\n",rank);
    }

    t_end = MPI_Wtime();
    local_achievement_time = (local_achievement_time+ t_end-t_start)/NUM_BARRIERS;
    local_arrival_time = local_arrival_time/NUM_BARRIERS;
    local_wake_up_time = local_wake_up_time/NUM_BARRIERS;

    rc = MPI_Reduce(&local_achievement_time, &global_achievement_time, 1, MPI_DOUBLE, MPI_SUM,0, MPI_COMM_WORLD);
    rc = MPI_Reduce(&local_arrival_time, &global_arrival_time, 1, MPI_DOUBLE, MPI_SUM,0, MPI_COMM_WORLD);
    rc = MPI_Reduce(&local_wake_up_time, &global_wake_up_time, 1, MPI_DOUBLE, MPI_SUM,0, MPI_COMM_WORLD);
/*
    if (rank ==0) {
        FILE *fp;
        fp = fopen("tour_test.csv","a");
        fprintf(fp,"Num_threads,%d,",NUM_THREADS);
        fprintf(fp,"%f,",global_achievement_time);
        fprintf(fp,"%f,",global_arrival_time);
        fprintf(fp,"%f\n",global_wake_up_time);
        fclose(fp);
    }
*/

    MPI_Finalize();
    return 0;
}
Esempio n. 20
0
/*!
 * general init function 
 * \version 1.0
 * \date    Sept 2007
 * \author Elie
 */
void init()
{
	
	unsigned int i;
	
	option.default_set_value = SET_COST;
	option.default_node_value = HOST_COST;
	option.start_time = time(NULL);
	
	//rand
	i = time(NULL);
	srand(i);


	//init tree;
	
	root = NULL;
	tree = NULL;
	last_branch = NULL;
	tree_init();
	
	//stat initi

	bzero(&stat, sizeof(t_stat));	
	
	//init strategy
	strategy = NULL;
	
	//init formula
	formula = NULL;

	//player init
	admin = malloc(sizeof(t_player));
	bzero(admin, sizeof(t_player));
	admin->name = ADMIN_NAME;
	admin->target = -1;
	admin->target_succ = UNSET;
	admin->rule_status = UNSET;
	incident = malloc(sizeof(t_player));
	bzero(incident, sizeof(t_player));
	incident->name = INCIDENT_NAME;
	incident->target = -1;
	incident->target_succ = UNSET;
	incident->rule_status = UNSET;
	
	//init graph
	graph_init();
	
	//init penality

	penality = NULL;

	//parse game file
	parse(option.filename);

	//preprocessing game to statically optimize it
	preprocessor();
}
Esempio n. 21
0
void list_add_right(_tree_node *p,_tree_data *data){
    if(p==NULL){
        //fprintf(stderr,"NULL Pointer\n");
    }else if(p->right!=NULL){
        //fprintf(stderr,"Not free pointer\n");
    }else{
        p->right=tree_init(data);
    }
}
Esempio n. 22
0
int tree_insert_importDefinition(struct tree **t)
{
	//t = importDefinition, so get the ident subtree
	struct tree *t_sub = NULL;
	tree_get_subtree("ident", (*t), &t_sub);
	if(t_sub == NULL)
	{
		return(1); //failure
	}

	//Get symbol pointer to variable name
	//TODO: need to use more generic getter
	char * import_name = t_sub->kids[0]->leaf->text;

	//Parse the import file
	tree_init(); //inits YY_TREE

	//open the file and store its reference in global variable yyin
	tree_import_ident_to_path(import_name, &YY_FNAME);

	//yyrestart for multiple file parsing
	FILE *yyfile = fopen(YY_FNAME, "r");
        yyrestart(yyfile); lineno = 1; colno = 1;
        //instead of - yyin = fopen(YY_FNAME,"r");

	if (yyin == NULL) 
	{
		fprintf(stderr, "ERROR: import: Cannot open '%s'. ",\
								YY_FNAME);
		#ifdef DEBUG_TREE
		fprintf(stderr, "Continuing anyway...\n");
		#else
		fprintf(stderr, "Cannot continue.\n");
		exit(ERROR_SEMANTIC);
		#endif
	}
	else
	{
		//print the name of the file
		printf("%s\n", YY_FNAME);

		//parse import file
		yyparse();
		
		//delete the importDefinition subtree...
		tree_del((*t));

		//...and replace it with the newly parsed YY_TREE
		//TODO: do we really want to replace with a as3CompilationUnit
		// subtree, or it's children? Leaving for now.
		(*t) = YY_TREE;
	}

	return(0); //success
}
Esempio n. 23
0
static void
filter_api_init(void)
{
	extern const char *__progname;
	struct passwd  *pw;
	static int	init = 0;

	if (init)
		return;

	init = 1;

	log_init(-1);
	log_verbose(1);

	pw = getpwnam(SMTPD_USER);
	if (pw == NULL) {
		log_warn("warn: filter-api:%s getpwnam", filter_name);
		fatalx("filter-api: exiting");
	}

	smtpd_process = PROC_FILTER;
	filter_name = __progname;

	tree_init(&queries);
	tree_init(&sessions);
	event_init();

	memset(&fi, 0, sizeof(fi));
	fi.p.proc = PROC_PONY;
	fi.p.name = "filter";
	fi.p.handler = filter_dispatch;
	fi.uid = pw->pw_uid;
	fi.gid = pw->pw_gid;
	fi.rootpath = PATH_CHROOT;

	/* XXX just for now */
	fi.hooks = ~0;

	mproc_init(&fi.p, 0);
}
Esempio n. 24
0
// Take 2 trees and merge them as the left and right children of a new node
Tree* tree_merge(Tree *left, Tree *right){
    Tree *t = tree_init(left->root->freq + right->root->freq, '\0');
    
    t->root->left  = left->root;
    t->root->right = right->root;

    // Just free the old tree dummy heads, not the actual trees
    free(left);
    free(right);

    return t;
}
Esempio n. 25
0
int main() {

    slong n, i, m, prec = 60;
    flint_rand_t state;
    
    flint_printf("symplectic basis...");
    fflush(stdout);
    flint_randinit(state);

    for (n = 3; n < 10; n++)
    {
        for (i = 0; i < 5; i++)
        {
            acb_ptr x;
            tree_t tree;
 
            x = _acb_vec_init(n);
            acb_vec_set_random(x, n, state, prec, 4);

            tree_init(tree, n - 1);
            spanning_tree(tree, x, n, INT_DE);

            for (m = 2; m < 7; m++)
            {
                sec_t c;
                homol_t alpha, beta;

                sec_init(&c, m, n);
                tree_ydata_init(tree, x, n, m, prec);

                alpha = flint_malloc(c.g * sizeof(loop_t));
                beta = flint_malloc(c.g * sizeof(loop_t));

                symplectic_basis(alpha, beta, tree, c);

                homol_clear(alpha, c.g);
                homol_clear(beta, c.g);

                tree_ydata_clear(tree);
                sec_clear(c);
            }

            tree_clear(tree);
            _acb_vec_clear(x, n);
        }
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return 0;
}
Esempio n. 26
0
/**
 * Überprüft auf eine Kollision
 * Return: diff = neues Struct direkt zum Ziel
 * return: 0 wenn keine Kollision, 1 sonst
 */
uint8_t calc_Offroad(gps_reducedData_t* diff, gps_reducedData_t* own, gps_reducedData_t* target){
	int16_t xCollision, yCollision;

	tree_init(CoordinatesToMap(own->x), CoordinatesToMap(own->y));
	if (calc_reachability(&xCollision, &yCollision,CoordinatesToMap(own->x), CoordinatesToMap(own->y),CoordinatesToMap(target->x), CoordinatesToMap(target->y)) == 0){
		setCoordinates(diff, target->cam_id, target->tag_id, target->x, target->y, target->angle, target->isWorld);
		return 0;
	}
	else{
		scan_Obstacles(xCollision, yCollision, own, target, CoordinatesToMap(own->x), CoordinatesToMap(own->y)); //übergibt hier die Kollisionskoordinaten
	}
	return 1;
}
Esempio n. 27
0
void compute(struct In *input, struct Out *output){
  tree_t tree;
  BOOL success = FALSE;

  tree_init(&tree);

  success = tree_insert(&tree, 9, 112);
  success = tree_insert(&tree, 27, 8);
  success = tree_insert(&tree, 63, 789);

  tree_find_gt(&tree, 26, FALSE, &(output->result_set1));
  tree_find_range(&tree, 8, TRUE, 63, FALSE, &(output->result_set2));
}
Esempio n. 28
0
Tree *set_tree (char *argv[])
{
    Tree *tptr;
    int type_length = strlen (argv[1]);
    char *tree_type = (char *) malloc ((type_length + 1) * (sizeof(char)));
    tree_type [type_length - 1] = '\0';

    for (int i = 0; i < type_length; i++) {
        tree_type[i] = toupper ((int)argv[1][i]);
    }
    if (strsame (tree_type, "AVL")) {
        tptr =  tree_init(compare_ints, copy_ints, avl_insert_balance,
                          avl_delete_balance);
        printf("\nAVL tree selected.\n");
    }
    else if (strsame (tree_type, "WAVL")) {
        tptr =  tree_init(compare_ints, copy_ints, wavl_insert_balance,
                          wavl_delete_balance);
        printf("\nWAVL tree selected.\n");
    }
    else if (strsame (tree_type, "2-3")) {
        tptr =  tree_init(compare_ints, copy_ints, two_three_insert_balance,
                          two_three_delete_balance);
        printf("\n2-3 tree selected.\n");
    }
    else if (strsame (tree_type, "2-3-4")) {
        tptr =  tree_init(compare_ints, copy_ints, two_four_insert_balance,
                          two_four_delete_balance);
        printf("\n2-3-4 tree selected.\n");
    }
    else {
        fprintf (stderr, "Expecting a tree type as the second argument.\n"
                 "The options are 'avl', 'wavl', '2-3' and '2-3-4',\n");
        tptr =  NULL;
    }
    free (tree_type);
    return tptr;
}
Esempio n. 29
0
int
queue_init(const char *name, int server)
{
	struct passwd	*pwq;
	struct group	*gr;
	int		 r;

	pwq = getpwnam(SMTPD_QUEUE_USER);
	if (pwq == NULL)
		errx(1, "unknown user %s", SMTPD_QUEUE_USER);

	gr = getgrnam(SMTPD_QUEUE_GROUP);
	if (gr == NULL)
		errx(1, "unknown group %s", SMTPD_QUEUE_GROUP);
	
	tree_init(&evpcache_tree);
	TAILQ_INIT(&evpcache_list);

	if (!strcmp(name, "fs"))
		backend = &queue_backend_fs;
	else if (!strcmp(name, "null"))
		backend = &queue_backend_null;
	else if (!strcmp(name, "ram"))
		backend = &queue_backend_ram;
	else
		backend = &queue_backend_proc;

	if (server) {
		if (ckdir(PATH_SPOOL, 0711, 0, 0, 1) == 0)
			errx(1, "error in spool directory setup");
		if (ckdir(PATH_SPOOL PATH_OFFLINE, 0770, 0, gr->gr_gid, 1) == 0)
			errx(1, "error in offline directory setup");
		if (ckdir_quiet(PATH_SPOOL PATH_PURGE, 0700, pwq->pw_uid, 0))
			chmod(PATH_SPOOL PATH_PURGE, 0750);
		if (ckdir(PATH_SPOOL PATH_PURGE, 0750, pwq->pw_uid, 0, 1) == 0)
			errx(1, "error in purge directory setup");

		mvpurge(PATH_SPOOL PATH_TEMPORARY, PATH_SPOOL PATH_PURGE);

		if (ckdir(PATH_SPOOL PATH_TEMPORARY, 0700, pwq->pw_uid, 0, 1) == 0)
			errx(1, "error in purge directory setup");
	}

	r = backend->init(pwq, server, name);

	log_trace(TRACE_QUEUE, "queue-backend: queue_init(%d) -> %d", server, r);

	return (r);
}
Esempio n. 30
0
int
queue_init(const char *name, int server)
{
	struct passwd	*pwq;
	int		 r;

	pwq = getpwnam(SMTPD_QUEUE_USER);
	if (pwq == NULL)
		pwq = getpwnam(SMTPD_USER);
	if (pwq == NULL)
		errx(1, "unknown user %s", SMTPD_USER);

	tree_init(&evpcache_tree);
	TAILQ_INIT(&evpcache_list);

	if (!strcmp(name, "fs"))
		backend = &queue_backend_fs;
	if (!strcmp(name, "null"))
		backend = &queue_backend_null;
	if (!strcmp(name, "proc"))
		backend = &queue_backend_proc;
	if (!strcmp(name, "ram"))
		backend = &queue_backend_ram;

	if (backend == NULL) {
		log_warn("could not find queue backend \"%s\"", name);
		return (0);
	}

	if (server) {
		if (ckdir(PATH_SPOOL, 0711, 0, 0, 1) == 0)
			errx(1, "error in spool directory setup");
		if (ckdir(PATH_SPOOL PATH_OFFLINE, 01777, 0, 0, 1) == 0)
			errx(1, "error in offline directory setup");
		if (ckdir(PATH_SPOOL PATH_PURGE, 0700, pwq->pw_uid, 0, 1) == 0)
			errx(1, "error in purge directory setup");

		mvpurge(PATH_SPOOL PATH_TEMPORARY, PATH_SPOOL PATH_PURGE);

		if (ckdir(PATH_SPOOL PATH_TEMPORARY, 0700, pwq->pw_uid, 0, 1) == 0)
			errx(1, "error in purge directory setup");
	}

	r = backend->init(pwq, server);

	log_trace(TRACE_QUEUE, "queue-backend: queue_init(%i) -> %i", server, r);

	return (r);
}