int slist_prepend(slist_t *list,void *Value)
{
	if (Value == NULL)
	{ // if no have Value
		return 0;
	}
	slist_node_t *temp_p;
	temp_p=(slist_node_t *)calloc(1,sizeof(slist_node_t));
	if(temp_p==NULL)
	{
		return -1;
	}
	slist_data(temp_p)=Value;
	temp_p->next = NULL;
	if (slist_head(list)==NULL) // the list is empty
	{
		slist_head(list) = temp_p;
		slist_tail(list) = temp_p;
		slist_next(temp_p) = NULL;
		slist_size(list) = 1;
		return 0;
	}
	slist_next(temp_p) = slist_head(list);
	slist_head(list) = temp_p;
	if (slist_tail(list)==NULL)
	{
		slist_tail(list)=temp_p;
	}
	slist_size(list)++;
	return 0;
}
int slist_append(slist_t *list,void *Value)
{
	slist_node_t *temp_p=NULL;
	if (Value == NULL)
	{ // if no have Value
		return 0;
	}
	temp_p=(slist_node_t *)calloc(1,sizeof(slist_node_t));
	if(temp_p==NULL)
	{
		return -1;
	}
	slist_data(temp_p) = Value;
	slist_next(temp_p)=NULL;
	if (slist_head(list)==NULL)
	{
		slist_head(list) = temp_p;
		slist_tail(list) = temp_p;
		slist_size(list)++;
		return 0;
	}
	slist_next(slist_tail(list)) = temp_p;
	slist_tail(list) = temp_p;

	slist_size(list)++;
	return 0;

}
Exemple #3
0
static void test_empty(void)
{
	struct list_node *spos, *ssafe;
	struct node *pos, *safe;

	check(!slist_is_empty(&slist),
	      "slist is empty but slist_is_empty returned false");
	check(!list_is_empty(&list),
	      "list is empty but list_is_empty returned false");

	check(slist_head(&slist) != &slist,
	      "slist is empty but slist_head returned non-self");
	check(list_head(&list) != NULL,
	      "list is empty but list_head returned non-NULL");

	check(slist_tail(&slist) != &slist,
	      "slist is empty but slist_tail returned non-self");
	check(list_tail(&list) != NULL,
	      "list is empty but list_tail returned non-NULL");

	check_loop_never(slist_for_each(spos, &slist),
			 "slist is empty, but slist_for_each looped");
	check_loop_never(list_for_each(pos, &list),
			 "list is empty, but list_for_each looped");

	check_loop_never(slist_for_each_safe(spos, ssafe, &slist),
			 "slist is empty, but slist_for_each_safe looped");
	check_loop_never(list_for_each_safe(pos, safe, &list),
			 "list is empty, but list_for_each_safe looped");

	check_loop_never(slist_for_each_entry(pos, &slist, node),
			 "slist is empty, but slist_for_each_entry looped");
	check_loop_never(slist_for_each_entry_safe(pos, safe, &slist, node),
			 "slist is empty, but slist_for_each-entry_safe looped");
}
int slist_append_list(slist_t* listOne, slist_t* listSec) {
	if (slist_tail(listSec) == NULL && slist_head(listOne) == NULL)
	{ // both of list is NULL
		return 0;
	}
	if (slist_head(listSec) == NULL)
	{ // list two is NULL
		return 0;
	}
	if(!listOne || !listSec) {return -1;}
	if(slist_size(listSec) == 0) {return 0;}
	slist_node_t* p = slist_head(listSec);
	while(p) {
		if( slist_append(listOne, p->data) == -1 ) {return -1;}
		p = slist_next(p);
	}
	slist_size(listOne) += slist_size(listSec);
/*	slist_destroy(l2, SLIST_LEAVE_DATA);*/
	return 0;
	
}
void *slist_pop_first(slist_t *list)
{
	if (slist_head(list)==NULL)
	{
		return NULL;
	}
	slist_node_t *temp_p=NULL;
	void *PopValue;
	temp_p = slist_head(list);
	PopValue= slist_data(temp_p);
	slist_head(list) =slist_next(temp_p);
	free(temp_p);
	int countSize = slist_size(list) -1; 
	if (countSize==0) // if the list have one node
	{
		slist_tail(list)=NULL;
		slist_head(list)=NULL;
		slist_size(list)=0;
	}
	return(PopValue); // return the Value of head list
	
}
void slist_destroy(slist_t *list_p ,slist_destroy_t flag)
{
	if (list_p==NULL)
	{
		return;
	}
	slist_node_t *temp_p;
	temp_p = slist_head(list_p);
	while(temp_p!= NULL)
	{
		slist_head(list_p) = slist_next(temp_p);
		if (flag==SLIST_FREE_DATA)
		{
			free(slist_data(temp_p));
		}
		free(temp_p);
		temp_p = slist_head(list_p);
	}
	free(temp_p);
	slist_size(list_p) = 0;
return;
}
Exemple #7
0
static struct ConfigItem *
find_item(uint32_t hash) {
    SLIST_ITERATOR p = slist_head(configs, NULL);

    while(p != NULL) {
        struct ConfigItem *item = *(struct ConfigItem **)slist_get(p);

        if (item->hash == hash)
            return item;

        p = slist_next(p);
    }

    return NULL;
}
int chtbl_lookup(const struct chtbl_t *htbl, void **data)
{
	struct slist_node *elem;
	int bucket;

	bucket = htbl->hash(*data) % htbl->buckets;

	for (elem = slist_head(&htbl->table[bucket]); elem; elem = slist_next(elem)) {
		if (htbl->match(*data, slist_data(elem))) {
			*data = slist_data(elem);
			return 0;
		}
	}

	return -1;
}
Exemple #9
0
void
configs_cleanup(void) {
    if (!configs)
        return;

    SLIST_ITERATOR p = slist_head(configs, NULL);

    while(p != NULL) {
        struct ConfigItem *item = *(struct ConfigItem **)slist_get(p);

        free(item);

        p = slist_next(p);
    }

    slist_free(configs);
}
//Private Method
int contains(slist_t* list, char* string) {

	if(list == NULL) {
		return -1;
	}

	slist_node_t* p;
	for(p = slist_head(list); p != NULL; p = slist_next(p)) {

		if(slist_data(p) == string) {
			return -1;
		}

	}

	return 0;
}
int chtbl_remove(struct chtbl_t *htbl, void **data)
{
	struct slist_node *elem, *prev;
	int bucket;

	bucket = htbl->hash(*data) % htbl->buckets;
	prev = NULL;

	for (elem = slist_head(&htbl->table[bucket]); elem; elem = slist_next(elem)) {
		if (htbl->match(*data, slist_data(elem))) {
			if (slist_rem_next(&htbl->table[bucket], prev, data) == 0) {
				htbl->size--;
				return 0;
			} else {
				return -1;
			}
		}
		prev = elem;
	}
	return -1;
}
Exemple #12
0
/* Follows the transition arrow from the state, along the edge labeled by the
   symbol.  If no such transition exists, returns FAIL. */
