Example #1
0
void (list_splice) (SCL_list_t a_list1, size_t a_index, SCL_list_t a_list2)
   {
   S_SCL_list_t* const list1 = a_list1;
   S_SCL_list_t* const list2 = a_list2;

   if (a_index == 0)
      {
      list_join (list2, list1);
      list1->head = list2->head;
      list1->tail = list2->tail;
      list1->count = list2->count;
      list2->head = NULL;
      list2->tail = NULL;
      list2->count = 0;
      return;
      }

   if (list1->count <= a_index)
      {
      list_join (list1, list2);
      return;
      }

   {
   S_node_t* node1;
   S_node_t* node2;
   S_node_t* next;

   node1 = list1->head;
   node2 = list2->head;

   if (node2 == NULL) return;

   while (--a_index > 0) node1 = SUCC(node1);
   next = SUCC(node1);

   SUCC(node1) = node2;
   PRED(node2) = node1;

   node1 = list2->tail;
   SUCC(node1) = next;
   if (next != NULL) PRED(next) = node1;

   list1->count += list2->count;

   list2->head = NULL;
   list2->tail = NULL;
   list2->count = 0;
   }

   return;
   }
Example #2
0
struct element * quick_sort(struct element ** list_ptr) {
  struct element * list = *list_ptr;

  if (!is_empty(list) && list->pointer != list) {
    struct element * list_low = list_init();
    struct element * list_high = list_init();

    double pivot = list_shift(&list);
    double temp;

    while (!is_empty(list)) {
      temp = list_shift(&list);
      if (temp > pivot)
        list_high = list_push(list_high, temp);
      else
        list_low = list_push(list_low, temp);
    }

    quick_sort(&list_low);
    quick_sort(&list_high);

    list_low = list_push(list_low, pivot);
    list = list_join(list_low, list_high);
  }

  *list_ptr = list;

  return list;
}
Example #3
0
void bucket_sort(int *arr, int size, int max, int min)
{
	int i;
	int interval = (max - min)/size;
	List *list = (List*)malloc(sizeof(List)*size);
	List *array = (List*)malloc(sizeof(List)*size);
	for(i = 0; i < size; i++)
	{
		list[i].next = NULL;
		array[i].value = arr[i];
		array[i].next = NULL;
	}

	for(i = 0; i < size; i++)
	{
		int k = (array[i].value - min)/interval;
		list_insert(&(list[k]), &(array[i]));		
	}
	for(i = 1; i < size; i++)
	{
		list_join(&(list[0]), &(list[i]));
	}
	List *head = list[0].next;
	for(i = 0; i < size; i++)
	{
		arr[i] = head->value;
		head = head->next;
	}

	free(list);
	free(array);
}
Example #4
0
tm_obj tm_add(  tm_obj a, tm_obj b){
	if( a.type == b.type ){
		switch( a.type ){
			case TM_NUM:
				get_num(a) += get_num(b);
				return a;
			case TM_STR:
			{
				char* sa = get_str(a);
				char* sb = get_str(b);
				int la = get_str_len(a);
				int lb = get_str_len(b);
				if( la == 0){
					return b;
				}
				if( lb == 0){
					return a;
				}
				int len = la + lb;
				tm_obj des = str_new(NULL, len);
				char*s = get_str(des);
				memcpy(s,      sa, la);
				memcpy(s + la, sb, lb);
				return des;
			}
			case TM_LST:
			{
				return list_join(get_list(a), get_list(b) );
			}
		}
	}
    tm_raise("tm_add: can not add %t and %t", (a),(b));
	return obj_none;
}
Example #5
0
void ipv4_ifr_get_addr_func(struct if_record *ifr, struct linked_list *ret_list) {
	if (ifr->flags & IFF_RUNNING) { //ifr->status ?
		//struct linked_list *temp_list = list_find_all(ifr->addr_list, addr_is_v4);
		struct linked_list *temp_list = list_filter(ifr->addr_list, addr_is_v4, addr_clone);
		if (list_join(ret_list, temp_list)) {
			free(temp_list);
		} else {
			PRINT_ERROR("todo error");
			//list_free(temp_list, nop_func);
			list_free(temp_list, free);
		}
	}
}
Example #6
0
/*
 * Return an allocated string with the string representation of a list.
 * May return NULL.
 */
    char_u *
