Esempio n. 1
0
Floor new_floor (int floor_number) {
	
	Floor f;
	f.number = floor_number;
	f.request_button[0] = 0;
	f.request_button[1] = 0;
	f.queue = llist_new();
	f.in_floor = llist_new();
	f.stair_case = llist_new();

	return f;
}
Esempio n. 2
0
static LinkedList *adapters()
{
	if (! _adapters){
		_adapters = llist_new();
	}
	return _adapters;
}
Esempio n. 3
0
/**
 * Returns the list of loaded transcodings plugins
 * @return list of transcoding plugins
 */
static LinkedList *plugins()
{
	if (! _plugins) {
		_plugins = llist_new();
	}
	return _plugins;
}
Esempio n. 4
0
static LinkedList *devices()
{
	if (! _devices) {
		_devices = llist_new();
	}
	return _devices;
}
Esempio n. 5
0
Stack* stack_new()
{
    Stack* st=(Stack*)malloc(sizeof(Stack));
    //st->list=(LList*)malloc(sizeof(LList));
    st->list=llist_new();
    return (st);
}
Esempio n. 6
0
static LinkedList *tcp_clients()
{
	if ( ! _tcp_clients) {
		_tcp_clients = llist_new();
	}
	return _tcp_clients;
}
Esempio n. 7
0
static LinkedList *channels()
{
	if (! _channels){
		_channels = llist_new();
	}
	return _channels;
}
Esempio n. 8
0
static LinkedList *apps()
{
	if (! _apps) {
		_apps = llist_new();
	}
	return _apps;
}
Esempio n. 9
0
int main(){
    int D,N;
    scanf("%d%d",&D,&N);
    LList*peg_1=llist_new();
    LList*peg_2=llist_new();
    LList*peg_3=llist_new();
    int i=1;
    while(i<=D){
      peg_1=llist_append(peg_1,i);
      i++;
    }
    int num_of_steps = 0;

    num_of_steps = play_TOH(peg_1,peg_2,peg_3);
    printf(" No of steps= %d\n",num_of_steps);
    return 0;
}
Esempio n. 10
0
static char* test_newlist() {
	linked_list* list = llist_new();
	mu_assert("** test_newlist: linked_list creation failed.", list != NULL);
	mu_assert("** test_newlist: head not null.", list->head == NULL);
	mu_assert("** test_newlist: tail not null.", list->tail == NULL);
	mu_assert("** test_newlist: size not 0.", list->size == 0);
	
	return 0;
}
Esempio n. 11
0
streambuf_t *streambuf_new(size_t h_limit)
{
	struct streambuf_st *buf;

	pthread_once(&init_once, init_cache);

	buf = malloc(sizeof(*buf));
	if (h_limit < BUFVOL_MAX) {
		buf->ringbuf = llist_new(BUFVOL_MAX * 2);
	} else {
		buf->ringbuf = llist_new(h_limit * 2);
	}
	buf->h_limit = h_limit;
	buf->nr_bytes = 0;
	pthread_mutex_init(&buf->mut, NULL);
	pthread_cond_init(&buf->cond, NULL);
	return buf;
}
Esempio n. 12
0
int cllist_new(void **cllist)
{
	cLinkedList **_cllist = (cLinkedList **)cllist;
	*_cllist = (cLinkedList *)malloc(sizeof(cLinkedList));

	llist_new((void **) & ((*_cllist)->llist));
	pthread_mutex_init(&((*_cllist)->mutex), NULL);

	return 0;
}
Esempio n. 13
0
Lift* create_lift() {

	int floor_num;
	Lift* l = (Lift*)malloc(sizeof(Lift));;

	l->current_floor = 0;
	l->people = llist_new();
	l->direction = 1;
	l->max_limit = 8;
	l->dests = llist_new();
	l->counter = 0;
	l->max_count = 5;
	l->destination = 0;

	for( floor_num = 0; floor_num < NUM_OF_FLOORS; floor_num++ ) {
		l->panel[floor_num] = 0;
	}

	return l;
}
Esempio n. 14
0
static char* test_remove1() {
	linked_list* list = llist_new();
	node* n = llist_insert(list, 1, 1);
	free(llist_remove(list, n));
	
	mu_assert("** test_removehead: size != 0.", list->size == 0);
	mu_assert("** test_removehead: head != tail.", list->head == list->tail);
	mu_assert("** test_removehead: head != NULL.", list->head == NULL);
	
	return 0;
}
Esempio n. 15
0
static char* test_insert2() {
	linked_list* list = llist_new();
	llist_insert(list, 1, 1);
	llist_insert(list, 2, 2);
	
	mu_assert("** test_insert2: head == tail.", list->head != list->tail);
	mu_assert("** test_insert2: head->next != tail.", list->head->next == list->tail);
	mu_assert("** test_insert2: tail->prev != head.", list->tail->prev == list->head);
	mu_assert("** test_insert2: size != 2.", list->size == 2);
	
	return 0;
}
Esempio n. 16
0
/**
 * \brief Adds a new node at the end of the list.
 * Adds a new node at the end of the list. This method creates the node.
 * 
 * \param list LLIST to handle
 * \param c complex number
 * \param iteration number of iteration that have been necessary to create
 * the new node
 * \return the complete LLIST with the new element attached to it
 */
