Ejemplo n.º 1
0
static void free_afriend(UserNode *punode) {
	if(punode == NULL)
		return;
	if(punode->from)
		free_queue(punode->from, 1);
	if(punode->to)
		free_queue(punode->to, 1);
	free(punode);
}
void
Checksum_dealloc(accuraterip_Checksum *self)
{
    free(self->accuraterip_v1.checksums);
    free_queue(self->accuraterip_v1.initial_values);
    free_queue(self->accuraterip_v1.final_values);

    Py_XDECREF(self->framelist_class);

    Py_TYPE(self)->tp_free((PyObject*)self);
}
Ejemplo n.º 3
0
void clear_consumer() {
	free_hashmap(&savedRequests);
	free_hashmap(&wb_cl_map);
	free_hashmap(&cl_req_map);
	free_cache(cache);
	free_queue(&queue_clients);
	free_queue(&queue_webservers);
	
	pthread_attr_destroy(&attr);
		
	pthread_cond_destroy(&queue_cond);
	pthread_mutex_destroy(&queue_mutex);
	pthread_mutex_destroy(&wb_cl_map_mutex);
	pthread_mutex_destroy(&savedReq_map_mutex);
}
Ejemplo n.º 4
0
int main (int argc, char **argv) {
   execname = basename (argv[0]);
   queue_ref queue = new_queue();

   if (argc < 2) {
      putinqueue (queue, stdin, "-");
   }else {
      for (int argi = 1; argi < argc; ++argi) {
         if (strcmp (argv[argi], "-") == 0) {
            putinqueue (queue, stdin, "-");
         }else {
            putfileinqueue (queue, argv[argi]);
         }
      }
   }

   while (! isempty_queue (queue)) { 
      char *oldstring = remove_queue(queue);
      printf ("%s\n", oldstring);
      free (oldstring);
   }

   free_queue(queue);

   return exit_status;
}
int main(int ac, char **av)
{
	Queue *queue;
	int i;
	char *str;

	queue = NULL;
	i = 0;
	while (i < ac)
	{
		push_queue(&queue, av[i]);
		++i;
	}
	print_queue(queue);
	str = pop_queue(&queue);
	printf("%s\n", str);
	free(str);
	print_queue(queue);
	str = pop_queue(&queue);
	printf("%s\n", str);
	free(str);
	print_queue(queue);
	str = pop_queue(&queue);
	printf("%s\n", str);
	free(str);
	print_queue(queue);
	free (str);
	free_queue(queue);
	return (0);
}
Ejemplo n.º 6
0
static int div_one(UserNode *punode, short div, int distance) {
	UserNode *tmp;
	DivParam dp;
	
	tmp = punode;
	
	dp.pList = init_queue();
	if(dp.pList == NULL)
		return -1;

	dp.div = div;
	dp.distance = distance;
	
	dp.flag = 1; //"to"
	punode->div = -dp.div;
	apply_queue(punode->to, add_node, &dp);
	while(!is_empty(dp.pList)) {
		punode = read_first(dp.pList);
		apply_queue(punode->to, add_node, &dp);
		delete_node(dp.pList, 0, 0);
	}
	
	punode = tmp;
	dp.flag = 0; //"from"
	punode->div = dp.div;
	apply_queue(punode->from, add_node, &dp);
	while(!is_empty(dp.pList)) {
		punode = read_first(dp.pList);
		apply_queue(punode->from, add_node, &dp);
		delete_node(dp.pList, 0, 0);
	}
	free_queue(dp.pList, 1);
	return 0;
}
Ejemplo n.º 7
0
int main(){
    char text[50];
    printf("Please provide a command\n");
    do{
        memset(text,'\0',50);
        printf(">>> ");
        fflush(stdout);
        scanf("%s",text);
        if(strcmp(text,"put")==0){
            printf("provide a label\n");
            fflush(stdout);
            char label[10];
            memset(label,'\0',10);
            scanf("%s",label);    
            enqueue(label);
        }
        else if(strcmp(text,"remove")==0){
            qNode* temp=dequeue();
            printf("The label is: %s",temp->label);
            free(temp);
        }
        else if(strcmp(text,"print")==0)
            print_queue();
        else{}
                    
    }while(strcmp(text,"quit")!=0);
    
    free_queue(head);
    return 0;
}
Ejemplo n.º 8
0
int main()
{
        struct priority_queue *queue = create_queue(10);

        if (queue == NULL)
                printf("create_queue error\n");

        insert_queue(queue, 10, (struct huff_table*)10);
        insert_queue(queue, 11, (struct huff_table*)11);
        insert_queue(queue, 8, (struct huff_table*)8);
        insert_queue(queue, 3, (struct huff_table*)3);
        insert_queue(queue, 7, (struct huff_table*)7);
        insert_queue(queue, 15, (struct huff_table*)15);

        uint32_t priority = 0;
        struct huff_table *table = NULL;

        while (best_queue(queue, &priority, &table)) {

                printf("Table = %ld\n", (uint64_t)table);
                delete_queue(queue);
        }

        free_queue(queue);


        return EXIT_SUCCESS;
}
Ejemplo n.º 9
0
main()
{
  IS is;
  Queue q;
  Stack s;
  Dllist l;
  int i;
  Jval j;

  is = new_inputstruct(NULL);

  while (get_line(is) > 0) {
    q = new_queue();
    s = new_stack();
    l = new_dllist();
    for (i = 0; i < strlen(is->fields[0]); i++) {
      queue_enqueue(q, new_jval_c(is->fields[0][i]));
      stack_push(s, new_jval_c(is->fields[0][i]));
      dll_append(l, new_jval_c(is->fields[0][i]));
      dll_prepend(l, new_jval_c(is->fields[0][i]));
    }
    while (!queue_empty(q)) {
      j = queue_dequeue(q); printf("%c", j.c);
      j = stack_pop(s); printf("%c", j.c);
      printf("%c", l->flink->val.c); dll_delete_node(l->flink);
      printf("%c", l->flink->val.c); dll_delete_node(l->flink);
      printf(" ");
    }
    printf("\n");
    free_queue(q);
    free_stack(s);
    free_dllist(l);
  }
}
Ejemplo n.º 10
0
// calculate gen function due to the execution of bbi
static void
tcfg_node_gen(tcfg_node_t *bbi)
{
    addr_t	    addr, ea;
    mem_blk_t	    mblk, *p;
    int		    i, set, tag, num_updates = 0;
    Queue	    worklist;

    init_queue(&worklist, sizeof(mem_blk_t));

    addr = CLEAR_LSB(bbi->bb->sa);
    ea = bbi->bb->sa + bbi->bb->size;
    while (addr < ea) {
        mblk.set = SET(addr);
        mblk.tag = TAG(addr);
        enqueue(&worklist, &mblk);
        addr += cache.ls;
        num_updates++;
    }

    gen[bbi->id] = (mem_blk_t *) calloc(num_updates+1, sizeof(mem_blk_t));
    CHECK_MEM(gen[bbi->id]);
    for (i = 0; i < num_updates; i++) {
        p = (mem_blk_t *) dequeue(&worklist);
        memmove(&gen[bbi->id][i], p, sizeof(mem_blk_t));
    }
    gen[bbi->id][i].set = MAX_CACHE_SETS;

    free_queue(&worklist);
}
Ejemplo n.º 11
0
static void
map_bbi_loop()
{
    Queue	    worklist;
    tcfg_node_t	    *src, *dst;
    tcfg_edge_t	    *e;

    init_queue(&worklist, sizeof(tcfg_node_t *));
    enqueue(&worklist, &tcfg[0]);
    tcfg[0]->flags = 1;
    while (!queue_empty(&worklist)) {
	src = *((tcfg_node_t **) dequeue(&worklist));
	for (e = src->out; e != NULL; e = e->next_out) {
	    dst = e->dst;
	    if (exit_loop(e))
		deal_exit_edge(e);
	    else if (dst->flags == 0)
		deal_other_edge(e);
	    
	    if (dst->flags == 0) {
		enqueue(&worklist, &dst);
		dst->flags = 1;
	    }
	}
    }
    clear_bbi_flags();
    free_queue(&worklist);
}
Ejemplo n.º 12
0
/* 
 populates rank lists of g.  there are some key details:
 1) the input graph ordering must be respected (in left to right initialization)
 2) connected components are separated and marked with indices
 3) series-parallel graphs (includes trees, obviously) must not have crossings
*/
static void build_ranks(Agraph_t *g, boolean down)
{
	queue			*q;
	component_t c;
	int				r;
	Agnode_t	*n;
	Agedge_t	*e;

	c = build_components(g, down);

	/* process each each component */
	q = new_queue(agnnodes(g)+1);
	for (r = 0; r < c.r; r++) {
		enqueue(q,c.root[r]);
		if ((r + 1 >= c.r)||(ND_component(c.root[r])!=ND_component(c.root[r+1]))) {
			while ((n = dequeue(q))) {
				install(g,n);
					if (down) {
						for (e = agfstout(g,n); e; e = agnxtout(g,e))
							if (--ND_priority(e->head) == 0) enqueue(q,e->head);
					}
					else {
						for (e = agfstin(g,n); e; e = agnxtin(g,e))
							if (--ND_priority(e->tail) == 0) enqueue(q,e->head);
					}
			}
		}
	}
	free_queue(q);
}
Ejemplo n.º 13
0
//产生一个随机地图, rate决定地图的渲染率. 地图大小应在mcMap中设定
int
gen_map(McMap * mcMap, double rate)
{
	int i, j, retv = 0, count = 0;
	int prev = 0, trans = 0, next = 0;
	double sum;
	pLinkList pList;
	pQueuePoint pqp;

	pList = init_queue();
	if (pList == NULL)
		return -1;

	srandom(time(NULL));

	//随机选择一个渲染点
	i = random() % (mcMap->row - 2) + 1;
	j = random() % (mcMap->col - 2) + 1;

	sum = mcMap->row * mcMap->col + 0.1;
	while (count / sum < rate) {	//保证一定的渲染率
		pqp = calloc(1, sizeof (QueuePoint));
		if (pqp == NULL) {
			retv = -1;
			goto END;
		}
		pqp->i = i;
		pqp->j = j;
		insert_node(pList, pqp);	//加入渲染队列
		mcMap->map[i][j].exit |= NODE_QUEUED;

		while (!is_empty(pList)) {
			pqp = read_first(pList);	//取队列首点

			//产生该点的随机出口
			gen_exit(mcMap, pqp->i, pqp->j, count / (rate * sum),
				 &prev, &trans, &next);

			//产生该点的东东, ncp, box, boss...
			gen_item(mcMap, pqp->i, pqp->j);

			//加入该点的出口点
			if (check_exit_node(pList, mcMap, pqp->i, pqp->j, 0) ||
			    check_exit_node(pList, mcMap, pqp->i, pqp->j, 1) ||
			    check_exit_node(pList, mcMap, pqp->i, pqp->j, 2) ||
			    check_exit_node(pList, mcMap, pqp->i, pqp->j, 3)) {
				retv = -1;
				goto END;
			}
			delete_node(pList, 0, 1);	//从队列中删除该点
			if ((++count) / sum > rate)	//渲染率达到就跳出
				goto END;
		}		//end of while(...)
		random_select(mcMap, &i, &j);	//如果一个点不够渲染率, 则再选择一个
	}
      END:
	free_queue(pList, 1);	//释放队列资源
	return retv;
}
Ejemplo n.º 14
0
void divert_kill(void)
{
	lock();

	free_queue(&_packet_queue);
	free_queue(&_packet_free);

	free_ifs();

	// XXX
	NdisFreeBufferPool(_buf_pool);
	NdisFreePacketPool(_packet_pool);

	unlock();

	NdisFreeSpinLock(&_lock);
}
Ejemplo n.º 15
0
} END_TEST