list2string(typval_T *tv, int copyID, int restore_copyID)
{
    garray_T	ga;

    if (tv->vval.v_list == NULL)
	return NULL;
    ga_init2(&ga, (int)sizeof(char), 80);
    ga_append(&ga, '[');
    if (list_join(&ga, tv->vval.v_list, (char_u *)", ",
				       FALSE, restore_copyID, copyID) == FAIL)
    {
	vim_free(ga.ga_data);
	return NULL;
    }
    ga_append(&ga, ']');
    ga_append(&ga, NUL);
    return (char_u *)ga.ga_data;
}
Example #7
0
struct sighttpd * sighttpd_init (struct cfg * cfg)
{
        struct sighttpd * sighttpd;
        const char *portname;
        int port;

        if ((sighttpd = malloc (sizeof(*sighttpd))) == NULL)
                return NULL;

        portname = dictionary_lookup (cfg->dictionary, "Listen");
        if (portname == NULL) {
                fprintf (stderr, "Portname not specified.\n");
                exit (1);
        }

        /* Get server's IP and standard service connection* */
        if (!isdigit(portname[0])) {
                struct servent *srv = getservbyname(portname, "tcp");

                if (srv == NULL) {
                        perror(portname);
                        exit (1);
                }

                port = ntohs(srv->s_port);
        } else {
                port = atoi(portname);
        }

        sighttpd->port = port;

	sighttpd->resources = cfg->resources;

	sighttpd->resources = list_append (sighttpd->resources, status_resource(sighttpd));
	sighttpd->resources = list_append (sighttpd->resources, flim_resource());
	sighttpd->resources = list_append (sighttpd->resources, uiomux_resource());
	sighttpd->resources = list_append (sighttpd->resources, kongou_resource());
	sighttpd->resources = list_join (sighttpd->resources, statictext_resources (cfg->dictionary));

