Пример #1
0
void sort_veh_movement(hash_table_t *table){
	node_info* head_node=head_node_info;
	while(head_node->next!=NULL){
		int *value1 = NULL;
		value1 = (int *) HT_LOOKUP(table, head_node->vid_addr);
		Exnode* head_veh_node = (Exnode *)value1;
		Exnode* value2 = (Exnode *)value1;
		while (value2->next!=NULL){
			value2 = value2->next;

		}
		Exnode* tail_veh_node = (Exnode *)value2;
		quicksortlist(head_veh_node, tail_veh_node);
		head_node=head_node->next;
	}
	// come on !! use functions :-)
	// last node with ->next == NULL
	int *value1 = NULL;
	value1 = (int *) HT_LOOKUP(table, head_node->vid_addr);
	Exnode* head_veh_node = (Exnode *)value1;
	Exnode* value2 = (Exnode *)value1;
	while (value2->next!=NULL){
		value2 = value2->next;

	}
	Exnode* tail_veh_node = (Exnode *)value2;
	quicksortlist(head_veh_node, tail_veh_node);
}
Пример #2
0
Exnode* get_next_position(hash_table_t *table,int node_id){
	node_info* head_node=head_node_info;
	while(head_node->next!=NULL){

		if(head_node->vid==node_id){
			int *value1 = NULL;
			value1 = (int *) HT_LOOKUP(table, head_node->vid_addr);
			if (value1!=NULL){
				Exnode* value2=(Exnode *)value1;
				while(value2->next!=NULL){
					if (value2->visit==1) value2=value2->next;
					else {
						value2->visit=1;
						return value2;
					}
				}
				if (value2->visit!=1){
					value2->visit=1;
					return value2;
				}
			}
		}
		head_node=head_node->next;
	}
	// not to leave the last node with ->next=NULL
	if(head_node->vid==node_id){
		int *value1 = NULL;
		value1 = (int *) HT_LOOKUP(table, head_node->vid_addr);
		if (value1!=NULL){
			Exnode* value2=(Exnode *)value1;
			while(value2->next!=NULL){
				if (value2->visit==1) value2=value2->next;
				else {
					value2->visit=1;
					return value2;
					}
				}
				if (value2->visit!=1){
					value2->visit=1;
					return value2;
					}
			}
		}
	return NULL;
}
Пример #3
0
/*---------------------------------------------------------------------------*/
struct xio_session *xio_sessions_cache_lookup(uint32_t session_id)
{
	struct xio_session *s;
	struct xio_key_int32  key;

	spin_lock(&ss_lock);
	key.id = session_id;
	HT_LOOKUP(&sessions_cache, &key, s, sessions_htbl);
	spin_unlock(&ss_lock);