START_TEST (single_item) {
  Job job;
  Queue *q = new_queue();
  assert_not_null(q);
  q_enqueue(q, &job);
  Job *d_job = q_dequeue(q);
  assert_equal(&job, d_job);
  free_queue(q);
} END_TEST
/**
 * free_queue - frees an entire queue of structs of type Queue
 *
 * @queue: queue is a pointer to queue of type Queue
 *
 * Description:  Given a pointer to a queue, the function will free the entire
 * queue
 */
void free_queue(Queue *queue)
{
	if (queue == NULL)
		return ();
	if (queue->next != NULL)
	{
		free_queue(queue->next);
	}
	free(queue->str);
	free(queue);
}
Ejemplo n.º 17
0
void free_queue(qNode *q){
    if(q->next!=NULL){
        free_queue(q->next);
        q->next=NULL;
        free(q);
        q=NULL;
    }
    else
        free(q); 

}
Ejemplo n.º 18
0
} END_TEST

START_TEST(check_queue_size) {
  Job job1, job2;
  Queue *q = new_queue();
  assert_equal(0, q_size(q));
  q_enqueue(q, &job1);
  assert_equal(1, q_size(q));
  q_enqueue(q, &job2);
  assert_equal(2, q_size(q));
  free_queue(q);
} END_TEST
Ejemplo n.º 19
0
void
pushback_line (p_queue_t queue, char *input)
{

if (input == NULL ) return;

  p_entry_t entry_new = (p_entry_t) malloc (sizeof (entry_t));

if (entry_new == NULL )
{
free_queue ( queue );
Error ( "Zlyhala alokacia pamete \n" );
}

  entry_new->line = (char *) malloc (sizeof (char) * (strlen (input) + 1));

if ( entry_new->line == NULL )
{
free ( entry_new );
free_queue ( queue );
Error ( "Zlyhala alokacia pamete \n" );
}

  strcpy (entry_new->line, input);

  entry_new->next = NULL;
  if (queue->first == NULL)
    {
      queue->first = entry_new;
      queue->last = entry_new;
    }
  else
    {
      queue->last->next = entry_new;
      queue->last = entry_new;
    }
}
Ejemplo n.º 20
0
void finish(int sig) {
  printf(BAR);
  printf("Finishing:\n");
  free(listener);
#ifdef VERBOSE
  printf("Freeing queues.\n");
#endif
  free_queue(my_queue);
  free_queue(backup_queue);
  if(server_list) {
#ifdef VERBOSE
    printf("Freeing server list.\n");
#endif
    free_host_list(server_list, 1);
  }
  if(failed_hosts) {
#ifdef VERBOSE
    printf("Freeing failed hosts list.\n");
#endif
    free_host_list(failed_hosts, 1);
  }
#ifdef VERBOSE
  printf("Destroying mutexes.\n");
#endif
  pthread_mutex_destroy(&count_mutex);
  pthread_mutex_destroy(&server_list_mutex);
  pthread_mutex_destroy(&failure_mutex);
  pthread_mutex_destroy(&d_add_mutex);
  if(listener_thread) {
#ifdef VERBOSE
    printf("Killing listener thread.\n");
#endif
    pthread_kill(listener_thread, SIGTERM);
  }
  printf(BAR);
  exit(0);
}
Ejemplo n.º 21
0
} END_TEST

