Exemple #1
0
int main(void)
{

	dict_h lh ;
	dict_iter iter ;
	int i ;
	int *ip ;

	lh = dll_create( int_comp, int_kcomp, 0 ) ;

	for ( i = 0 ; i < N ; i++ )
	{
		nums[ i ] = 10-i ;
		if ( dll_insert( lh, &nums[ i ] ) != DICT_OK )
		{
			printf( "Failed at %d\n", i ) ;
			exit( 1 ) ;
		}
	}

	printf( "Successor test\n" ) ;
	for ( ip=INTP(dll_minimum( lh )) ; ip ; ip=INTP(dll_successor( lh, ip )) )
		printf( "%d\n", *ip ) ;
	printf( "Predecessor test\n" ) ;
	for ( ip=INTP(dll_maximum( lh )) ; ip ; ip=INTP(dll_predecessor( lh, ip )) )
		printf( "%d\n", *ip ) ;

	printf( "Search/delete test\n" ) ;
	i = 7 ;
	ip = INTP( dll_search( lh, &i ) ) ;
	if ( ip == NULL )
		printf( "Search failed\n" ) ;
	else
		if ( dll_delete( lh, ip ) != DICT_OK )
		{
			printf( "Delete failed\n" ) ;
			exit( 0 ) ;
		}

	printf( "Successor test 2\n" ) ;
	for ( ip=INTP(dll_minimum( lh )) ; ip ; ip=INTP(dll_successor( lh, ip )) )
		printf( "%d\n", *ip ) ;
	printf( "Predecessor test 2\n" ) ;
	for ( ip=INTP(dll_maximum( lh )) ; ip ; ip=INTP(dll_predecessor( lh, ip )) )
		printf( "%d\n", *ip ) ;

	printf( "Iteration test\n" ) ;
	iter = dll_iterate( lh, DICT_FROM_START ) ;
	while (( ip = INTP( dll_nextobj( lh, iter ) ) ))
		if ( *ip == 5 )
			(void) dll_delete( lh, ip ) ;
		else
			printf( "%d\n", *ip ) ;

	exit( 0 ) ;
}
Exemple #2
0
int list_replace_items(pgenobj_cmp_t lri_cmp, DLL_NODE_PTR list)
{
	int error = 0;

	FF_VALIDATE(list);

	list = dll_first(list);
	while (!DLL_IS_HEAD_NODE(list))
	{
		DLL_NODE_PTR list_walker = NULL;

		list_walker = dll_next(list);

		while (!DLL_IS_HEAD_NODE(list_walker))
		{
			if ((*lri_cmp)(list->data.u.var, list_walker->data.u.var))
			{
				list = dll_previous(list);
				dll_delete(list->next);
				break;
			}

			list_walker = dll_next(list_walker);
		}

		list = dll_next(list);
	}

	return(error);
}
Exemple #3
0
int dll_free_holdings(DLL_NODE_PTR head)
{
	DLL_NODE_PTR node = NULL;
	int count = 0;

	FF_VALIDATE(head);
	if (head == NULL)
		return(0);
	
	dll_rewind(&head);

	node = dll_first(head);
	while (!DLL_IS_HEAD_NODE(node))
	{
		dll_delete(node);

		count++;
		node = dll_first(head);
	}

#ifdef DLL_CHK
	assert(DLL_COUNT(head) == 0);
#endif

	head->next = head->previous = NULL;

#ifdef FF_CHK_ADDR
	head->check_address = NULL;
#endif

	memFree(head, "Header Node");          

	return(count);
}
Exemple #4
0
int main(void) {
	A* a = malloc(sizeof(A)), *b = malloc(sizeof(A)), *c = NULL;
	List* l = list_init();
	Stack* s = stack_init();
	Queue* q = queue_init();
	DoubleLinkedList* d = dll_init();
	printf("a: %d\nB: %d\nc: %d\n", (int)a, (int)b, (int)c);
	a->a1 = 1;
	a->a2 = 'c';
	b->a1 = 2;
	b->a2 = 'a';

	printf("\n=== LIST TEST ===\n");
	list_add(l, a, 0);
	list_append(l, b);
	list_remove(l, 0);
	list_print(l);	
	c = list_get(l, 0);
	printf("c: %d\n", (int)c);
	list_delete(l);

	printf("\n=== STACK TEST ===\n");
	stack_push(s, b);
	stack_push(s, a);
	stack_pop(s);
	stack_print(s);
	c = stack_peek(s);
	printf("c: %d\n", (int)c);
	stack_delete(s);

	printf("\n=== QUEUE TEST ===\n");
	queue_push(q, a);
	queue_push(q, b);
	queue_pop(q);
	queue_print(q);
	c = queue_peek(q);
	printf("c: %d\n", (int)c);
	queue_delete(q);

	printf("\n=== DOUBLE LINKED LIST TEST ===\n");
	dll_add(d, b, 0);
	dll_prepend(d, a);
	dll_remove(d, 1);
	dll_print(d);
	c = dll_get(d, 0);
	printf("c: %d\n", (int)c);
	dll_delete(d);

	free(a);
	free(b);
	return 0;
}
Exemple #5
0
void dllhashtable_delete(struct DLLHASHTABLE* dllhashtable_ptr,
	void* key)
{
	struct DLL* dll_ptr;
	struct HASHTABLE* hashtable_ptr;
	struct HASHITEM* hashitem_ptr;
	struct DLLHASHTABLE_HASHTABLEVALUE* hashtablevalue_ptr;
	struct DLLHASHTABLE_DLLITEM* dllitem_ptr;

	dll_ptr = dllhashtable_ptr->dll_ptr;
	hashtable_ptr = dllhashtable_ptr->hashtable_ptr;

	hashitem_ptr = hashtable_search(hashtable_ptr, key);
	hashtablevalue_ptr = hashitem_ptr->value;
	dllitem_ptr = hashtablevalue_ptr->dllitem_ptr;

	dll_delete(dll_ptr, (struct DLLITEM*)dllitem_ptr);
	hashtable_delete(hashtable_ptr, key);
}
Exemple #6
0
int main(int argc, char *argv[]) {

  dllist_t *list = (dllist_t*) malloc(sizeof(dllist_t));
  dll_init(list);
  dll_print(list);

  dll_add(list, 12);
  dll_print(list);

  dll_add(list, 12);
  dll_add(list, 13);
  dll_add(list, 14);
  dll_print(list);
  
  dll_remove(list, 12);
  dll_print(list);

  dll_delete(list);
  free(list);
  return 0;
}
Exemple #7
0
int main(void)
{
    doublylinkedlist *sample = dll_create();
    doublylinkedlistnode node;

    char input[15][30] = {0, };
    
    int position = 0;
    int element = 0;

    printf("ListCommader\n");

    printf("Set list name: ");
    //scanf("%s", &input[14]);
    input[14][0] = 's';
    input[14][1] = 'a';
    input[14][2] = 'm';
    input[14][3] = 'p';
    input[14][4] = 'l';
    input[14][5] = 'e';
    printf("%s\n", input[14]);

    printf("\nHint: h<enter>\n");
    while(true)
    {
        printf("Select list type: ");
        scanf("%s", &input[15]);

        if(!strcmp("q", input[15]))
            break;
        else if(!strcmp("h", input[15]))
        {
            printf("--------------------------------\n");
            printf("Available list types            \n");
            printf("dll     Use DoublyLinkedList    \n");
            printf("--------------------------------\n");
            printf("Available commands              \n");
            printf("q       Quit ListCommander      \n");
            printf("--------------------------------\n");
        }
        else if(!strcmp("dll", input[15]))
        {
            printf("\nYou are in [%s:doublylinkedlist].\n", input[14]);
            while(true)
            {
                printf("Enter command: ");
                scanf("%s", &input[0]);
                
                if(!strcmp("h", input[0]))
                {
                    printf("--------------------------------\n");
                    printf("Available commands              \n");
                    printf("a       Add element             \n");
                    printf("r       Remove element          \n");
                    printf("c       Clear all elements      \n");
                    printf("l       Show length             \n");
                    printf("s       Show all elements       \n");
                    printf("q       Close and delete list   \n");
                    printf("--------------------------------\n");
                }
                else if(!strcmp("a", input[0])) 
                {
                    printf("Position: ");
                    scanf("%s", &input[1]);
                    
                    printf("Value of the element: (int)");
                    scanf("%s", &input[2]);

                    position = strtol(input[1], NULL, 10);
                    element = strtol(input[2], NULL, 10);

                    node.element = element;
                    dll_add_element(sample, position, node);

                    printf("\"%d\" to %d added.\n", element, position);
                }
                else if(!strcmp("r", input[0])) 
                {
                    printf("Position: ");
                    scanf("%s", &input[1]);

                    position = strtol(input[1], NULL, 10);

                    dll_remove_element(sample, position);
                    
                    printf("Element of position %d has been removed.\n", position);
                }
                else if(!strcmp("c", input[0]))
                    dll_clear(sample);
                else if(!strcmp("l", input[0]))
                    printf("Size: %d\n", dll_get_length(sample));
                else if(!strcmp("s", input[0]))
                {
                    printf("--------------------------------\n");
                    dll_interate(sample);
                    printf("--------------------------------\n");
                }
                else if(!strcmp("q", input[0]))
                    break;
                else
                    printf("%s is not a command\n");
            }

            dll_delete(sample);
            printf("[%s:doublylinkedlist] has been deleted.\n", input[14], input[15]);
            printf("Hint: q<enter> again to quit\n");
        }
        else
            printf("%s is not a list type or a command\n", input[15]);
    }
    return EXIT_SUCCESS;
}
/* Get flow ring ID, if not present try to create one */
static INLINE int
dhd_flowid_lookup(dhd_pub_t *dhdp, uint8 ifindex,
                  uint8 prio, char *sa, char *da, uint16 *flowid)
{
	uint16 id;
	flow_ring_node_t *flow_ring_node;
	flow_ring_table_t *flow_ring_table;
	unsigned long flags;

	DHD_INFO(("%s\n", __FUNCTION__));

	if (!dhdp->flow_ring_table)
		return BCME_ERROR;

	flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;

	id = dhd_flowid_find(dhdp, ifindex, prio, sa, da);

	if (id == FLOWID_INVALID) {

		if_flow_lkup_t *if_flow_lkup;
		if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;

		if (!if_flow_lkup[ifindex].status)
			return BCME_ERROR;

		id = dhd_flowid_alloc(dhdp, ifindex, prio, sa, da);
		if (id == FLOWID_INVALID) {
			DHD_ERROR(("%s: alloc flowid ifindex %u status %u\n",
			           __FUNCTION__, ifindex, if_flow_lkup[ifindex].status));
			return BCME_ERROR;
		}

		/* register this flowid in dhd_pub */
		dhd_add_flowid(dhdp, ifindex, prio, da, id);
	}

	ASSERT(id < dhdp->num_flow_rings);

	flow_ring_node = (flow_ring_node_t *) &flow_ring_table[id];
	DHD_FLOWRING_LOCK(flow_ring_node->lock, flags);
	if (flow_ring_node->active) {
		DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
		*flowid = id;
		return BCME_OK;
	}

	/* Init Flow info */
	memcpy(flow_ring_node->flow_info.sa, sa, sizeof(flow_ring_node->flow_info.sa));
	memcpy(flow_ring_node->flow_info.da, da, sizeof(flow_ring_node->flow_info.da));
	flow_ring_node->flow_info.tid = prio;
	flow_ring_node->flow_info.ifindex = ifindex;
	flow_ring_node->active = TRUE;
	if (flow_ring_node->status != 0)
		DHD_ERROR(("setting flowring status to pending from %d\n", flow_ring_node->status));

	flow_ring_node->status = FLOW_RING_STATUS_PENDING;
	DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
	DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
	dll_prepend(&dhdp->bus->const_flowring, &flow_ring_node->list);
	DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);

	/* Create and inform device about the new flow */
	if (dhd_bus_flow_ring_create_request(dhdp->bus, (void *)flow_ring_node)
	        != BCME_OK) {
		DHD_FLOWRING_LOCK(flow_ring_node->lock, flags);
		flow_ring_node->active = FALSE;
		DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
		DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
		flow_ring_node->status = FLOW_RING_STATUS_CLOSED;
		dll_delete(&flow_ring_node->list);
		DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
		DHD_ERROR(("%s: create error %d\n", __FUNCTION__, id));
		return BCME_ERROR;
	}

	*flowid = id;
	return BCME_OK;
}