        return sighttpd;
}
Example #8
0
NODE* parse(char **exp) {
    if (!sym_map) parser_init();
    debug("Parse List: %s\n",*exp);
    NODE *head = NIL;
    while (**exp) {
        switch (*((*exp)++)) {
            case '\'': {
                debug("to quote: %s\n",*exp);
                NODE *quoted = parse(exp);
                debugVal(quoted->data,"quoted: ");
                list_push(newNODE(newPRIMFUNC(SPEC_QUOTE,l_quote),newNODE(quoted->data,NIL)),&head);
                if (quoted->addr) head = list_join(list_reverse((NODE*)quoted->addr),head);
                head = list_reverse(head);
                debugVal(head,"expression: ");
                return head;
            }
            case '(':
                list_push(parse(exp),&head);
                break;
            case ')':
                head = list_reverse(head);
                debugVal(head,"expression: ");
                return head;
            case ';':
                while (**exp != '\0' && **exp != '\r' && **exp != '\n') (*exp)++;
                break;
            case '\n':
            case '\r':
            case '\t':
            case ' ':
                break;
            default: {
                char *sym = *exp-1;
                debug("origin: %s\n",sym);
                while (**exp && **exp != ' ' && **exp != ')' && **exp != '\n' && **exp != '\r' && **exp != '\t') (*exp)++;
                char old = **exp;
                **exp = 0;
                debug("literal: %s\n",sym);
                switch (sym[0]) {
                    case '+':
                    case '-':
                        if (!isdigit(sym[1])) {
                            list_push(newSYMBOL(intern(sym)),&head);
                            break;
                        }  
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                        {
                            bool real = false;
                            char *scn = sym+1;
                            while (*scn) {
                                if (*scn == '.') { 
                                    real = true;
                                } else if (!isdigit(*scn)) {
                                    error("Malformed number character %c",*scn);
                                }
                                scn++;
                            }
                            if (real) {
                                list_push(newREAL(atof(sym)),&head);
                            } else {
                                list_push(newINTEGER(atoi(sym)),&head);
                            }
                        }
                        break;
                    default:
                        list_push(newSYMBOL(intern(sym)),&head);
                        break;
                 }
                 **exp = old;
                 if (head->data->type == ID_SYMBOL) {
                    NODE *literal;
                    if ((literal = binmap_find(head->data,literal_map))) {
                        NODE *last = (NODE*)head->addr;
                        incRef(last);
                        decRef(head);
                        incRef(literal->addr);
                        head = last;
                        list_push(literal->addr,&head);
                        decRef(literal);
                    }
                 }
                 debugVal(head,"parsed: ");
             }
        }
    }
    head = list_reverse(head);
    debugVal(head,"dangling: ");
    return head;
}
Example #9
0
/* entry of  listen service */
NEINT32 common_update_entry(struct listen_contex *listen_info)
{
	NEINT32 ret  ,sleep = 0 ;

	struct cm_manager *pmanger  ;
	struct ne_client_map  *client;
	
	NEUINT16 session_id = 0;
#ifdef USER_UPDATE_LIST
	struct list_head *pos ;
	swap_list_t *swap ;
#else 
//	NEINT32 i, num ;
	cmlist_iterator_t cm_iterator ;
#endif 
	
	pmanger = ne_listensrv_get_cmmamager(listen_info) ;	

	if(ne_atomic_read(&pmanger->connect_num) <= 0) {
		ne_sleep(100) ;
		return 0 ;
	}
	
#ifdef USER_UPDATE_LIST
	swap = &listen_info->wait_add ;
	if(0==ne_mutex_trylock(&swap->lock) ) {
		list_join(&swap->list, &listen_info->conn_list) ;
		INIT_LIST_HEAD(&swap->list) ;
		ne_mutex_unlock(&swap->lock) ;
	}
	
	pos = listen_info->conn_list.next ;
	while (pos!=&listen_info->conn_list) {
		client = list_entry(pos,struct ne_client_map , map_list) ;
		pos = pos->next ;
		
		session_id = client->connect_node.session_id ;
		client = pmanger->trylock(pmanger, session_id) ;
		if(client) {
			++sleep;
			ret = tryto_close_tcpsession((ne_session_handle)client, listen_info->operate_timeout ) ;
			if(ret) {
				if(-1==ret)	list_del_init(&client->map_list) ;
				pmanger->unlock(pmanger,session_id) ;
				continue ;
			}
			ret = ne_do_netmsg(client,&listen_info->tcp) ;					
			if(ret > 0) {
				ne_tcpnode_flush_sendbuf(&(client->connect_node)) ;
			}
			else if(ret ==0){
				if(0==tcp_client_close(client,1) ) {
					list_del_init(&client->map_list) ;
				}
			}
			pmanger->unlock(pmanger,session_id) ;
		}
		
	}
#else 
//	num = ne_atomic_read(&pmanger->connect_num);
//	i = 0 ;
	for(client = pmanger->lock_first (pmanger,&cm_iterator) ; client;	client = pmanger->lock_next (pmanger,&cm_iterator) ) {
		if(tryto_close_tcpsession((ne_session_handle)client, listen_info->operate_timeout ) ) {
			continue ;
		}
		ret = ne_do_netmsg(client,&listen_info->tcp) ;
		if(ret>0) {
			ne_tcpnode_flush_sendbuf(&(client->connect_node)) ;
			sleep++ ;
		}
		else if(0==ret) {
			tcp_client_close(client,1) ;
		}
	}
#endif
	if(!sleep ){
		ne_sleep(100);
	}
	return 0;
}