	return s;
}
Пример #4
0
void reset_visit_status(hash_table_t *table,float time, int node_id){
	node_info* head_node=head_node_info;
	while(head_node->next!=NULL){

		if(head_node->vid==node_id){
			int *value1 = NULL;
			value1 = (int *) HT_LOOKUP(table, head_node->vid_addr);
			if (value1!=NULL){
				Exnode* value2=(Exnode *)value1;
				while(value2->next!=NULL){
					if (value2->time == time) {
						value2->visit=0;
						}
					value2=value2->next;
				}
				if (value2->time == time){
					value2->visit=0;
				}
			}
		}
		head_node=head_node->next;
	}
	// not to leave the last node with ->next=NULL
	if(head_node->vid==node_id){
		int *value1 = NULL;
		value1 = (int *) HT_LOOKUP(table, head_node->vid_addr);
		if (value1!=NULL){
			Exnode* value2=(Exnode *)value1;
			while(value2->next!=NULL){
				if (value2->time==time) value2->visit=0;
				value2=value2->next;

				}
				if (value2->time==time) value2->visit=0;
			}
		}

}
Пример #5
0
/*---------------------------------------------------------------------------*/
static int sessions_cache_add(struct xio_session *session,
			      uint32_t session_id)
{
	struct xio_session *s;
	struct xio_key_int32  key = {
		session_id
	};
	HT_LOOKUP(&sessions_cache, &key, s, sessions_htbl);
	if (s != NULL)
		return -1;

	HT_INSERT(&sessions_cache, &key, session, sessions_htbl);

	return 0;
}
Пример #6
0
/*---------------------------------------------------------------------------*/
static int sessions_cache_add(struct xio_session *session,
			      uint32_t session_id)
{
	struct xio_session *s;
	struct xio_key_int32  key = {
		.id = session_id,
		.pad = {0},
	};
	HT_LOOKUP(&sessions_cache, &key, s, sessions_htbl);
	if (s)
		return -1;

	HT_INSERT(&sessions_cache, &key, session, sessions_htbl);

	return 0;
}
Пример #7
0
/*---------------------------------------------------------------------------*/
int xio_sessions_cache_remove(uint32_t session_id)
{
	struct xio_session *s;
	struct xio_key_int32  key;

	spin_lock(&ss_lock);
	key.id = session_id;
	HT_LOOKUP(&sessions_cache, &key, s, sessions_htbl);
	if (s == NULL) {
		spin_unlock(&ss_lock);
		return -1;
	}

	HT_REMOVE(&sessions_cache, s, xio_session, sessions_htbl);
	spin_unlock(&ss_lock);

	return 0;
}
Пример #8
0
int main()
{
    hash_table_t *table = hash_table_new(MODE_VALUEREF);
    int i = 1;
    int val = 100;
    int val2 = 200;
    int j = 2;
    int x =0;
    for (x=0;x<300;x++)
    {
        // use the macro
        HT_ADD(table, &j, &val);
        // or use the function
        //hash_table_add(table, &j, i, (void *) &val, sizeof(int));
        val++;
        j++;
    }
    hash_table_add(table, &j, i, (void *) &val2, 1);
    j--; j--;
    hash_table_remove(table, &j, i);
    HT_REMOVE(table, &j);
    if (hash_table_has_key(table, &j, i))
    {
        printf("Key found %d\n", j);
    }
    else
    {
        printf("Key NOT found %d\n", j);
    }
    val = -100;
    val2 = -200;
    int *value = NULL;
    value = (int* ) HT_LOOKUP(table, &j);
    void** keys = NULL;
    size_t num = hash_table_get_keys(table, keys);
    printf("found %d keys\n", (int)num);
    printf("j -> %d \n", j);
    if (value)
        printf("value is %d\n", *value);
    else
        printf("*value is %p\n", value);

    return 0;
}
Пример #9
0
//read the mobility file and generates a hashtable of linked list with key pointing to vehicle id
hash_table_t* read_mobility_file(char mobility_file[]){
		FILE *fp;
	    char str[128];
	    hash_table_t *table = hash_table_new(MODE_ALLREF);
	    if((fp=fopen(mobility_file, "r"))==NULL) {
	      printf("Cannot open file. %s\n",mobility_file);
	      exit(1);
	    }
	    Exnode* headRef;
	    node_info* Node_info=NULL;

	    head_node_info=Node_info;
	    int *keyholder[10];
	    int i=0;
	    while(!feof(fp)) {
	      if(fgets(str, 126, fp)) { // happy go for small mobility file :-)
	    	  char * pch;
	      	  int fmt=0;

	      	  pch = strtok (str," "); // the separator between the items in the list is a space
	      	  Exnode* node = malloc(sizeof(Exnode));

	      	  while (pch != NULL)
	      	  {	  node->visit=0;
	      		  switch(fmt){
	      						  case 0:
	      							node->time=atof(pch);
	      							break;
	      						  case 1:
	      							node->vid =atoi(pch);
	      							break;
	      						  case 2:
	      							node->x=atof(pch);
	      							break;
	      						  case 3:
	      							node->y=atof(pch);
	      							break;
	      						  case 4:
	      							node->speed=atof(pch);
	      							break;
	      						  default:
	      							  //need a log statement here
	      							  break;
	      		  }
	      		fmt +=1;

	          pch = strtok (NULL, " ");

	      	  }
	      	  node->next=NULL;

	      	  //check in the hash table if the key exist node->vid if exist ? initialize headRef
	      	  int *value = NULL;
	      	  value = (int *)HT_LOOKUP(table, &node->vid);
	      	  if (value==NULL){
	      		if (Node_info==NULL){
	      			Node_info=build_node_info(Node_info,node->vid,&(node->vid));
	      			head_node_info=Node_info;
	      		}
	      		else{
	      			build_node_info(Node_info,node->vid,&(node->vid));
	      		}
	      		keyholder[i]=&node->vid;i++;
	      		//printf("Before to hash %p %d %lf\n",node,(node->vid),(node->time));
	      		hash_table_add(table, &(node->vid), sizeof(node->vid), node, sizeof(&node));
	      		//puts("NO node doesnt exist");
	      		headRef=gen_list();

	      	  }
	      	  else{
	      		 //puts("Yes node exist");
	      		 headRef = (Exnode *)value;
	      		 //printf("After from hash %p %d\n",headRef, headRef->vid );

	      	  }
	      	  if (headRef!=NULL){
	      		  	  AppendNode(headRef, node);
	      	  	  	 }

	      }
	    }

	    fclose(fp);
	    return table;
}