aho_corasick_state_t* aho_corasick_goto_get(aho_corasick_state_t *state,
					    unsigned char symbol) {
	slist_node_t *node;
	switch (state->_transitions.type) {
	case AHO_CORASICK_DENSE_TRANSITIONS:
		return state->_transitions.data.array[symbol];
	case AHO_CORASICK_SPARSE_TRANSITIONS:
		node = slist_head(state->_transitions.data.slist);
		while (node != NULL) {
			if (((aho_corasick_labeled_edge_t *) node->data)
			    ->label == symbol) {
				return ((aho_corasick_labeled_edge_t *)
					node->data)->state;
			}
			node = node->next;
		}
		return FAIL;
	}

	/* FIXME: We should never get here. */
	return FAIL;
}
Exemple #13
0
void print(slist_t *list)
{	
	if(slist_size(list) == 0)
		return;

	slist_node_t *p = slist_head(list);
	while( p != NULL)
	{
		pm_labeled_edge_t* edge = (pm_labeled_edge_t*)slist_data(p);
		pm_state_t* nextState = edge->state;

		if (slist_size(nextState->_transitions) == 0)
			printf("s: %d , l: %c -> " , nextState->id , edge->label);
		else
		{	
			printf("s: %d , l: %c -> " , nextState->id , edge->label);
			print(nextState->_transitions);
		}
		p = slist_next(p);
		
	}

}
void slist_init(slist_t *pointer_list)
{
	slist_head(pointer_list)=NULL;
	slist_tail(pointer_list)=NULL;
	slist_size(pointer_list)=0;
}