LLIST *
llist_append (LLIST * list, complex c, unsigned int iteration)
{
	LLIST * currentNode = list;
	
	while (currentNode->next != NULL)
	{
		currentNode = currentNode->next;
	}
	currentNode->next = llist_new(c, iteration, NULL);
	
	return list;
}
Esempio n. 17
0
static char* test_insert1() {
	linked_list* list = llist_new();
	node* n = llist_insert(list, 1, 1);
	
	mu_assert("** test_insert1: n->key != 1", n->key == 1);
	mu_assert("** test_insert1: n->data != 1", n->data == 1);
	mu_assert("** test_insert1: unable to insert node.", list->head != NULL);
	mu_assert("** test_insert1: head and tail not equal.", list->head == list->tail);
	mu_assert("** test_insert1: size != 1", list->size == 1);
	mu_assert("** test_insert1: head->next != null.", list->head->next == NULL);
	mu_assert("** test_insert1: head->prev != null.", list->head->prev == NULL);
	
	return 0;
}
Esempio n. 18
0
fslist_p fslist_new(void)
{
	fslist_p fsp;
	fsp = (fslist_p) malloc(sizeof(fslist));
	if (fsp) {
		pthread_rwlock_init(&fsp->lock, NULL);
		fsp->list = llist_new();
		if (fsp->list == NULL) {
			free(fsp);
			return NULL;
		}
	}
	return fsp;
}
Esempio n. 19
0
/**
 * \brief Adds a new node at the beginning of the list.
 * Adds a new node at the beginning of the list. This method creates the node.
 * 
 * \param list LLIST to handle
 * \param c complex number
 * \param iteration number of iteration that have been necessary to create
 * the new node
 * \return the complete LLIST with the new element attached to it
 */
LLIST *
llist_prepend (LLIST * list, complex c, unsigned int iteration)
{
	LLIST * newNode = llist_new(c,iteration, list);
	
	if (newNode == NULL)
	{
		return list;
	}
	else
	{
		return newNode;
	}
}
Esempio n. 20
0
void stack_print(Stack* st)
{
    LList* new3=(LList*)malloc(sizeof(LList));
    new3->head=(Node*)malloc(sizeof(Node));
    LList* new2=(LList*)malloc(sizeof(LList));
    new2->head=(Node*)malloc(sizeof(Node));
    new3=llist_new();
    new2->head=st->list->head;
    while (new2->head!=NULL)
    {
        new3=llist_prepend(new3,new2->head->data);
        new2->head=new2->head->next;
    }
    llist_print(new3);
}
Esempio n. 21
0
static char* test_remove3() {
	linked_list* list = llist_new();
	llist_insert(list, 1, 1);
	node* n = llist_insert(list, 2, 2);
	
	llist_remove(list, n);
	
	mu_assert("** test_remove3: head != tail.", list->head == list->tail);
	mu_assert("** test_remove3: head->next != NULL.", list->head->next == NULL);
	mu_assert("** test_remove3: head->prev != NULL.", list->head->prev == NULL);
	mu_assert("** test_remove3: removed node != n.", n->key == 2);
	
	free(n);
	
	return 0;
}
Esempio n. 22
0
int main (void){

	LNode my_List;
	LNode temp;
	void *ptr;
	ptr	=NULL;
	arr_init(ptr);
	my_List=llist_new(ptr);

	temp=my_List;

	while (temp!=NULL){
		printf("%d\n",temp->data);
		temp=temp->next;
	}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	node_insert(my_List,888,21);

	temp=my_List;

	while (temp!=NULL){
		printf("%d\n",temp->data);
		temp=temp->next;
	}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	node_delete(my_List,21);
	temp=my_List;
	while (temp!=NULL){
		printf("%d\n",temp->data);
		temp=temp->next;
	}









	return 0;
}
Esempio n. 23
0
static char* test_remove4() {
	linked_list* list = llist_new();
	llist_insert(list, 1, 1);
	node* n = llist_insert(list, 2, 2);
	llist_insert(list, 3, 3);
	
	llist_remove(list, n);
	
	mu_assert("** test_remove4: head == tail.", list->head != list->tail);
	mu_assert("** test_remove4: head->next != tail.", list->head->next == list->tail);
	mu_assert("** test_remove4: tail->prev != head.", list->tail->prev == list->head);
	mu_assert("** test_remove4: head->prev != NULL.", list->head->prev == NULL);
	mu_assert("** test_remove4: tail->next != NULL.", list->tail->next == NULL);
	mu_assert("** test_remove4: head != 1.", list->head->key == 3);
	mu_assert("** test_remove4: tail != 3.", list->tail->key == 1);
	
	free(n);
	
	return 0; 
}
Esempio n. 24
0
/**
 * Read a directory into a glib list. Each list entry should
 * be freed with free and the list with g_list_free.
 * FIXME: provide Iterator directory_iterator(const char *dir)!
 */