START_TEST (multiple_items) {
  Job job1, job2;
  Queue *q = new_queue();
  assert_not_null(q);
  q_enqueue(q, &job1);
  q_enqueue(q, &job2);
  assert_false(q_empty(q));
  
  Job *d_job1 = q_dequeue(q);
  Job *d_job2 = q_dequeue(q);
  assert_equal(&job1, d_job1);
  assert_equal(&job2, d_job2);
  free_queue(q);
} END_TEST
Ejemplo n.º 22
0
void test_queue() {
	Queue q;
	init_queue(&q);
	for (int i = 0; i < 10; i++) {
		enqueue(&q, i);
	}

	std::cout << "size: " << q.size << std::endl;

	for (int i = 0; i < 10; i++) {
		std::cout << dequeue(&q) << " ";
	}
	std::cout << std::endl;
	std::cout << "size: " << q.size << std::endl;
	free_queue(&q);
}
Ejemplo n.º 23
0
void create_table(cube *(*construct_cube)(cube*),
                      hash_cube_t (*hash_cube)(cube*),
                      cube *(*reconstruct_stickers)(hash_cube_t*),
                      int total_count
                      ) {
  hash_set_t hash_set = new_hash_set(hash_cube_index, hash_cube_equals);
  queue q = new_queue();

  cube *c0 = construct_cube(init_cube());
  hash_cube_t h0 = hash_cube(c0);
  delete_cube(c0);

  enqueue(&q, h0);
  insert(&hash_set, &h0);

  int count = 0;
  int depth = 0;
  while (queue_size(&q) != 0) {
    int n = queue_size(&q);
    for (int i = 0; i < n; ++i) {
      ++count;
      if (count % 1000 == 0) {
        fprintf(stderr, "%f\n", (float) count / total_count);
      }

      hash_cube_t val = dequeue(&q);
      cube *c1 = reconstruct_stickers(&val);
      print_cube_flat(c1);
      printf(",%d\n", depth);

      for (int i = 0; i < 18; ++i) {
        cube *c2 = cube_expand[i](c1);
        hash_cube_t h1 = hash_cube(c2);
        if (!contains(&hash_set, &h1)) {
          enqueue(&q, h1);
          insert(&hash_set, &h1);
        }
        delete_cube(c2);
      }
      delete_cube(c1);
    }
    ++depth;
  }

  free_queue(&q);
  free_hash_set(&hash_set);
}
Ejemplo n.º 24
0
int main(void) {
	queue q;		// Discovered vertices yet to be processed
	int v;			// Current Vertex
	int x[] = {1,2,3,4,5,6,7,8};

	init_queue(&q);
	for (int i = 0; i < 8; i++) {
		enqueue(&q, x[i]);
	}

	while (!empty_queue(&q)) {
		v = dequeue(&q);
		printf("vertex.. %d\n", v);
	}

	free_queue(&q);
}
Ejemplo n.º 25
0
node *bfs(node *root, char searchfor) {
	mininode *temp;
	mininode *curmn;
	mininode *queue;
	node *foundnode = NULL;

	/* Enqueue root node into mininode queue */
	curmn = safe_malloc(sizeof(mininode));
	curmn->n = root;
	curmn->next = NULL;
	queue = curmn;

	/* Perform breadth-first search */
	while (queue != NULL) {
		curmn = dequeue(&queue);

		/* If we've found the char, destroy queue and end loop */
		if (curmn->n->c == searchfor) {
			foundnode = curmn->n;
			free_queue(queue);
			break;
		/* If we're still looking */
		} else {
			/* If we have a left child, add to end of queue */
			if (curmn->n->left != NULL) {
				temp = safe_malloc(sizeof(mininode));
				temp->n = curmn->n->left;
				temp->next = NULL;
				enqueue(temp, &queue);
			}

			/* If we have a right child, add to end of queue */
			if (curmn->n->right != NULL) {
				temp = safe_malloc(sizeof(mininode));
				temp->n = curmn->n->right;
				temp->next = NULL;
				enqueue(temp, &queue);
			}
		}
		free(curmn);
	}

	return foundnode;

}
Ejemplo n.º 26
0
int main(int argc, char *argv[]) {
	char s[100];
	QUEUE *q = NULL;
	Q_ELEMENT_WHAT *qpt;
	int i, n;

	q = init_queue(q, what_cmp);
	qpt = (Q_ELEMENT_WHAT *) malloc(sizeof(double));
	while (fgets(s, 99, stdin) != NULL) {
		switch (s[0]) {
			case 'n':
				n = atoi(strtok(s+1, " "));
				printf("n: %d\n", n);
				if (n < 1)
					break;
				qpt = (Q_ELEMENT_WHAT *) malloc(n * sizeof(Q_ELEMENT_WHAT));
				printf("enqueued ");
				for (i = 0; i < n; i++) {
					qpt[i] = atof(strtok(NULL, " \n"));
					printf("%g ", qpt[i]);
				}
				printf("\n");
				enqueue(q, qpt, n);
				break;
			case 'e':
				*qpt = atof(s+1);
				enqueue(q, qpt, 1);
				break;
			case 'd':
				printf("d %g\n", dequeue(q));
				break;
			case 'p':
				print_queue(q);
				break;
			case 'q':
				free_queue(q);
				exit(0);
				break;
			default:
				printf("%s", Q_HELP);
				break;
		}
	}
	return 0;
}
Ejemplo n.º 27
0
RESULT delete_queue(QUEUE_TICKET ticket)
{//Free a queue struct and it's associated memory
	RESULT outcome = set_result(SUCCESS,"");
	PRIORITY_QUEUE* pQueue = redeem_ticket(ticket);

	//Ticket returned a valid queue, delete it
	if(pQueue != NULL)
	{	
		queue_guard.queues[decrypt_ticket(ticket)] = NULL;	//remove refernce in the array of queues
		queue_guard.size = queue_guard.size - 1;	//decrement the size
		
		free_queue(pQueue);
	}
	else
		outcome = set_result(TICKET_INVALID,"Provided an invalid queue ticket");
		
	return outcome;
}
Ejemplo n.º 28
0
static void trace_draw_scope(void *vp)
{
    struct drawing_queue *q;
    q = (struct drawing_queue *)vp;
    if(!midi_trace.flush_flag)
    {
	if(view_soundspec_flag)
	    draw_scope(q->values);
	if(ctl_speana_flag)
	{
	    CtlEvent e;
	    e.type = CTLE_SPEANA;
	    e.v1 = (long)q->values;
	    e.v2 = FFTSIZE/2;
	    ctl->event(&e);
	}
    }
    free_queue(q);
}
Ejemplo n.º 29
0
/*
TODO tentar diminuir o numero de passos
*/
int main(void) {

    int dimension=3;
    int **initial = mount_board("./initial_state.txt");
    if(initial == NULL) return -1;
    int **final = mount_board("./final_state.txt");
    if(final == NULL) return -1;

    heap_node *node = NULL;
    node_queue *queue = NULL;

    solve_puzzle(initial, final, &node, &queue, dimension);

    free_matrix(initial, dimension);
    free_matrix(final, dimension);
    free_priority_queue(search_root(node));
    free_queue(&queue);

    printf("ok\n");

    return 0;
}
Ejemplo n.º 30
0
void multiprogram(FILE *ptr_file, queue *q_ready, queue *q_process)
{
	process *curr_proc = NULL;		/* the current process removed from the front of the ready queue */
	char **token_arr = NULL;		/* array of tokens used to store the current instruction */
	char buffer[256];			/* buffer used to store the string read from the input file */
	queue *q_wait = init_queue();

	while (!(empty_queue(q_ready))) {	/* continue executing processes until no processes remain in the ready state */
		curr_proc = (process *) dequeue(q_ready);

		fsetpos(ptr_file, &(curr_proc->process_fpos));	/* update the file read position curr_proc's next instruction */
		fgets(buffer, 256, ptr_file);

		token_arr = tokenize_str(buffer);
		int continue_processing = TRUE;
		int ret_val = -999;
		while (continue_processing) {
			ret_val = process_instruction(curr_proc, q_ready, q_process, q_wait, token_arr);
			free_token(token_arr);

			if (ret_val == 0) {		/* alloc/dealloc was successful continue processing at next instruction */
				fgetpos(ptr_file, &(curr_proc->process_fpos));
				fgets(buffer, 256, ptr_file);

				token_arr = tokenize_str(buffer);
				continue_processing = TRUE;
			} else if (ret_val == 1) { 	/* a "SL #" instruction was encountered continue processing later */
				fgetpos(ptr_file, &(curr_proc->process_fpos)); /* update the processes fpos */
				continue_processing = FALSE;
			} else if (ret_val == -1) {	/* alloc/dealloc failed continue processing later at same instruction */
				continue_processing = FALSE;
			}
		}
	}
	free_queue(q_wait);

	return;
}