LList *
read_directory(const char *dir)
{
	DIR *dp;
	struct dirent *ep;
	LList *files = llist_new();

	dp = opendir(dir);
	if (dp == NULL)
		return NULL;

	while ((ep = readdir(dp)) != NULL)
		llist_add(files, xstrdup(ep->d_name));

#if CLOSEDIR_VOID
    	closedir(dp);
#else
	if (closedir(dp) == -1)
		return NULL;
#endif

	return files;
}
Esempio n. 25
0
/**
 * server_new
 *
 * Creates a server structure and initializes the variables
 *
 * @return s Returns the server structure
 */
server* server_new(void) {
	//int i;
	server *s = malloc(sizeof (server));
	if (s == NULL)
		SystemFatal("Malloc() Failed \n");

	s->pid = getpid();
	s->n_clients = 0;
	s->n_max_connected = 0;
	s->n_max_bytes_received = 0;

	s->client_list = llist_new();

	/*for (i = 0; i <= FD_SETSIZE; i++) {
		s->clients[i] = -1;
		}*/

	if (pthread_mutex_init(&s->dataLock, NULL) != 0) {
		free(s);
		return NULL;
	}

	return s;
}
Esempio n. 26
0
void multi_thread_test()
{
	llist_t *ll;
	ll = llist_new(2000);	
	pthread_t pid[10];

	/*
	 * test 4
	 */

	int i;
	for (i=0; i < 6; i++) {
		pthread_create(&pid[i], NULL, producer, ll);
	}
	for (i=6; i<10; i++) {
		pthread_create(&pid[i], NULL, consumer, ll);
	}
	for (i=0; i<10; i++) {
		pthread_join(pid[i], NULL);
	}
	printf("nodes is %d\n", ll->nr_nodes);
	llist_delete(ll);
	printf("%stest4 successful%s\n", COR_BEGIN, COR_END);
}
Esempio n. 27
0
StringHash *
string_hash_new ()
{
	return (StringHash *) llist_new (sizeof (StringHashItem));
}
Esempio n. 28
0
static struct i_bitmap *
i_flood_fill_low(i_img *im,i_img_dim seedx,i_img_dim seedy,
                 i_img_dim *bxminp, i_img_dim *bxmaxp, i_img_dim *byminp, i_img_dim *bymaxp,
		 i_color const *seed, ff_cmpfunc cmpfunc) {
  i_img_dim ltx, rtx;
  i_img_dim tx = 0;

  i_img_dim bxmin = seedx;
  i_img_dim bxmax = seedx;
  i_img_dim bymin = seedy;
  i_img_dim bymax = seedy;

  struct llist *st;
  struct i_bitmap *btm;

  int channels;
  i_img_dim xsize,ysize;
  i_color cval;

  channels = im->channels;
  xsize    = im->xsize;
  ysize    = im->ysize;

  btm = btm_new(xsize, ysize);
  st  = llist_new(100, sizeof(struct stack_element*));

  /* Find the starting span and fill it */
  ltx = i_lspan(im, seedx, seedy, seed, cmpfunc);
  rtx = i_rspan(im, seedx, seedy, seed, cmpfunc);
  for(tx=ltx; tx<=rtx; tx++) SET(tx, seedy);
  bxmin = ltx;
  bxmax = rtx;

  ST_PUSH(ltx, rtx, ltx, rtx, seedy+1,  1);
  ST_PUSH(ltx, rtx, ltx, rtx, seedy-1, -1);

  while(st->count) {
    /* Stack variables */
    i_img_dim lx,rx;
    i_img_dim dadLx,dadRx;
    i_img_dim y;
    int direction;

    i_img_dim x;
    int wasIn=0;

    ST_POP(); /* sets lx, rx, dadLx, dadRx, y, direction */


    if (y<0 || y>ysize-1) continue;
    if (bymin > y) bymin=y; /* in the worst case an extra line */
    if (bymax < y) bymax=y; 


    x = lx+1;
    if ( lx >= 0 && (wasIn = INSIDE(lx, y, seed)) ) {
      SET(lx, y);
      lx--;
      while(lx >= 0 && INSIDE(lx, y, seed)) {
	SET(lx,y);
	lx--;
      }
    }

    if (bxmin > lx) bxmin = lx;
    while(x <= xsize-1) {
      /*  printf("x=%d\n",x); */
      if (wasIn) {
	
	if (INSIDE(x, y, seed)) {
	  /* case 1: was inside, am still inside */
	  SET(x,y);
	} else {
	  /* case 2: was inside, am no longer inside: just found the
	     right edge of a span */
	  ST_STACK(direction, dadLx, dadRx, lx, (x-1), y);

	  if (bxmax < x) bxmax = x;
	  wasIn=0;
	}
      } else {
	if (x > rx) goto EXT;
	if (INSIDE(x, y, seed)) {
	  SET(x, y);
	  /* case 3: Wasn't inside, am now: just found the start of a new run */
	  wasIn = 1;
	    lx = x;
	} else {
	  /* case 4: Wasn't inside, still isn't */
	}
      }
      x++;
    }
  EXT: /* out of loop */
    if (wasIn) {
      /* hit an edge of the frame buffer while inside a run */
      ST_STACK(direction, dadLx, dadRx, lx, (x-1), y);
      if (bxmax < x) bxmax = x;
    }
  }

  llist_destroy(st);

  *bxminp = bxmin;
  *bxmaxp = bxmax;
  *byminp = bymin;
  *bymaxp = bymax;

  return btm;
}
Esempio n. 29
0
void func_test()
{
	char *s = "this is a test";
	char *s2 = "x";
	void *b;
	int i, j;
	llist_t *ll;

	/*
	 * test 1
	 */

	ll = llist_new(20);	
	for (i = 0; i < 4; i++) {
		if (i%3 == 0) {
			llist_append(ll, &s2[0]);
		}
		llist_append(ll, &s[i]);
	}
	
	llist_travel(ll, &show);
	printf("\n");
	for (i = 0; i < 4; i++) {
		llist_prepend(ll, &s[0]);
	}
	llist_travel(ll, &show);
	printf("\n");
	for (i = 0; i < 4; i++) {
		llist_prepend_nb(ll, &s[1]);
	}
	llist_travel(ll, &show);
	printf("\n");
	llist_fetch_head(ll, &b);
	llist_travel(ll, &show);
	printf("\n");
	llist_fetch_head(ll, &b);
	llist_travel(ll, &show);
	printf("\n");
	llist_delete(ll);
	
	printf("%stest1 successful%s\n", COR_BEGIN, COR_END);

	/*
	 * test 2
	 */

	ll = llist_new(1000);
	for (j = 0; j < 100; j++) {
		for (i = 0; i < 10; i++) {
			llist_append_nb(ll, &s[i]);
		}
	}
	printf("append done.\n");
	for (i = 0; i< 100; i++) {
		llist_fetch_head_nb(ll, &b);
		printf("%c", *(char *)b);
	}
	printf("\nthere are %d nodes\n", ll->nr_nodes);
	for (i = 0; i< 100; i++) {
		llist_get_head_nb(ll, &b);
		printf("%c", *(char *)b);
	}
	printf("\n");
	printf("%stest2 successful%s\n", COR_BEGIN, COR_END);
	printf("there are %d nodes\n", ll->nr_nodes);
	
	/*
	 * test 3
	 */
	void *ptr, *ptr2;
	llist_get_head_node_nb(ll, &ptr);
	for (i = 0; i< 100; i++) {
		printf("%c", *(char *)(((llist_node_t *)ptr)->ptr));
		ptr = llist_get_next_nb(ll, ptr);
	}
	printf("\nthere are %d nodes\n", ll->nr_nodes);
	llist_delete(ll);
	printf("%stest3 successful%s\n", COR_BEGIN, COR_END);
	return;
}