Esempio n. 1
0
int main(int argc, char **argv)
{
	printf("begining...\n");
	struct timeval start, end;
	long cost_time;

	int param1 = atoi(argv[1]);
	int param2 = atoi(argv[2]);

	int pkeylen = DATALEN[param1];
	int fkeylen = DATALEN[param2];

	printf("malloc space...\n");
	gettimeofday(&start, NULL);
	int *pkeydata = (int*)malloc(sizeof(int) * pkeylen);
	assert(pkeydata);
	int *fkeydata = (int*)malloc(sizeof(int) * fkeylen);
	assert(fkeydata);
	int *hashtable = (int*)malloc(sizeof(int) * TABLESIZE);
	assert(hashtable);
	memset(hashtable, 0, sizeof(int) * TABLESIZE);
	gettimeofday(&end, NULL);
	cost_time = 1000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000;
	printf("malloc time = %d\n", cost_time);

	printf("loading data...\n");
	gettimeofday(&start, NULL);
	loaddata(FILENAME, param1, pkeylen, pkeydata);
	loaddata(FILENAME, param2, fkeylen, fkeydata);
	gettimeofday(&end, NULL);
	cost_time = 1000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000;
	printf("loaddata time = %d\n", cost_time);

	printf("hash join...\n");
	gettimeofday(&start, NULL);
	Hash_Join(pkeydata, fkeydata, hashtable, pkeylen, fkeylen);
	gettimeofday(&end, NULL);
	cost_time = 1000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000;
	printf("join time = %d\n", cost_time);

	printf("free space...\n");
	free(pkeydata);
	free(fkeydata);
	free(hashtable);

	printf("ending...\n");
	return 0;
}
Esempio n. 2
0
int main() {
	int choice;
	item1=loaddata("Pen", 100, 7.35);
	displayitem(item1);
	item2=loaddata("Pencil", 150, 3.90);
	displayitem(item2);
	printf("Select 1 to buy %s or 2 to buy %s", item1.name, item2.name);
	scanf("%d", &choice);
	if(choice==1) {
		printf("You must pay $%1.2f\n", item1.price);
		item1.amount--;
		displayitem(item1);
	}
	if(choice==2) {
		printf("You must pay $%1.2f\n", item2.price);
		item2.amount--;
		displayitem(item2);
	}
}
Esempio n. 3
0
int sdl_main(int argc, char **argv, void *runner) {
  char *game_argv[] = {"descent", "-debug"};
  int game_argc = 2;
  NaClCrashDumpInit();
  loaddata(runner);
  GameArg.DbgVerbose = CON_DEBUG;
  con_printf(CON_DEBUG, "starting\n");
  game_main(game_argc, game_argv);
  return 0;
}
Esempio n. 4
0
int main(){

	int pkfileIndex =1; // 0 - 5

	int fkfileIndex =1; // 6 - 19
	
	int pkeylen = data_len[pkfileIndex]; 
	int fkeylen = data_len[fkfileIndex]; 
	int rkeylen = 0;

	unsigned int* primaryKeys=(unsigned int*)malloc(sizeof(int)*(pkeylen));
	unsigned int* foreignKeys=(unsigned int*)malloc(sizeof(int)*(fkeylen));  
	
	loaddata(filenames,pkfileIndex,data_len, primaryKeys,&pkeylen);
	loaddata(filenames,fkfileIndex,data_len, foreignKeys,&fkeylen);
	
	long start_time = getCurrentTime();
	printf("start time:%d\n", start_time);

	unsigned int* primaryKeysTemp=(unsigned int*)malloc(sizeof(int)*(pkeylen));
	unsigned int* foreignKeysTemp=(unsigned int*)malloc(sizeof(int)*(fkeylen)); 

	mergeSort(primaryKeys, primaryKeysTemp, 0, pkeylen - 1);
	mergeSort(foreignKeys, foreignKeysTemp, 0, fkeylen - 1);
	countRepeated(primaryKeys,foreignKeys,pkeylen,fkeylen);

	long finish_time = getCurrentTime();
	printf("finish time:%d\n", finish_time);

	double elapsed_time = (finish_time - start_time) / 1000000.0;
	printf("The elapsed time = %e seconds\n",elapsed_time);

	free(primaryKeys);
	free(foreignKeys);
	free(primaryKeysTemp);
	free(foreignKeysTemp);


	return 1;

}
Esempio n. 5
0
int main(int argc, char **argv)
{
	printf("begining...\n");
	clock_t t1, t2, begin, end;

	begin = clock();
	int pkeylen = datalen[0];
	int *pkeydata = (int*)malloc(sizeof(int) * pkeylen);
	assert(pkeydata);

	int fkeylen = datalen[1];
	int *fkeydata = (int*)malloc(sizeof(int) * fkeylen);
	assert(pkeydata);

	loaddata(filenames, 0, pkeylen, pkeydata);
	loaddata(filenames, 1, fkeylen, fkeydata);

	int *hashtable = (int*)malloc(sizeof(int) * TABLESIZE);
	memset(hashtable, 0, sizeof(int) * TABLESIZE);
	assert(hashtable);

	printf("building hashtable...\n");
	t1 = clock();
	buildhash(pkeydata, hashtable, pkeylen);
	t2 = clock();
	printf("build hashtable time = %f\n", (double)(t2 - t1) / CLOCKS_PER_SEC);

	printf("probing...\n");
	t1 = clock();
	probe(hashtable, fkeydata, fkeylen);
	t2 = clock();
	printf("probing time = %f\n", (double)(t2 - t1) / CLOCKS_PER_SEC);

	end = clock();
	printf("total time = %f\n", (double)(end - begin) / CLOCKS_PER_SEC);

	free(hashtable);
	free(fkeydata);
	free(pkeydata);
}
Esempio n. 6
0
int main()
{
    welcome();
    int primaryKeyLen;
    // primary key comes from DataKey0M16M
    unsigned int *primaryKey = new unsigned int[data_len[0]];
    // 取值范围 [0, 16M),数量 16M
    loaddata(0, primaryKey, &primaryKeyLen);
    std::cout << "length of primary key is " << primaryKeyLen << std::endl;

    int idx = 4;
    // foreign key comes from one of other dataset
    unsigned int *foreignKey = new unsigned int[data_len[idx]];
    int foreignKeyLen;
    // 取值范围 [0, 16M), 数量:取决于使用的数据集
    loaddata(idx, foreignKey, &foreignKeyLen);
    std::cout << "length of foreign key is " << foreignKeyLen << std::endl;

    struct timespec tw1;
    clock_gettime(CLOCK_MONOTONIC, &tw1);

    // join算法实现要求:采用自然连接,将外键中数值跟主键相同的索引跟主键连接在一起
    // 所以输出值是一个大小不定(最大为外键数据集的数量)的list,其中first为主键,
    // second为原外键的索引。
    std::list<std::pair<unsigned int, unsigned int> > result;
    join(primaryKey, primaryKeyLen, foreignKey, foreignKeyLen, result);

    struct timespec tw2;
    clock_gettime(CLOCK_MONOTONIC, &tw2);
    double posix_wall = 1000.0 * tw2.tv_sec + 1e-6 * tw2.tv_nsec
                       - (1000.0 * tw1.tv_sec + 1e-6 * tw1.tv_nsec);
    std::cout << "Wall time: " << posix_wall << " ms\n";

    // 这里输出join的结果的元组数
    std::cout << "The number of join result is " << result.size() << std::endl;

    delete []primaryKey;
    delete []foreignKey;
    return 0;
}
Esempio n. 7
0
int main(int argc, char**argv){
	//Load data and Initialize.
	loaddata(&model);
	loadfile(&deta);
	InitDispParam(&model, &disp);
	InitializeGL(argc, argv);

	glutMainLoop();
	free(mesh);


	return 0;
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
	if (!loaddata()) exit(1);
	if (!readconfig()) exit(1);
	
	buildnodelist();
	EZ_Initialize(argc,argv,0);
	initgui();

	EZ_EventMainLoop();

	return 0;
}
Esempio n. 9
0
File: storage.c Progetto: bazil/tra
static XDBlock*
popfree(XDStore *s, int slot)
{
	u32int na;
	XDBlock *d, *nd;

	d = s->free[slot];
	if(d == nil){
		werrstr("empty slot %d", slot);
		return nil;
	}
	if(d->db.n != ~(u32int)0){
		fprint(2, "slot %d allocated page on the free list (oops)\n", slot);
		abort();
	}

	if(d->p == nil){
		d->p = loadpage(s, d->db.addr&~(s->ds.pagesize-1));
		if(d->p == nil){
			werrstr("loadpage %ud: %r", d->db.addr&~(s->ds.pagesize-1));
			return nil;
		}
		d->pa = d->p->a + (d->db.addr&(s->ds.pagesize-1));
		d->db.a = d->pa+HdrSize;
	}
	if(d->next){
DBG print("used slot %d got %ud next %ud\n", slot, d->db.addr, d->next->db.addr);
		s->free[slot] = d->next;
		return d;
	}
	na = gbit32(d->db.a);
	if(na == 0){
DBG print("used slot %d got %ud next 0\n", slot, d->db.addr);
		s->free[slot] = nil;
		return d;
	}
	nd = loaddata(s, na);
	if(nd == nil){	/* if we return d we'll leak the rest of the free chain */
DBG print("used slot %d got %ud next %ud bad: %r\n", slot, d->db.addr, na);
		werrstr("loaddata %ud: %r", na);
		return nil;
	}
	pbit32((uchar*)nd->db.a+4, 0);
	((Dpage*)nd->p)->flags |= DDirty;
	s->free[slot] = nd;
DBG print("used slot %d got %ud next %ud (loaded)\n", slot, d->db.addr, nd->db.addr);
	return d;
}
Esempio n. 10
0
/*
 * Main loop
 */
void
game_run(void)
{
  U32 tm, tmx;

	loaddata(); /* load cached data */

	game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD;
	tm = sys_gettime();
	game_state = XRICK;

	/* main loop */
	while (game_state != EXIT) {

		/* timer */
		tmx = tm; tm = sys_gettime(); tmx = tm - tmx;
		if (tmx < game_period) sys_sleep(game_period - tmx);

		/* video */
		/*DEBUG*//*game_rects=&draw_SCREENRECT;*//*DEBUG*/
		sysvid_update(game_rects);
		draw_STATUSRECT.next = NULL;  /* FIXME freerects should handle this */

		/* sound */
		/*snd_mix();*/

		/* events */
		if (game_waitevt)
			sysevt_wait();  /* wait for an event */
		else
			sysevt_poll();  /* process events (non-blocking) */

		/* frame */
		frame();
	}

	freedata(); /* free cached data */
}
Esempio n. 11
0
static GElf_Addr get_glink_vma(struct ltelf *lte, GElf_Addr ppcgot,
			       Elf_Data *plt_data)
{
	Elf_Scn *ppcgot_sec = NULL;
	GElf_Shdr ppcgot_shdr;
	if (ppcgot != 0
	    && !get_section_covering(lte, ppcgot, &ppcgot_sec, &ppcgot_shdr))
		// xxx should be the log out
		fprintf(stderr,
			"DT_PPC_GOT=%#" PRIx64 ", but no such section found.\n",
			ppcgot);

	if (ppcgot_sec != NULL) {
		Elf_Data *data = loaddata(ppcgot_sec, &ppcgot_shdr);
		if (data == NULL
		    || data->d_size < 8 )
			debug(1, "Couldn't read GOT data.");
		else {
			// where PPCGOT begins in .got
			size_t offset = ppcgot - ppcgot_shdr.sh_addr;
			GElf_Addr glink_vma = read32be(data, offset + 4);
			if (glink_vma != 0) {
				debug(1, "PPC GOT glink_vma address: %#" PRIx64,
				      glink_vma);
				return glink_vma;
			}
		}
	}

	if (plt_data != NULL) {
		GElf_Addr glink_vma = read32be(plt_data, 0);
		debug(1, ".plt glink_vma address: %#" PRIx64, glink_vma);
		return glink_vma;
	}

	return 0;
}
Esempio n. 12
0
/*
 * Main loop
 */
void
game_run(void)
{
  U32 tm;
#if 0
  U32 tmx;
#endif

	loaddata(); /* load cached data */

	game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD;
	tm = sys_gettime();
	game_state = XRICK;

	/* main loop */
	while (game_state != EXIT) {

#if 0
		/* This code doesn't make any sense to me at all. It waits
		   until the desired amount of time has passed and then
		   takes the time at which it started waiting (which is
		   not synchronous with anything) as the reference point
		   for the next frame. This sort of works if your system
		   takes very little time to compute the frame, but fails
		   horribly otherwise, e.g. if you use blocking I/O
		   (sound, vblank). */
		tmx = tm; tm = sys_gettime(); tmx = tm - tmx;
		if (tmx < game_period) sys_sleep(game_period - tmx);
#endif

		/* video */
		/*DEBUG*//*game_rects=&draw_SCREENRECT;*//*DEBUG*/
		sysvid_update(game_rects);
		draw_STATUSRECT.next = NULL;  /* FIXME freerects should handle this */

		/* timer */
		/* Reset the timing if it's way out of line, such as when
		   the game thread has been paused. */
		if (sys_gettime() - tm > game_period * 10)
			tm = sys_gettime() - game_period / 2;
		/* Update sound while waiting. */
		do {
			syssnd_callback();
		} while (sys_gettime() - tm < game_period / 2);
		/* Use the time at which the frame should have been complete as
		   reference for the next frame. This makes it possible to
		   "catch up" if a frame has taken longer for some reason. */
		tm = tm + game_period / 2;

		/* sound */
		/*snd_mix();*/

		/* events */
		if (game_waitevt)
			sysevt_wait();  /* wait for an event */
		else
			sysevt_poll();  /* process events (non-blocking) */

		/* frame */
		frame();
	}

	freedata(); /* free cached data */
}
Esempio n. 13
0
int main(int argc, char **argv){
  
  FILE *data;
  double *matriz;
  int x,y,i,j,a;
  int m3=0,m1=0,m2=0;
  data=opendata(argv[1]);
  countdata(data,&x,&y);
  
  //hacer la matriz provisional
  matriz = loaddata(data,x,y);
  gsl_matrix_view P =gsl_matrix_view_array(matriz,y,x);
  // sacar la media para cada dimension
  gsl_vector *m= gsl_vector_alloc(3);
  for(i=0;i<x;i++){
    for(j=0;j<y;j++){
      if(i==0)
	{
	  m1+= gsl_matrix_get(&P.matrix,j,i);
	}
      if(i==1)
	{
	  m2+= gsl_matrix_get(&P.matrix,j,i);
	}
      if(i==2)
	{
	  m3+= gsl_matrix_get(&P.matrix,j,i);
	}
      m1/= y; m2/= y; m3/=y;
    }
  }
  gsl_vector_set(m,0,m1);
  gsl_vector_set(m,1,m2);
  gsl_vector_set(m,2,m3);
  
  // crear la matriz de covarianza COV
  gsl_matrix *COV= gsl_matrix_alloc(x,x);
  for(i=0;i<x;i++){
    for(a=0;a<x;a++){
      double element=0;
      for(j=0;j<y;j++){
	double ei= gsl_matrix_get(&P.matrix,j,i) - gsl_vector_get(m,i);
	double ea= gsl_matrix_get(&P.matrix,j,a) - gsl_vector_get(m,a);
	double ee=ei*ea;
	element+=ee;
      }
      element/= (y-1);
      gsl_matrix_set(COV,i,a,element);
    }
  }
  
  // calcular los valores propios de la matriz COV
  gsl_vector *eval=gsl_vector_alloc(x);
  gsl_matrix *evec=gsl_matrix_alloc(x,x);
  gsl_eigen_symmv_workspace *w= gsl_eigen_symmv_alloc(x);

  gsl_eigen_symmv(COV,eval,evec,w);
  gsl_eigen_symmv_free(w);
  
  gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC);

  //output
  FILE *fileout;
  fileout=fopen("autovectores_3D_data.dat", "w");

  for(i=0;i<x-1;i++){
    double eval_i= gsl_vector_get(eval,i);
    gsl_vector_view evec_i = gsl_matrix_column (evec,i);
    
    printf("eigenvalue %g\n", eval_i);
    printf("eigenvector = \n");
    gsl_vector_fprintf(stdout, &evec_i.vector, "%g");
    
    float evec_i_0= (float) gsl_vector_get(&evec_i.vector,0); 
    float evec_i_1= (float) gsl_vector_get(&evec_i.vector,1);
    float evec_i_2= (float) gsl_vector_get(&evec_i.vector,2);
    fprintf(fileout,"%f %f %f\n", evec_i_0, evec_i_1, evec_i_2); 
    
  } 
  close(fileout);
  return 0;
}
Esempio n. 14
0
int main()
{
	struct dbSysHead head;
	long fid1, fid2;

	/*
	≥ı ºªØ£¨»ª∫Û¥Ú”°≥ˆµ±«∞œµÕ≥µƒ–≈œ¢
	*/
	init_database(&head);
	showDesc(&head);

//	printf("create file1...\n");
	
	showFileDesc(&head);
/*	printf("extend 10 pages for file1...\n");
	extendFileSpace(&head, fid1, 10);//¿©’π Æ“≥
	showFileDesc(&head);
	printf("extend 10 pages for file1...\n");
	extendFileSpace(&head, fid1, 10);//‘Ÿ¿©’π Æ“≥
	showFileDesc(&head);

	printf("create file2...\n");
	fid2 = creatFileSpace(&head);
	showFileDesc(&head);
	printf("extend 10 pages for file2...\n");
	extendFileSpace(&head, fid2, 10);
	showFileDesc(&head);
	printf("extend 10 pages for file2...\n");
	extendFileSpace(&head, fid2, 10);
	showFileDesc(&head);

	printf("delete file1...\n");
	recyFileSpace(&head, fid1);
	showFileDesc(&head);
	printf("delete file2...\n");
	recyFileSpace(&head, fid2);
	showFileDesc(&head);*/
    //use dictID to scan file1
    /*
     int dictID = 1;
     int scanPointer = 0;
     int rec_length = head.redef[dictID].getRecordLength();
     printf("attributeName::%s", head.redef[dictID].getAttributeByNo(0).getName());
     RecordCursor scanTable(&head, 1, rec_length, 0);
     char * one_Row_ = (char *)malloc(sizeof(char)*rec_length);
     while (true == scanTable.getNextRecord(one_Row_)) { //only scan
     scanPointer ++;
     if(scanPointer > 230)
     getOneRecord(one_Row_, head.redef[dictID]); //get each attribute value and print
     }
     free(one_Row_);
     */
/*
    fid1 = creatFileSpace(&head);//Œ™Œƒº˛“ª∑÷≈‰ø’º‰
    fid2 = creatFileSpace(&head);
	
    if(initTable(&head, FIRST_FID) == 0)
		printf("1 initTable: customer.tbl\n");
	if(showTable(&head, "customer") == -1 )
		printf("2 showTable: customer\n");
    
    if(initTable(&head, FIRST_FID+1) == 0)
        printf("1 initTable: nation.tbl\n");
    if(showTable(&head, "nation") == -1 )
        printf("2 showTable: nation\n");
*/

    if(createTable(&head) == -1)
        printf("Create Table1 failed\n");
    if(createTable(&head) == -1)
        printf("Create Table2 failed\n");
    if(createTable(&head) == -1)
        printf("Create Table3 failed\n");
 /*
    struct eachAttribute * nation_att = new struct eachAttribute[12];
    strcpy(nation_att[0].attribute_name_,"custkey");
    nation_att[0].attribute_type_ = 1;
    nation_att[0].attribute_length_ = 4;
    strcpy(nation_att[1].attribute_name_,"name");
    nation_att[1].attribute_type_ = 2;
    nation_att[1].attribute_length_ =32;
    strcpy(nation_att[2].attribute_name_,"address");
    nation_att[2].attribute_type_ = 2;
    nation_att[2].attribute_length_ =40;
    strcpy(nation_att[3].attribute_name_,"nationkey");
    nation_att[3].attribute_type_ = 1;
    nation_att[3].attribute_length_ = 4;
    strcpy(nation_att[4].attribute_name_,"phone");
    nation_att[4].attribute_type_ = 2;
    nation_att[4].attribute_length_ =16;
    strcpy(nation_att[5].attribute_name_,"acctbal");
    nation_att[5].attribute_type_ = 2;
    nation_att[5].attribute_length_ =64;
    strcpy(nation_att[6].attribute_name_,"mktsemgent");
    nation_att[6].attribute_type_ = 2;
    nation_att[6].attribute_length_ =12;
    strcpy(nation_att[7].attribute_name_,"comment");
    nation_att[7].attribute_type_ = 2;
    nation_att[7].attribute_length_ =128;
    if (createTable( &head, "customer", "TianzhenWu",  8, nation_att) == -1) {
        printf("Create Table failed\n");
    }

    struct eachAttribute * region_att = new struct eachAttribute[3];
    strcpy(region_att[0].attribute_name_,"regionkey");
    region_att[0].attribute_type_ = 1;
    region_att[0].attribute_length_ = 4;
    strcpy(region_att[1].attribute_name_,"regionname");
    region_att[1].attribute_type_ = 2;
    region_att[1].attribute_length_ = 12;
    strcpy(region_att[2].attribute_name_,"regioncomment");
    region_att[2].attribute_type_ = 2;
    region_att[2].attribute_length_ = 152;
    if (createTable( &head, "region", "Mengxi", 3, region_att) == -1) {
        printf("Create Table failed\n");
    }
    */
    relation * temp_data_dict = new relation[MAX_FILE_NUM];
    //read customer.tbl and write into our file1, 一次性
//    loaddata(&head, FIRST_FID);
    loaddata(&head, FIRST_FID + 1);
    loaddata(&head, FIRST_FID + 2);
    sysUpdate(&head);

    insertOneTuple(&head, "customer", "501|Customer#000000501|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets.H|");
    
    insertOneTuple(&head, "customer", "1002|Customer#000001001|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets.HH|");
    
    insertOneTuple(&head, "customer", "1003|Customer#000001002|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets.HHH|");
//    sysUpdate(&head);

    //Scan Table
    int customer_scan = -1;
    customer_scan = TableScan(&head, temp_data_dict, "customer");
    if (customer_scan>=0) {
        printf("tablescan succeed!\n");
    }
    printTempTable(&head, temp_data_dict,0);
    //char attribute_list[3][NAMELENGTH] = {"address", "name", "custkey"};
    //if(project(&head, temp_data_dict, customer_scan, 3, attribute_list)>=0)
    //    printf("project succeed!\n");
    //for each old table, only one time SPJ operator allowed, because it will be freed by this SPJ operator.
    /*
    printf("start tableScanEqualFilter()...\n");
    relation filter_result1;
    if(true == tableScanEqualFilter(&head, &temp_data_dict[0],"custkey","3", &filter_result1)){
        printf("tableScanEqualFilter()\n");
    }

    relation filter_result2;
    if(true == tableScanEqualFilter(&head, &temp_data_dict[0],"name","Customer#000000009", &filter_result2)){
        printf("tableScanEqualFilter()\n");
    }

    relation filter_result3;
    if(true == tableScanScopeFilter(&head,  &temp_data_dict[0],"custkey","220",NOT_MORE_THAN,"230",LESS_THAN,&filter_result3)){
        printf("tableScanScopeFilter()\n");
    }
    RecordCursorTmp t2(&head,-2,filter_result3.getRecordLength(), - filter_result3.fileID,filter_result3.getRecordNum());
    char * one_Row_ = (char *)malloc(sizeof(char)* filter_result3.getRecordLength());
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &filter_result3); //get each attribute value and print
    }
    free(one_Row_);
*/
    

/*
    //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1]
    int buffer_ID_ = - temp_data_dict[1].fileID;   //find which buffer
    int record_num_ = temp_data_dict[1].getRecordNum();
    int record_len_ = temp_data_dict[1].getRecordLength();
    RecordCursorTmp t1(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    char * one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t1.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &temp_data_dict[1]); //get each attribute value and print
    }
    free(one_Row_);
*//*
printf("customer_scan:%d\n",customer_scan);
    	deleteRecordWhere(&head, FIRST_FID, "name", "Customer#000000005",LESS_THAN,0);

    printf("start tableScanEqualFilter()...\n");
    
    int filterFlag=-1;
//    filterFlag = tableScanSemiscopeFilter(&head, temp_data_dict, customer_scan,"custkey","3",LESS_THAN);

    filterFlag = tableScanSemiscopeFilter(&head, temp_data_dict,customer_scan, "name","Customer#000000009",NOT_MORE_THAN);

    int buffer_ID_,record_num_,record_len_; 
    buffer_ID_ = - temp_data_dict[filterFlag].fileID;   //find which buffer
    record_num_ = temp_data_dict[filterFlag].getRecordNum();
    record_len_ = temp_data_dict[filterFlag].getRecordLength();
    RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    char * one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        //printf("%s\n",one_Row_);
	//if(strcpy(one_Row_,"\0") == 0)
           // break;
    //    getOneRecord(one_Row_, &temp_data_dict[filterFlag]); //get each attribute value and print
    }
    free(one_Row_);
 printf("HERE~~~\n\n");
    deleteRecordWhere(&head, FIRST_FID, "name", "Customer#000000005",EQUAL,0); 
    customer_scan = -1;
    customer_scan = TableScan(&head, temp_data_dict, "customer");
    if (customer_scan>=0) {
        printf("tablescan succeed!\n");
    }
    printf("customer_scan:%d\n",customer_scan);
    buffer_ID_ = - temp_data_dict[customer_scan].fileID;   //find which buffer
    record_num_ = temp_data_dict[customer_scan].getRecordNum();
    record_len_ = temp_data_dict[customer_scan].getRecordLength();
    RecordCursorTmp t3(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    while (true == t3.getNextRecord(one_Row_)) { //only scan
        //printf("%s\n",one_Row_);
        //if(strcpy(one_Row_,"\0") == 0)
           // break;
        getOneRecord(one_Row_, &temp_data_dict[filterFlag]); //get each attribute value and print
    }
    free(one_Row_);


//    TableScan(&head, FIRST_FID + 1, temp_data_dict);
/*
    //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1]
    buffer_ID_ = - temp_data_dict[1].fileID;   //find which buffer
    record_num_ = temp_data_dict[1].getRecordNum();
    record_len_ = temp_data_dict[1].getRecordLength();
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    RecordCursorTmp t2(&head,2,record_len_,buffer_ID_,record_num_);
    one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &temp_data_dict[1]); //get each attribute value and print
    }
    free(one_Row_);
 */
    // create index
/*
    printf("recordNum:%d\n",head.redef[dictID].recordNum);
	if(true == createIndexOn(&head, 1, "custkey")){
		char* index_filename= "b_plus_tree_index_1custkey.dat";
		
		FILE* fp = fopen(index_filename,"rb+");
		printf("search(fp,-10):%d\n",search(fp,-10));
		printf("search(fp,1):%d\n",search(fp,1));
		printf("search(fp,2):%d\n",search(fp,2));
		printf("search(fp,50):%d\n",search(fp,50));
		display(fp);
		fclose(fp);
	}
	
    // insert one record
	relationDefine dic = head.redef[0];
    int size_per_record = dic.recordLength;
    char *oneRec = (char *)malloc(sizeof(char)*size_per_record);
        
	char * insertTest = (char *)malloc(sizeof(char)* 256);
    strcpy(insertTest,"501|Customer#000000001|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets. regular, ironic epitaphs nag eHHHHHH|");
    parserOneLineFromFile(insertTest, oneRec, dic);
    insertOneRecord(&head, 1, oneRec);//≤»ΓªÃı ˝æ›£¨◊‘∂Ø∏¸–¬À˜“˝
	free(insertTest);
    free(oneRec);
    
    // look up key in index
	char* index_filename= "b_plus_tree_index_1custkey.dat";
	FILE* fp = fopen(index_filename,"rb+");
	int pos = search(fp,501);
	printf("pos:::%d\n",pos);
	fclose(fp);
 
	one_Row_ = (char *)malloc(sizeof(char)*rec_length);
	rdFile( &head, 0, 1, pos, rec_length,one_Row_);
	printf("reading from index:\n");
	getOneRecord(one_Row_, dic);
*/
 /*   //nestloop_cp
    relation result;
    result.init("cus_nation", "zhangwenhui");
    /*merge_relation_cp(&head,temp_data_dict[0],temp_data_dict[1],&result);
     showRelation(&result);
     
     nestloop_cp(&head, &temp_data_dict[0],&temp_data_dict[1], &result);*/
/*
    //nestloop_equal
    merge_relation(&head,temp_data_dict[0],temp_data_dict[1],&result);
    //nestloop_equal(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey");
    //nestloop_bigger(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey");
    //nestloop_smaller(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey");
    nestloop_smaller_or_equal(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey");
    //nestloop_bigger_or_equal(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey");

*/
    //project customer
/*	relation c_result;
	c_result.init("customer", "TianzhenWu");
	c_result.insertAttribute("name", 2, 64);
    c_result.insertAttribute("nationkey",1,4);
	c_result.insertAttribute("phone", 2, 64);
	showRelation(&c_result);
	project(&head, &temp_data_dict[0], &c_result);

    //project nation.tbl
    relation n_result;
    n_result.init("nation", "MengxiZhou");
    n_result.insertAttribute("nationkey", 1, 4);
    n_result.insertAttribute("name", 2, 16);
    n_result.insertAttribute("regionkey", 1, 4);
    showRelation(&n_result);
    project(&head, &temp_data_dict[1], &n_result);
*/
 /*
//    relation hashjoin_result_;
//    hashjoin_result_.init("customer_nation_hash", "irenewu");
//    hashjoin(&head, &c_result, &n_result, &hashjoin_result_,"nationkey");
    
    relation result;
    result.init("sortmergejoin zmx","zmx");
//    	merge_relation(&head, c_result, n_result, &result);
//    result.insertAttribute("custkey", 1, 4);
    result.insertAttribute("name", 2, 32);
//    result.insertAttribute("address", 2, 40);
    result.insertAttribute("nationkey", 1, 4);
    result.insertAttribute("phone", 2, 16);
//    result.insertAttribute("acctbal", 2, 64);
//    result.insertAttribute("mktsegment", 2, 12);
//    result.insertAttribute("comment", 2, 128);
    result.insertAttribute("nationkey", 1, 4);
    result.insertAttribute("name", 2, 32);
    result.insertAttribute("regionkey", 1, 4);
//    result.insertAttribute("comment", 2, 160);
    showRelation(&result);
    sortmergejoin(&head, &c_result, &n_result, "nationkey", &result);
    
    int buffer_ID_ = - result.fileID;   //find which buffer
    int record_num_ = result.getRecordNum();
    int record_len_ = result.getRecordLength();
    RecordCursorTmp t2(&head,-11,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    char * one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &result); //get each attribute value and print
    }
    free(one_Row_);
/*
    //filter
    printf("start tableScanEqualFilter()...\n");
    
    if(true == tableScanEqualFilter(&head, FIRST_FID, temp_data_dict,"custkey","3",&temp_data_dict[5])){
        printf("tableScanEqualFilter()\n");
    }

    if(true == tableScanEqualFilter(&head, FIRST_FID, temp_data_dict,"name","Customer#000000009",&temp_data_dict[5])){
        printf("tableScanEqualFilter()\n");
    }
  
    buffer_ID_ = - temp_data_dict[5].fileID;   //find which buffer
    record_num_ = temp_data_dict[5].getRecordNum();
    record_len_ = temp_data_dict[5].getRecordLength();
    RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    char * one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &temp_data_dict[5]); //get each attribute value and print
    }
    free(one_Row_);
    //head.buff[buffer_ID_].emptyOrnot = false;
 
    if(true == tableScanScopeFilter(&head, FIRST_FID, temp_data_dict,"custkey","220",NOT_MORE_THAN,"230",LESS_THAN,&temp_data_dict[5])){
        printf("tableScanScopeFilter()\n");
    }
*/

    showFileDesc(&head);
    dropTable(&head,"customer");
    deleteAllTuples(&head,"nation");
    dropTable(&head,"nation");

/*
   if(true == createIndexOn(&head, FIRST_FID, "custkey")){
        char* index_filename = "/Users/Irene/Desktop/b_plus_tree_index_1custkey.dat";
        FILE* fp;
        int pos;

        if( !(fp = fopen(index_filename,"rb+")))
                printf("error indexFile name.\n");
        printf("search(fp,-10):%d\n",search(fp,-10));
        printf("search(fp,1):%d\n",search(fp,1));
        printf("search(fp,2):%d\n",search(fp,2));
        printf("search(fp,50):%d\n",search(fp,50));
        //display(fp);


        deleteRecordWhere(&head, FIRST_FID, "name", "Customer#000000005",LESS_THAN,0);
        pos = search(fp,5);

        fclose(fp);
        printf("%d\n",pos);

        printf("start indexScanEqualFilter()...\n");
        if(true == indexScanEqualFilter(&head, FIRST_FID, "custkey","4",&temp_data_dict[5])){
          printf("indexScanEqualFilter(9) end!\n");

          buffer_ID_ = - temp_data_dict[5].fileID;   //find which buffer
          record_num_ = temp_data_dict[5].getRecordNum();
          record_len_ = temp_data_dict[5].getRecordLength();
          RecordCursorTmp t3(&head,1,record_len_,buffer_ID_,record_num_);
          cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
          one_Row_ = (char *)malloc(sizeof(char)*record_len_);
          while (true == t3.getNextRecord(one_Row_)) { //only scan
                if(one_Row_[0] == '$')
                        printf("empty\n");
           //getOneRecord(one_Row_, &temp_data_dict[5]); //get each attribute value and print
          }
          free(one_Row_);
          head.buff[buffer_ID_].emptyOrnot = true;

        }
    }//end of createIndexOn if
*/
    sysUpdate(&head);
    showFileDesc(&head);
    exit_database(&head);
	system("pause");
	return 0;
}
Esempio n. 15
0
int main()//int argc, char* argv[])
{
	int choice,sel;
	//int decistat;
	char xml[5][30]={
		"xml1.xml",
		"xml2.xml",
		"xml21.xml",
		"xml22.xml",
		"xml3.xml"
	};
	//char *fpxml[5];

	char xmldir[100]="./input/test01/";/*文件所在目录*/
	/*亲和性数据*/
	char xmlaffdir[100]="./input/Data/affinity/";
	/*负载均衡*/
	char xmlaffdir1[100]="./input/Data/hotsolve/";

	char xmlnewfiledir[100]="./input/Data/xmltest/";/*新产生的模拟数据所在目录*/

	char xmlaffdir2[100]="./input/Data/initplace/";

	
	//char urlfile[200];

	//FILE *fp;
	
	/*
	if(argc!=6) 
	{
		printf("error, please input 5 parameters!\n");
		exit(0);
	}

	for(i=1;i<argc;i++)
	{
		if((fp=fopen(argv[i],"r"))==NULL)
		{
			printf("%s File open error, please check this file is existed!\n",argv[i]);
			exit(0);
		}
		else 
		{
			fpxml[i]=argv[i];
			fclose(fp);
		}

	}

	printf("All files are existed!\n");

	///////////////////////////////////////////////
	//exit(0);

	*/

	while(1){
		printf("Enter choice:\n");
		printf("1-Load data XML1, XML2(VM & PM), XML21(PM2PM), XML22(VM2VM) from xmldata.\n");
		printf("2-Generate XML2, XML21, XML22 data from generator and initialize all globals.\n");
		printf("3-Getdata from outer cloud computing platforms and initialize all globals.\n");
		printf("4-Make a whole scheduling test and see the result in xml3.\n");
		printf("5-Make scheduling for test, take initialplace as an example by grouping and packing.\n");
		printf("6-Output the actionlist into xml file.\n");		
		printf("0-exit.\n");
		scanf("%d",&choice);
		if(choice==0) break;
		
		switch(choice){
		case 1:
		
			/*初始化全局输入数据结构*/
			init_shared_data();	
			/*从文件加载所有数据*/
			
			//loaddata(xmldir);
			printf("加载数据测试:\n1.加载%s;\n2.加载%s.\n3.加载%s.\n4.加载%s\n5.加载%s\n0-结束.\n输入:",
					xmlaffdir,xmlaffdir1,xmldir,xmlnewfiledir,xmlaffdir2);
				
			scanf("%d",&sel);
			
			while(sel>0){
				
				switch (sel)
				{
				case 1:
					loaddata(xmlaffdir);
					break;
				case 2:

					loaddata(xmlaffdir1);
					break;
				case 3:

					loaddata(xmldir);

					break;
				case 4:
					loaddata(xmlnewfiledir);
					break;
				case 5:
					loaddata(xmlaffdir2);
					break;
				}
	
				printf("加载数据测试:\n1.加载%s;\n2.加载%s.\n3.加载%s.\n4.加载%s\n5.加载%s\n0-结束.\n输入:",
					xmlaffdir,xmlaffdir1,xmldir,xmlnewfiledir,xmlaffdir2);
				scanf("%d",&sel);
			}

			break;
		
		case 2:
			/*初始化全局输入数据结构*/
			//init_shared_data();	
			/*调用产生数据模块,生成xml模拟数据文件到xmlnewfiledir目录下*/
			 //GenerateData(xmlnewfiledir);	
			printf("模拟数据生成,输出见目录%s............\n",xmlnewfiledir);
			printf("分四步完成:\n1.生成VM和PM(见XML2);\n");
			printf("2.生成框(见XML2);\n3.生成组(见XML2);");
			printf("\n4.生成亲和关系(见XML22);\n输入:1-开始,0-结束!\n");

			scanf("%d",&sel);
			while(sel==1){
				GenerateData1(xmlnewfiledir);
				scanf("%d",&sel);
			}
			printf("Please find and check result file in dir: %s.\n",xmlnewfiledir);
			break;	
		case 3:/*由华为提供*/
			
			/**/
			//getdatafromcloud();
			{
				int *ar,i,sum=0;
				ar=(int*)malloc(10*sizeof(int));
				for(i=0;i<10;i++)
				{
					ar[i]=i;
					sum+=ar[i];
				}
				printf("%d\n",sum);
				free(ar);			
			}


			break;/**/
		
		case 4:
			
			
			make_whole_scheduling();
			

			break;
		
		case 5: /*通用调度函数*/
			
			/*初始化全局输入数据结构*/
			init_shared_data();	
			/*A whole scheduling test.*/
			execute(xml[0],xml[1],xml[2],xml[3],xml[4]);
			break;
		case 6:
			//生成XML3
			{
				cls_st_xmlprocess xp;
				//g_sharedata.action_total=0;
			
				xp.sd=&g_sharedata;
				init_xmlprocess(&xp);
				xp.xml_create_by_actions("xml3-1.xml");
			}

			printf("CPU:%d\n",CPU);
			break;
		}	
	}
	
	printf("Thank you for your using!\n");
	
}
Esempio n. 16
0
int
do_init_elf(struct ltelf *lte, const char *filename) {
	int i;
	GElf_Addr relplt_addr = 0;
	size_t relplt_size = 0;

	debug(DEBUG_FUNCTION, "do_init_elf(filename=%s)", filename);
	debug(1, "Reading ELF from %s...", filename);

	if (open_elf(lte, filename) < 0)
		return -1;

	Elf_Data *plt_data = NULL;
	GElf_Addr ppcgot = 0;

	for (i = 1; i < lte->ehdr.e_shnum; ++i) {
		Elf_Scn *scn;
		GElf_Shdr shdr;
		const char *name;

		scn = elf_getscn(lte->elf, i);
		if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
			error(EXIT_FAILURE, 0,
			      "Couldn't get section header from \"%s\"",
			      filename);

		name = elf_strptr(lte->elf, lte->ehdr.e_shstrndx, shdr.sh_name);
		if (name == NULL)
			error(EXIT_FAILURE, 0,
			      "Couldn't get section header from \"%s\"",
			      filename);

		if (shdr.sh_type == SHT_SYMTAB) {
			Elf_Data *data;

			lte->symtab = elf_getdata(scn, NULL);
			lte->symtab_count = shdr.sh_size / shdr.sh_entsize;
			if ((lte->symtab == NULL
			     || elf_getdata(scn, lte->symtab) != NULL)
			    && opt_x != NULL)
				error(EXIT_FAILURE, 0,
				      "Couldn't get .symtab data from \"%s\"",
				      filename);

			scn = elf_getscn(lte->elf, shdr.sh_link);
			if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
				error(EXIT_FAILURE, 0,
				      "Couldn't get section header from \"%s\"",
				      filename);

			data = elf_getdata(scn, NULL);
			if (data == NULL || elf_getdata(scn, data) != NULL
			    || shdr.sh_size != data->d_size || data->d_off)
				error(EXIT_FAILURE, 0,
				      "Couldn't get .strtab data from \"%s\"",
				      filename);

			lte->strtab = data->d_buf;
		} else if (shdr.sh_type == SHT_DYNSYM) {
			Elf_Data *data;

			lte->dynsym = elf_getdata(scn, NULL);
			lte->dynsym_count = shdr.sh_size / shdr.sh_entsize;
			if (lte->dynsym == NULL
			    || elf_getdata(scn, lte->dynsym) != NULL)
				error(EXIT_FAILURE, 0,
				      "Couldn't get .dynsym data from \"%s\"",
				      filename);

			scn = elf_getscn(lte->elf, shdr.sh_link);
			if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
				error(EXIT_FAILURE, 0,
				      "Couldn't get section header from \"%s\"",
				      filename);

			data = elf_getdata(scn, NULL);
			if (data == NULL || elf_getdata(scn, data) != NULL
			    || shdr.sh_size != data->d_size || data->d_off)
				error(EXIT_FAILURE, 0,
				      "Couldn't get .dynstr data from \"%s\"",
				      filename);

			lte->dynstr = data->d_buf;
		} else if (shdr.sh_type == SHT_DYNAMIC) {
			Elf_Data *data;
			size_t j;

			lte->dyn_addr = shdr.sh_addr;
			lte->dyn_sz = shdr.sh_size;

			data = elf_getdata(scn, NULL);
			if (data == NULL || elf_getdata(scn, data) != NULL)
				error(EXIT_FAILURE, 0,
				      "Couldn't get .dynamic data from \"%s\"",
				      filename);

			for (j = 0; j < shdr.sh_size / shdr.sh_entsize; ++j) {
				GElf_Dyn dyn;

				if (gelf_getdyn(data, j, &dyn) == NULL)
					error(EXIT_FAILURE, 0,
					      "Couldn't get .dynamic data from \"%s\"",
					      filename);
#ifdef __mips__
/**
  MIPS ABI Supplement:

  DT_PLTGOT This member holds the address of the .got section.

  DT_MIPS_SYMTABNO This member holds the number of entries in the
  .dynsym section.

  DT_MIPS_LOCAL_GOTNO This member holds the number of local global
  offset table entries.

  DT_MIPS_GOTSYM This member holds the index of the first dyamic
  symbol table entry that corresponds to an entry in the gobal offset
  table.

 */
				if(dyn.d_tag==DT_PLTGOT){
					lte->pltgot_addr=dyn.d_un.d_ptr;
				}
				if(dyn.d_tag==DT_MIPS_LOCAL_GOTNO){
					lte->mips_local_gotno=dyn.d_un.d_val;
				}
				if(dyn.d_tag==DT_MIPS_GOTSYM){
					lte->mips_gotsym=dyn.d_un.d_val;
				}
#endif // __mips__
				if (dyn.d_tag == DT_JMPREL)
					relplt_addr = dyn.d_un.d_ptr;
				else if (dyn.d_tag == DT_PLTRELSZ)
					relplt_size = dyn.d_un.d_val;
				else if (dyn.d_tag == DT_PPC_GOT) {
					ppcgot = dyn.d_un.d_val;
					debug(1, "ppcgot %#" PRIx64, ppcgot);
				}
			}
		} else if (shdr.sh_type == SHT_HASH) {
			Elf_Data *data;
			size_t j;

			lte->hash_type = SHT_HASH;

			data = elf_getdata(scn, NULL);
			if (data == NULL || elf_getdata(scn, data) != NULL
			    || data->d_off || data->d_size != shdr.sh_size)
				error(EXIT_FAILURE, 0,
				      "Couldn't get .hash data from \"%s\"",
				      filename);

			if (shdr.sh_entsize == 4) {
				/* Standard conforming ELF.  */
				if (data->d_type != ELF_T_WORD)
					error(EXIT_FAILURE, 0,
					      "Couldn't get .hash data from \"%s\"",
					      filename);
				lte->hash = (Elf32_Word *) data->d_buf;
			} else if (shdr.sh_entsize == 8) {
				/* Alpha or s390x.  */
				Elf32_Word *dst, *src;
				size_t hash_count = data->d_size / 8;

				lte->hash = (Elf32_Word *)
				    malloc(hash_count * sizeof(Elf32_Word));
				if (lte->hash == NULL)
					error(EXIT_FAILURE, 0,
					      "Couldn't convert .hash section from \"%s\"",
					      filename);
				lte->lte_flags |= LTE_HASH_MALLOCED;
				dst = lte->hash;
				src = (Elf32_Word *) data->d_buf;
				if ((data->d_type == ELF_T_WORD
				     && __BYTE_ORDER == __BIG_ENDIAN)
				    || (data->d_type == ELF_T_XWORD
					&& lte->ehdr.e_ident[EI_DATA] ==
					ELFDATA2MSB))
					++src;
				for (j = 0; j < hash_count; ++j, src += 2)
					*dst++ = *src;
			} else
				error(EXIT_FAILURE, 0,
				      "Unknown .hash sh_entsize in \"%s\"",
				      filename);
		} else if (shdr.sh_type == SHT_GNU_HASH
			   && lte->hash == NULL) {
			Elf_Data *data;

			lte->hash_type = SHT_GNU_HASH;

			if (shdr.sh_entsize != 0
			    && shdr.sh_entsize != 4) {
				error(EXIT_FAILURE, 0,
				      ".gnu.hash sh_entsize in \"%s\" "
					"should be 4, but is %#" PRIx64,
					filename, shdr.sh_entsize);
			}

			data = loaddata(scn, &shdr);
			if (data == NULL)
				error(EXIT_FAILURE, 0,
				      "Couldn't get .gnu.hash data from \"%s\"",
				      filename);

			lte->hash = (Elf32_Word *) data->d_buf;
		} else if (shdr.sh_type == SHT_PROGBITS
			   || shdr.sh_type == SHT_NOBITS) {
			if (strcmp(name, ".plt") == 0) {
				lte->plt_addr = shdr.sh_addr;
				lte->plt_size = shdr.sh_size;
				if (shdr.sh_flags & SHF_EXECINSTR) {
					lte->lte_flags |= LTE_PLT_EXECUTABLE;
				}
				if (lte->ehdr.e_machine == EM_PPC) {
					plt_data = loaddata(scn, &shdr);
					if (plt_data == NULL)
						fprintf(stderr,
							"Can't load .plt data\n");
				}
			}
#ifdef ARCH_SUPPORTS_OPD
			else if (strcmp(name, ".opd") == 0) {
				lte->opd_addr = (GElf_Addr *) (long) shdr.sh_addr;
				lte->opd_size = shdr.sh_size;
				lte->opd = elf_rawdata(scn, NULL);
			}
#endif
		}
	}

	if (lte->dynsym == NULL || lte->dynstr == NULL)
		error(EXIT_FAILURE, 0,
		      "Couldn't find .dynsym or .dynstr in \"%s\"", filename);

	if (!relplt_addr || !lte->plt_addr) {
		debug(1, "%s has no PLT relocations", filename);
		lte->relplt = NULL;
		lte->relplt_count = 0;
	} else if (relplt_size == 0) {
		debug(1, "%s has unknown PLT size", filename);
		lte->relplt = NULL;
		lte->relplt_count = 0;
	} else {
		if (lte->ehdr.e_machine == EM_PPC) {
			GElf_Addr glink_vma
				= get_glink_vma(lte, ppcgot, plt_data);

			assert (relplt_size % 12 == 0);
			size_t count = relplt_size / 12; // size of RELA entry
			lte->plt_stub_vma = glink_vma
				- (GElf_Addr)count * PPC_PLT_STUB_SIZE;
			debug(1, "stub_vma is %#" PRIx64, lte->plt_stub_vma);
		}

		for (i = 1; i < lte->ehdr.e_shnum; ++i) {
			Elf_Scn *scn;
			GElf_Shdr shdr;

			scn = elf_getscn(lte->elf, i);
			if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
				error(EXIT_FAILURE, 0,
				      "Couldn't get section header from \"%s\"",
				      filename);
			if (shdr.sh_addr == relplt_addr
			    && shdr.sh_size == relplt_size) {
				lte->relplt = elf_getdata(scn, NULL);
				lte->relplt_count =
				    shdr.sh_size / shdr.sh_entsize;
				if (lte->relplt == NULL
				    || elf_getdata(scn, lte->relplt) != NULL)
					error(EXIT_FAILURE, 0,
					      "Couldn't get .rel*.plt data from \"%s\"",
					      filename);
				break;
			}
		}

		if (i == lte->ehdr.e_shnum)
			error(EXIT_FAILURE, 0,
			      "Couldn't find .rel*.plt section in \"%s\"",
			      filename);

		debug(1, "%s %zd PLT relocations", filename, lte->relplt_count);
	}
	return 0;
}
int main()
{
	int i, j, k;
	double **train_features, *train_target, **test_features, *test_target, *tmp, maxval;
	int presentfeatures[(DATACOLS-1)*MODELCOMPLEXITY+1], maxfeat; 
	double parameters[(DATACOLS-1)*MODELCOMPLEXITY+1], gen_error[(DATACOLS-1)*MODELCOMPLEXITY+1];

	loaddata("housing_data.txt");

	//shuffle the dataset
	srand((unsigned int)time(NULL));
	for(i = 0; i < DATAROWS; ++i){
		j=(int)(((double)rand()/(double)RAND_MAX)*DATAROWS);
		k=(int)(((double)rand()/(double)RAND_MAX)*DATAROWS);
		tmp = dataset[j];
		dataset[j] = dataset[k];
		dataset[k] = tmp;
	}

	train_features = (double**)malloc(sizeof(double*)*(DATAROWS-HOLDOUT));
	test_features = (double**)malloc(sizeof(double*)*HOLDOUT);
	for(i = 0; i < (DATAROWS-HOLDOUT); ++i)train_features[i] = (double *)malloc(sizeof(double)*(DATACOLS-1));
	train_target = (double*)malloc(sizeof(double)*(DATAROWS-HOLDOUT));
	test_target = (double*)malloc(sizeof(double)*HOLDOUT);

	for(i = 0; i < (DATAROWS-HOLDOUT); ++i){
		for(j = 0; j < (DATACOLS-1); ++j)train_features[i][j] = dataset[i][j+1];
		train_target[i] = dataset[i][0];
	}

	generate_stepsizearr(train_features,(DATACOLS-1));

	for(i = 0; i < (DATAROWS-HOLDOUT); ++i){
		free(train_features[i]);
		train_features[i] = (double *)malloc(sizeof(double)*(DATACOLS-1)*MODELCOMPLEXITY+1);
		train_features[i][0] = 1;
		for(j = 0; j < (DATACOLS-1)*MODELCOMPLEXITY; ++j)
			train_features[i][1+j] = pow(dataset[i][(int)(j/3)+1],1+(j%MODELCOMPLEXITY));
	}for(; i < DATAROWS; ++i){
		test_features[i-(DATAROWS-HOLDOUT)] = (double *)malloc(sizeof(double)*(DATACOLS-1)*MODELCOMPLEXITY+1);
		test_features[i-(DATAROWS-HOLDOUT)][0] = 1;
		for(j = 0; j < (DATACOLS-1)*MODELCOMPLEXITY; ++j)
			test_features[i-(DATAROWS-HOLDOUT)][1+j] = pow(dataset[i][(int)(j/3)+1],1+(j%MODELCOMPLEXITY));
		test_target[i-(DATAROWS-HOLDOUT)] = dataset[i][0];
	}


	for(j = 0; j < (DATACOLS-1)*MODELCOMPLEXITY+1; ++j)presentfeatures[j] = (FORWARDSEARCHMODE)?0:1;

	for(i = 0; i < ((FORWARDSEARCHMODE)?WANTFEATURE:(((DATACOLS-1)*MODELCOMPLEXITY+1)-WANTFEATURE)); ++i){ //want the top 8 features
		for(j = 0; j < (DATACOLS-1)*MODELCOMPLEXITY+1; ++j){
			if(presentfeatures[j] == (FORWARDSEARCHMODE)?1:0)continue;

			//delete feature from our subset
			if(FORWARDSEARCHMODE)presentfeatures[j] = 1;
			else presentfeatures[j] = 0;
			memset(parameters, 0, sizeof(parameters));

			train_dataset(parameters, train_features, presentfeatures, train_target, (DATAROWS-HOLDOUT));
			gen_error[j] = calc_generalization_error(parameters, test_features, presentfeatures, test_target, HOLDOUT);
		
			if(FORWARDSEARCHMODE)presentfeatures[j] = 0;
			else presentfeatures[j] = 1;
			//printf("Generalization Error (%d): %f\n", j, gen_error[j]);
		}

		maxval = -1; maxfeat = -1;
		for(j = 0; j < (DATACOLS-1)*MODELCOMPLEXITY+1; ++j)
		if((presentfeatures[j] == (FORWARDSEARCHMODE)?0:1) && (maxval < 0 || maxval > gen_error[j])){
			maxval = gen_error[j];
			maxfeat = j;
		}

		//remove the winning feature from the subset
		if(FORWARDSEARCHMODE)presentfeatures[maxfeat] = 1;
		else presentfeatures[maxfeat] = 0;

		if(FORWARDSEARCHMODE)printf("Added feature: %d\n", maxfeat);
		else printf("Deleted feature: %d\n", maxfeat);

//		system("pause");
	}
	
	system("pause");

	return 0;
}
Esempio n. 18
0
int main()
{
	struct dbSysHead head;
	long fid1, fid2;

	/*
	≥ı ºªØ£¨»ª∫Û¥Ú”°≥ˆµ±«∞œµÕ≥µƒ–≈œ¢
	*/
	init_database(&head);
	showDesc(&head);

//	printf("create file1...\n");
	fid1 = creatFileSpace(&head);//Œ™Œƒº˛“ª∑÷≈‰ø’º‰
        fid2 = creatFileSpace(&head);
//	showFileDesc(&head);
/*	printf("extend 10 pages for file1...\n");
	extendFileSpace(&head, fid1, 10);//¿©’π Æ“≥
	showFileDesc(&head);
	printf("extend 10 pages for file1...\n");
	extendFileSpace(&head, fid1, 10);//‘Ÿ¿©’π Æ“≥
	showFileDesc(&head);

	printf("create file2...\n");
	fid2 = creatFileSpace(&head);
	showFileDesc(&head);
	printf("extend 10 pages for file2...\n");
	extendFileSpace(&head, fid2, 10);
	showFileDesc(&head);
	printf("extend 10 pages for file2...\n");
	extendFileSpace(&head, fid2, 10);
	showFileDesc(&head);

	printf("delete file1...\n");
	recyFileSpace(&head, fid1);
	showFileDesc(&head);
	printf("delete file2...\n");
	recyFileSpace(&head, fid2);
	showFileDesc(&head);*/
    //use dictID to scan file1
    /*
     int dictID = 1;
     int scanPointer = 0;
     int rec_length = head.redef[dictID].getRecordLength();
     printf("attributeName::%s", head.redef[dictID].getAttributeByNo(0).getName());
     RecordCursor scanTable(&head, 1, rec_length, 0);
     char * one_Row_ = (char *)malloc(sizeof(char)*rec_length);
     while (true == scanTable.getNextRecord(one_Row_)) { //only scan
     scanPointer ++;
     if(scanPointer > 230)
     getOneRecord(one_Row_, head.redef[dictID]); //get each attribute value and print
     }
     free(one_Row_);
     */

//	if(initTable(&head, fid1) == 0)
    if(initTable(&head, FIRST_FID) == 0)
		printf("1 initTable: customer.tbl\n");
	if(showTable(&head, "customer") == -1 )
		printf("2 showTable: customer\n");
    
    if(initTable(&head, FIRST_FID+1) == 0)
        printf("1 initTable: nation.tbl\n");
    if(showTable(&head, "nation") == -1 )
        printf("2 showTable: nation\n");
    //read customer.tbl and write into our file1, 一次性
    loaddata(&head, FIRST_FID);
    

    //Scan Table
    relation * temp_data_dict = new relation[MAX_FILE_NUM];
    TableScan(&head, FIRST_FID, temp_data_dict);
    //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1]
    int buffer_ID_ = - temp_data_dict[0].fileID;   //find which buffer
    int record_num_ = temp_data_dict[0].getRecordNum();
    int record_len_ = temp_data_dict[0].getRecordLength();
 //   RecordCursorTmp t1(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
 /*   int scanPointer = 0;
    int dictID = queryFileID(&head, FIRST_FID);
    char * one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t1.getNextRecord(one_Row_)) { //only scan
        scanPointer ++;
        if(scanPointer < 20)
            getOneRecord(one_Row_, &head.redef[dictID]); //get each attribute value and print
    }
    free(one_Row_);*/
    
    loaddata(&head, FIRST_FID + 1);
    
    TableScan(&head, FIRST_FID + 1, temp_data_dict);
    //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1]
    buffer_ID_ = - temp_data_dict[1].fileID;   //find which buffer
    record_num_ = temp_data_dict[1].getRecordNum();
    record_len_ = temp_data_dict[1].getRecordLength();
//    RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
/*    scanPointer = 0;
    dictID = queryFileID(&head, FIRST_FID + 1);
    char * one_Row_2 = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_2)) { //only scan
        scanPointer ++;
        if(scanPointer < 20)
            getOneRecord(one_Row_2, &head.redef[dictID]); //get each attribute value and print
    }
    free(one_Row_2);*/

    // create index
/*
    printf("recordNum:%d\n",head.redef[dictID].recordNum);
	if(true == createIndexOn(&head, 1, "custkey")){
		char* index_filename= "b_plus_tree_index_1custkey.dat";
		
		FILE* fp = fopen(index_filename,"rb+");
		printf("search(fp,-10):%d\n",search(fp,-10));
		printf("search(fp,1):%d\n",search(fp,1));
		printf("search(fp,2):%d\n",search(fp,2));
		printf("search(fp,50):%d\n",search(fp,50));
		display(fp);
		fclose(fp);
	}
	
    // insert one record
	relationDefine dic = head.redef[0];
    int size_per_record = dic.recordLength;
    char *oneRec = (char *)malloc(sizeof(char)*size_per_record);
        
	char * insertTest = (char *)malloc(sizeof(char)* 256);
    strcpy(insertTest,"501|Customer#000000001|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets. regular, ironic epitaphs nag eHHHHHH|");
    parserOneLineFromFile(insertTest, oneRec, dic);
    insertOneRecord(&head, 1, oneRec);//≤»ΓªÃı ˝æ›£¨◊‘∂Ø∏¸–¬À˜“˝
	free(insertTest);
    free(oneRec);
    
    // look up key in index
	char* index_filename= "b_plus_tree_index_1custkey.dat";
	FILE* fp = fopen(index_filename,"rb+");
	int pos = search(fp,501);
	printf("pos:::%d\n",pos);
	fclose(fp);
	
	
	one_Row_ = (char *)malloc(sizeof(char)*rec_length);
	rdFile( &head, 0, 1, pos, rec_length,one_Row_);
	printf("reading from index:\n");
	getOneRecord(one_Row_, dic);
*/    
    /*
	relation result;
	result.init("customer", "TianzhenWu");
	result.insertAttribute("name", 2, 64);
	result.insertAttribute("phone", 2, 64);
	showRelation(&result);
	project(&head, &temp_data_dict[0], &result);********/

    printf("start tableScanEqualFilter()...\n");
    
//    if(true == tableScanEqualFilter(&head, FIRST_FID, temp_data_dict,"custkey","3",&temp_data_dict[5])){
//	printf("tableScanEqualFilter()\n");
//    }
/*
    if(true == tableScanEqualFilter(&head, FIRST_FID, temp_data_dict,"name","Customer#000000009",&temp_data_dict[5])){
        printf("tableScanEqualFilter()\n");
    }

    buffer_ID_ = - temp_data_dict[5].fileID;   //find which buffer
    record_num_ = temp_data_dict[5].getRecordNum();
    record_len_ = temp_data_dict[5].getRecordLength();
    RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &temp_data_dict[5]); //get each attribute value and print
    }
    free(one_Row_);
    //head.buff[buffer_ID_].emptyOrnot = false;

*/
    if(true == tableScanScopeFilter(&head, FIRST_FID, temp_data_dict,"custkey","220",NOT_MORE_THAN,"230",LESS_THAN,&temp_data_dict[5])){
        printf("tableScanScopeFilter()\n");
    }

    buffer_ID_ = - temp_data_dict[5].fileID;   //find which buffer
    record_num_ = temp_data_dict[5].getRecordNum();
    record_len_ = temp_data_dict[5].getRecordLength();
    RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    char *one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &temp_data_dict[5]); //get each attribute value and print
    }
    free(one_Row_);
    //head.buff[buffer_ID_].emptyOrnot = false;



    showFileDesc(&head);
    exit_database(&head);
	system("pause");
	return 0;
}
Esempio n. 19
0
int main (int argc, char **argv) {
    int norun;
    char *startbrk, *endbrk;
    char *indir, *outdir, *outprefix;
    int attr;
    int splicemode;
    float digits;
    int bboxflag;

    startbrk = (char *) sbrk (0);
    indir = ".";
    outdir = ".";
    outprefix = "tiger";
    attr = T_EATTR_STATE;
    splicemode = 1;
    digits = 6;
    bboxflag = 0;
    savemask = 15;
    norun = 0;
    for (;;) {
        switch (optget (argv, usage)) {
        case -100:
            indir = opt_info.arg;
            continue;
        case -101:
            outdir = opt_info.arg;
            continue;
        case -200:
            splicemode = opt_info.num;
            continue;
        case -201:
            if ((digits = atof (opt_info.arg)) < 0)
                digits = -1;
            continue;
        case -300:
            if (strcmp (opt_info.arg, "zip") == 0)
                attr = T_EATTR_ZIP;
            else if (strcmp (opt_info.arg, "npanxxloc") == 0)
                attr = T_EATTR_NPANXXLOC;
            else if (strcmp (opt_info.arg, "state") == 0)
                attr = T_EATTR_STATE;
            else if (strcmp (opt_info.arg, "county") == 0)
                attr = T_EATTR_COUNTY;
            else if (strcmp (opt_info.arg, "ctbna") == 0)
                attr = T_EATTR_CTBNA;
            else if (strcmp (opt_info.arg, "blkg") == 0)
                attr = T_EATTR_BLKG;
            else if (strcmp (opt_info.arg, "blk") == 0)
                attr = T_EATTR_BLK;
            else if (strcmp (opt_info.arg, "blks") == 0)
                attr = T_EATTR_BLKS;
            else if (strcmp (opt_info.arg, "country") == 0)
                attr = T_EATTR_COUNTRY;
            else
                SUerror ("tiger2ps", "bad argument for -a option");
            continue;
        case -302:
            outprefix = opt_info.arg;
            continue;
        case -306:
            bboxflag = 1;
            continue;
        case -600:
            savemask &= 14;
            continue;
        case -601:
            savemask &= 13;
            continue;
        case -602:
            savemask &= 11;
            continue;
        case -603:
            savemask &= 7;
            continue;
        case -999:
            SUwarnlevel++;
            continue;
        case '?':
            SUusage (0, "tiger2ps", opt_info.arg);
            norun = 1;
            continue;
        case ':':
            SUusage (1, "tiger2ps", opt_info.arg);
            norun = 2;
            continue;
        }
        break;
    }
    if (norun)
        return norun - 1;
    argc -= opt_info.index, argv += opt_info.index;

    initrecords ();
    if (!(itemdict = dtopen (&itemdisc, Dtset)))
        SUerror ("tiger2ps", "dtopen failed");
    if (loaddata (indir) == -1)
        SUerror ("tiger2ps", "loaddata failed");
    if (splicemode > 0 && removedegree2vertices (splicemode) == -1)
        SUerror ("tiger2ps", "removedegree2vertices");
    if (digits >= 0 && simplifyxys (digits) == -1)
        SUerror ("tiger2ps", "simplifyxys failed");
    if (genpoints (attr) == -1)
        SUerror ("tiger2ps", "genpoints failed");
    calcbbox ();
    if (bboxflag)
        printbbox ();
    if ((savemask & 1) && savepoints (outdir, outprefix) == -1)
        SUerror ("tiger2ps", "savepoints failed for %s/%s", outdir, outprefix);
    if ((savemask & 2) && savelines (outdir, outprefix) == -1)
        SUerror ("tiger2ps", "savelines failed for %s/%s", outdir, outprefix);
    if ((savemask & 4) && savepolys (outdir, outprefix) == -1)
        SUerror ("tiger2ps", "savepolys failed for %s/%s", outdir, outprefix);
    if ((savemask & 8) && gentris () == -1)
        SUerror ("tiger2ps", "gentris failed");
    if ((savemask & 8) && savetris (outdir, outprefix) == -1)
        SUerror ("tiger2ps", "savetris failed for %s/%s", outdir, outprefix);
    printstats ();
    endbrk = (char *) sbrk (0);
    SUmessage (1, "tiger2ps", "memory usage %d", endbrk - startbrk);
    return 0;
}
Esempio n. 20
0
int main(int argc, char *argv[])
{
	printf("running...\n");
	clock_t t1, t2;
	int i;

	int pkeylen = datalen[0];
	int *pkeydata = (int*)malloc(sizeof(int) * pkeylen);
	assert(pkeydata != NULL);

	int fkeylen = datalen[1];
	int *fkeydata = (int*)malloc(sizeof(int) * fkeylen);
	assert(fkeydata != NULL);

	loaddata(filenames, 0, pkeylen, pkeydata);
	loaddata(filenames, 1, fkeylen, fkeydata);

	int *p_keyzonenum = (int*)malloc(sizeof(int) * pkeylen);
	assert(p_keyzonenum);
	int *p_hisgram = (int*)malloc(sizeof(int) * ZONENUM);
	assert(p_hisgram);
	memset(p_hisgram, 0, sizeof(int) * ZONENUM);
	int *f_keyzonenum = (int*)malloc(sizeof(int) * fkeylen);
	assert(f_keyzonenum);
	int *f_hisgram = (int*)malloc(sizeof(int) * ZONENUM);
	assert(f_hisgram);
	memset(f_hisgram, 0, sizeof(int) * ZONENUM);

	printf("begin hash partition...\n");
	t1 = clock();
	hash_partition(pkeydata, pkeylen, p_keyzonenum, p_hisgram);
	t2 = clock();
	printf("private data partition time = %f\n", (double)(t2 - t1) / CLOCKS_PER_SEC);

	t1 = clock();
	hash_partition(fkeydata, fkeylen, f_keyzonenum, f_hisgram);
	t2 = clock();
	printf("foreign data partition time = %f\n", (double)(t2 - t1) / CLOCKS_PER_SEC);

	int *hashtable[ZONENUM];
	for (i = 0; i < ZONENUM; i++)
	{
		hashtable[i] = (int*)malloc(sizeof(int) * TABLESIZE);
		assert(hashtable[i]);
		memset(hashtable[i], 0, TABLESIZE * sizeof(int));
	}

	printf("begin building hashtable...\n");
	t1 = clock();
	buildhash_with_zone(pkeydata, hashtable, p_hisgram);
	t2 = clock();
	printf("build hashtable time = %f\n", (double)(t2 - t1) / CLOCKS_PER_SEC);

	for (i = 0; i < ZONENUM; i++)
		free(hashtable[i]);
	free(p_keyzonenum);
	free(p_hisgram);
	free(f_keyzonenum);
	free(f_hisgram);
	free(pkeydata);
	free(fkeydata);

	printf("ending...\n");
	return 0;
}
Esempio n. 21
0
void NetGuard_Special_Limit::loaddata()
{
	struct	user_data * u_data;

	#ifdef userlist_use_simple
	struct	user_list * m_users = muser_data->get_list();
	while (m_users != NULL) {
		u_data = m_users->data;
	#else
	ip_storage_hash::iterator it;
	for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
		u_data =  (*it).second;
	#endif
		struct user_special_accounting_data *accouning_data = (struct user_special_accounting_data *)u_data->module_data[user_special_limit_module_number];
		if (accouning_data) {
			user_shutdown(u_data);
		}
		user_init(u_data);
		#ifdef userlist_use_simple
		m_users = m_users->next;
		#endif
	}
}

void NetGuard_Special_Limit::savedata()
{
	struct	user_data * u_data;

	FILE *myfile;

	ng_logdebug_spam("saving users to %s",db_filename.c_str());

	myfile = fopen(db_filename.c_str(), "w+");
	if (!myfile) return;

	fwrite(ACC_SPECIAL_LIMIT_VERSION_MAGIC,strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC),1,myfile);

	struct user_special_limit_data * limit_data;

	int counter = 0;
	#ifdef userlist_use_simple
	struct	user_list * m_users = muser_data->get_list();
	while (m_users != NULL) {
		u_data = m_users->data;
	#else
	ip_storage_hash::iterator it;
	for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
		u_data =  (*it).second;
	#endif
		limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
		if	(limit_data) {
			counter++;
		}
		#ifdef userlist_use_simple
		m_users = m_users->next;
		#endif
	}
	//write number of users
	fwrite(&counter ,sizeof(counter),1, myfile);

	#ifdef userlist_use_simple
	m_users = muser_data->get_list();
	while (m_users != NULL) {
		u_data = m_users->data;
	#else
	for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
		u_data =  (*it).second;
	#endif
		limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
		if	(limit_data) {
			fwrite(&u_data->saddr ,sizeof(u_data->saddr),1, myfile);
		} else {
			ng_logerror("skipping user %-15s on saving - no data present",inet_ntoa(*(struct in_addr *)&u_data->saddr));
		}
		#ifdef userlist_use_simple
		m_users = m_users->next;
		#endif
	}

	#ifdef userlist_use_simple
	m_users = muser_data->get_list();
	while (m_users != NULL) {
		u_data = m_users->data;
	#else
	for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
		u_data =  (*it).second;
	#endif
		limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
		if	(limit_data) {
			fwrite(limit_data,sizeof(struct user_special_limit_data),1, myfile);
			ng_logdebug_spam("save user %-15s max %lld",inet_ntoa(*(struct in_addr *)&u_data->saddr),limit_data->limit);
		}
		#ifdef userlist_use_simple
		m_users = m_users->next;
		#endif
	}
	ng_logdebug_spam("saved %d users",counter);

	fwrite(ACC_SPECIAL_LIMIT_VERSION_MAGIC,strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC),1,myfile);
	fclose(myfile);
}

struct user_special_limit_data * NetGuard_Special_Limit::load_limit_data(struct user_data *u_data, char *filename, int rename_onfail){
	FILE *myfile;
	struct stat fileinfo;
	char *tmpdata;
	struct user_special_limit_data * limit_data = NULL;
	int i;
	off_t f_pos;

	ng_logdebug_spam("loading data from %s",db_filename.c_str());

	if (stat(db_filename.c_str(),&fileinfo)) {
		ng_logerror("cant stat data file %s",db_filename.c_str());
		return NULL;
	}
	myfile = fopen(db_filename.c_str(), "r");
	if (!myfile) {
		ng_logerror("cant open data file %s",db_filename.c_str());
		return NULL;
	}
	
	//check file version
	tmpdata = (char *)malloc(sizeof(unsigned char)*(strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC)+1));
	tmpdata[strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC)] = 0;
	int count = fread(&tmpdata[0],strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC),1,myfile);
	if ((count != 1) || strcmp(tmpdata,ACC_SPECIAL_LIMIT_VERSION_MAGIC) ) {
		ng_logerror("limit: cant read traffic data from %s - illegal format (%s <> %s)",db_filename.c_str(),(char *)tmpdata,ACC_SPECIAL_LIMIT_VERSION_MAGIC);

		if (rename_onfail)
		{
			free(tmpdata);
			tmpdata = (char *)malloc(sizeof(unsigned char)*(strlen(db_filename.c_str())+20));
			time_t now;
			time(&now);		/* get the current time */
			sprintf(tmpdata,"%s_%d",db_filename.c_str(),(int)now);
			ng_log("renaming file to %s",tmpdata);
			rename(db_filename.c_str(),tmpdata);
		}
		return NULL;
	}

	f_pos = ftell(myfile);
	fseek(myfile,fileinfo.st_size-strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC),SEEK_SET);
	count = fread(&tmpdata[0],strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC),1,myfile);
	if ((count != 1) || strcmp(tmpdata,ACC_SPECIAL_LIMIT_VERSION_MAGIC) ) {
		ng_logerror("cant read traffic data from %s - illegal (end) format (%s <> %s)",db_filename.c_str(),(char *)tmpdata,ACC_SPECIAL_LIMIT_VERSION_MAGIC);

		if (rename_onfail)
		{
			free(tmpdata);
			tmpdata = (char *)malloc(sizeof(unsigned char)*(strlen(db_filename.c_str())+20));
			time_t now;
			time(&now);		/* get the current time */
			sprintf(tmpdata,"%s_%d",db_filename.c_str(),(int)now);
			ng_log("renaming file to %s",tmpdata);
			rename(db_filename.c_str(),tmpdata);
		}
		return NULL;
	}
	//set to old position again
	fseek(myfile,f_pos,SEEK_SET);

	ng_logdebug_spam("loading %lu bytes data",fileinfo.st_size);

	int counter = 0;
	count = fread(&counter,sizeof(counter),1, myfile);
	if (count  != 1 ) return NULL;
	ng_logdebug_spam("found %d users in file",counter);

	u_int32_t saddr;
	int found = 0;
	unsigned int seek_pos = 0;
	for (i=1; i<=counter ; i++ )
	{
		count = fread(&saddr ,sizeof(saddr),1, myfile);
		if (count  != 1 ) return NULL;
		if (saddr == u_data->saddr)
		{
			found = 1;
			seek_pos = i;
			ng_logdebug_spam("found user %-15s on pos %d",inet_ntoa(*(struct in_addr *)&u_data->saddr),seek_pos);
		}
	}

	if (!found) return NULL;
	seek_pos = (seek_pos-1) * sizeof(struct user_special_limit_data) + ftell(myfile);
	fseek(myfile,seek_pos,SEEK_SET);


	limit_data = (struct user_special_limit_data *)malloc(sizeof(struct user_special_limit_data));
	count = fread(limit_data,sizeof(struct user_special_limit_data),1, myfile);
	if (count  != 1 ) {
		delete limit_data;
		return NULL;
	}
	ng_logdebug_spam("loaded user data for %-15s (max: %lld) ",inet_ntoa(*(struct in_addr *)&u_data->saddr),limit_data->limit);

	fclose(myfile);
	free(tmpdata);

	return limit_data;
}

int NetGuard_Special_Limit::init(NetGuard_Config *data)
{
	general_acccounting = NULL;
	muser_data = NULL;

	ng_logdebug_spam("init");
	if (!data) return -1;
	int ret = NetGuard_Module::init(data); //important to get needed links
	if (ret) return ret;

	if (data_->GetStr("user_special_limit_filename") == "")
	{
		ng_logerror("need a user_special_limit_filename in config data");
		return -2;
	}
	db_filename=data_->GetStr("user_special_limit_filename");

	if (data_->GetModule("module_general_accounting") == NULL) {
		ng_logerror("need general_accounting module needs to be loaded");
		return -2;
	}


	//filter for accountable traffic
	if (data_->GetStr("accounting_filter_own") == "")
	{
		ng_logerror("need an accounting_filter_own in config data");
		return -2;
	}
	std::string filter_name_own=data_->GetStr("accounting_filter_own");

	filter_own = NetGuard_Global_IP_Filter::Filter(filter_name_own);
	if (filter_own == NULL)
	{
		ng_logerror("filter passed with accounting_filter_own (%s) does not exists",filter_name_own.c_str());
		return -2;
	}
	ng_logdebug_spam("using filter (%s) for filtering accounting ips",filter_own->GetPrefixName().c_str());

	//filter for internal traffic
	if (data_->GetStr("accounting_filter_intern") == "")
	{
		ng_logerror("need an accounting_filter_intern in config data");
		return -2;
	}
	std::string filter_name_intern=data_->GetStr("accounting_filter_intern");

	filter_intern = NetGuard_Global_IP_Filter::Filter(filter_name_intern);
	if (filter_intern == NULL)
	{
		ng_logerror("filter passed with accounting_filter_intern (%s) does not exists",filter_name_intern.c_str());
		return -2;
	}
	ng_logdebug_spam("using filter (%s) for filtering internal traffic",filter_intern->GetPrefixName().c_str());


	if (data_->GetInt("default_limit") != MININT)
	{
		default_limit = data_->GetInt("default_limit");
		default_limit = default_limit*1024*1024;
		ng_logdebug("set default_limit to %llu",default_limit);
	}

	if (data_->GetInt("default_max_limit") != MININT)
	{
		default_max_limit = data_->GetInt("default_max_limit");
		default_max_limit = default_max_limit*1024*1024;
		ng_logdebug("set default_max_limit to %llu",default_max_limit);
	}

	if (data_->GetInt("default_daily_addition") != MININT)
	{
		default_daily_addition = data_->GetInt("default_daily_addition");
		default_daily_addition = default_daily_addition*1024*1024;
		ng_logdebug("set default_daily_addition to %llu",default_daily_addition);
	}

	general_acccounting = (NetGuard_General_Module*)data_->GetModule("module_general_accounting");
	muser_data = (User_Data_Tools*)general_acccounting->get_data(NULL);

	my_dis_state = NetGuard_State_Handler::get_state(GlobalCFG::GetStr("user_special_limit.disable_state","disabled"));
	if (!my_dis_state) {
		ng_logerror("%s state %s unkown",__FUNCTION__,GlobalCFG::GetStr("user_special_limit.disable_state","disabled").c_str());
		return -2;
	}

	my_fail_state = NetGuard_State_Handler::get_state(GlobalCFG::GetStr("user_special_limit.failure_state","failure"));
	if (!my_fail_state) {
		ng_logerror("%s state %s unkown",__FUNCTION__,GlobalCFG::GetStr("user_special_limit.failure_state","failure").c_str());
		return -2;
	}

	my_enabled_state = NetGuard_State_Handler::get_state(GlobalCFG::GetStr("user_special_limit.enabled_state","enabled"));
	if (!my_enabled_state) {
		ng_logerror("%s state %s unkown",__FUNCTION__,GlobalCFG::GetStr("user_special_limit.enabled_state","enabled").c_str());
		return -2;
	}

	loaddata();

	return 0;
}

void NetGuard_Special_Limit::shutdown()
{
	ng_logdebug_spam("shutdown");
	if (muser_data)
	{
		struct	user_data *u_data;
		#ifdef userlist_use_simple
		struct	user_list *m_users = muser_data->get_list();
		while (m_users != NULL) {
			u_data = m_users->data;
		#else
		ip_storage_hash::iterator it;
		for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
			u_data =  (*it).second;
		#endif
			user_shutdown(u_data);
			#ifdef userlist_use_simple
			m_users = m_users->next;
			#endif
		}
	}

	general_acccounting = NULL;
	muser_data = NULL;
}

struct user_special_limit_data *NetGuard_Special_Limit::my_user_init(struct user_data *u_data, bool doload)
{
	struct user_special_limit_data * limit_data = NULL;
	
	//try to load it from file
	if (doload)
		limit_data = load_limit_data(u_data,NULL,1);

	if (limit_data == NULL)
	{
		ng_logdebug("setting new default special limits for %-15s",inet_ntoa(*(struct in_addr *)&u_data->saddr));
		//we need to init a new user
		//we need to init a new user
		limit_data = (struct user_special_limit_data *)malloc(sizeof(struct user_special_limit_data));

		//set default values
		memset(limit_data,0,sizeof(struct user_special_limit_data));
		limit_data->limit = (long long int)default_limit;
		limit_data->daily_addition = (unsigned long long int)default_daily_addition;
		limit_data->max_limit = (unsigned long long int)default_max_limit;
		u_data->external.bytes = limit_data->limit;
	};

	u_data->module_data[user_special_limit_module_number] = limit_data;

	return limit_data;	
}

void NetGuard_Special_Limit::user_init(struct user_data *u_data)
{
	if (!u_data) return;
	ng_logdebug_spam("user_init for %-15s",inet_ntoa(*(struct in_addr *)&u_data->saddr));
	my_user_init(u_data,true);
}

void NetGuard_Special_Limit::user_shutdown(struct user_data *u_data)
{
	struct user_special_limit_data * limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
	if ( limit_data != NULL ) {		
		ng_logdebug_spam("free limits data for %-15s",inet_ntoa(*(struct in_addr *)&u_data->saddr));
		delete limit_data;
	}
	u_data->module_data[user_special_limit_module_number] = NULL;
}


void NetGuard_Special_Limit::do_user_data_forgetday(int day, struct user_data *u_data){

	struct user_special_limit_data *limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
	long long int temp = u_data->external.bytes;

	if ( limit_data == NULL ) {
		limit_data = my_user_init(u_data,true);
	}

	if((u_data->external.bytes + limit_data->daily_addition) > limit_data->max_limit)
		 u_data->external.bytes = limit_data->max_limit;
	else
		 u_data->external.bytes += limit_data->daily_addition;

	NetGuard_User_State* nu_state = NetGuard_State_Handler::user_state(u_data);

	if (*nu_state == my_enabled_state) return;
	if (*nu_state == my_fail_state) return;

	if(temp == 0){
		if (!nu_state->set(my_enabled_state,GlobalCFG::GetStr("user_special_limit.enable_new_traffic","automatic enabling with new traffic"))) {
			ng_logerror("%s - %s - %d - ip: %s vlan: %d - could not do the state transition from %s to %s",__FUNCTION__,__FILE__,__LINE__,inet_ntoa(*(struct in_addr *)&nu_state->Getuser().saddr),nu_state->Getuser().vlan_id,nu_state->state()->GetName().c_str(),my_dis_state->GetName().c_str());
			return;
		}
	}
}

void NetGuard_Special_Limit::user_data_forgetday(int day)
{
	struct	user_data *u_data;

	#ifdef userlist_use_simple
	struct	user_list *m_users = muser_data->get_list();
	while (m_users != NULL) {
		u_data = m_users->data;
	#else
	ip_storage_hash::iterator it;
	for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
		u_data =  (*it).second;
	#endif

		//forget this day for external traffic
		do_user_data_forgetday(day,u_data);

		#ifdef userlist_use_simple
		m_users = m_users->next;
		#endif
	}
}

void NetGuard_Special_Limit::checkmax(struct user_special_limit_data * limit_data,struct user_data *u_data) {

	if(limit_data->limit > 0)
	{
		if(u_data->external.bytes <= 0)
		{
			// we have somebody over the internal over all limit
			NetGuard_User_State* nu_state = NetGuard_State_Handler::user_state(u_data);

			//ignore if we are already in the same state
			if (*nu_state == my_dis_state) return;
			if (*nu_state == my_fail_state) return;

			//nu_state->params()->SetInt("external_limit_exceeded",nu_state->params()->GetInt("external_limit_exceeded",0)+1);
			if (!nu_state->set(my_dis_state,GlobalCFG::GetStr("user_limit.disable_int_state_overall_msg","user have no traffic left"))) {
				ng_logerror("%s - %s - %d - ip: %s vlan: %d - could not do the state transition from %s to %s",__FUNCTION__,__FILE__,__LINE__,inet_ntoa(*(struct in_addr *)&nu_state->Getuser().saddr),nu_state->Getuser().vlan_id,nu_state->state()->GetName().c_str(),my_dis_state->GetName().c_str());
				return;
			}
		}
	}
}

void NetGuard_Special_Limit::packet_in(struct user_data *u_data, int *mode, unsigned int *vlanid, struct tpacket_hdr *h, struct ether_header *eth, struct iphdr *ip, struct tcphdr *tcp, void *data)
{
	in_addr_t *index_addr;
	in_addr_t *index_addr2;
	index_addr = 0;
	index_addr2 = 0;

	//we are only interested in packages that are linked to a user already	
	if (!u_data) return;

	struct user_special_limit_data *limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
	if ( limit_data == NULL ) {
		limit_data = my_user_init(u_data,true);
	}

	if (eth->ether_type == htons_ETHERTYPE_IP) {
		hl_saddr = ntohl(ip->saddr);
		hl_daddr = ntohl(ip->daddr);
		if ((*filter_own)==&hl_saddr) index_addr = &ip->saddr;
		if ((*filter_own)==&hl_daddr) index_addr2 = &ip->daddr;
	} else if (eth->ether_type == htons_ETHERTYPE_ARP) {
		struct ether_arp * arph;
		//#if __GNUC__ >= 4
		arph = (struct ether_arp *)ip;
		//#else
		//(void *)arph = (void *)ip;
		//#endif		
		hl_saddr = ntohl(*(uint32_t *)&arph->arp_spa);
		hl_daddr = ntohl(*(uint32_t *)&arph->arp_tpa);
		if ((*filter_own)==&hl_saddr) index_addr = (uint32_t *)&arph->arp_spa;
		if ((*filter_own)==&hl_daddr) index_addr2 = (uint32_t *)&arph->arp_tpa;
	}

	

	struct user_data_traffic *traffic_type;
	
	//set if internal or external traffic
	//default is internal for all non ip protocols


	if (eth->ether_type == htons_ETHERTYPE_IP) {
		//on ip its external per default
		traffic_type = &u_data->external;

		//if it match the filters its internal -> return
		if ((*filter_intern) == &hl_daddr && (*filter_intern)==&hl_saddr) return;
	}else
		return;

	signed long long int tmpval;
	tmpval = traffic_type->bytes;

	if((tmpval - h->tp_len) >= 0)
		traffic_type->bytes = traffic_type->bytes - h->tp_len;
	else 
		traffic_type->bytes = 0;

	checkmax(limit_data,u_data);
}

void NetGuard_Special_Limit::got_input(std::vector<std::string> params, std::vector<int> intparams, std::string command)
{
	if (params[0] == "help")
	{
		ng_logout("save - save limit data");
		ng_logout("dumpip <ip> <vlan> - show details for an ip");
		ng_logout("dumpip_all <ip> <vlan> - show details for an ip");
		ng_logout("set_limit <ip> <vlan> <start limit MB> <daily add MB> <maximum MB> - set limit data for an ip");
		//TODO: ng_logout("set_limit_reset <ip> <vlan> - set limit data for an ip to default"); 
		ng_logout("set_current_traffic <ip> <vlan> <traffic MB> - set the current traffic volume for an ip");
	}

	if (params[0] == "version")
	{
		ng_logext(100,"%s - Version: %s build: %s from %s at %s with %s",NetGuard_NAME, NetGuard_VERSION,NetGuard_COMPILE_DATE,NetGuard_COMPILE_BY,NetGuard_COMPILE_HOST,NetGuard_COMPILER);
	}

	if (params[0] == "save")
	{
		savedata();
	}

	if ((params[0] == "dumpip") ||  (params[0] == "dumpip_all"))
	{
		if (params.size() != 3)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan>",params[0].c_str());
			return;
		}
		struct in_addr m_ip;
		if (!inet_aton(params[1].c_str(),&m_ip ))
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan>",params[0].c_str());
			return;
		}
		if (intparams[2]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan>",params[0].c_str());
			return;
		}

		unsigned int tmpvlanid = intparams[2];
		struct user_data *u_data = muser_data->get_user(&m_ip.s_addr,&tmpvlanid);
		if (!u_data) 
		{
			ng_logout_not_found("could not find user with ip: %s vlan: %d",inet_ntoa(*(struct in_addr *)&m_ip.s_addr),intparams[2]);
			return;
		}
		

		#define EINHEIT 1024/1024
		struct user_special_limit_data *limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
		if ( limit_data == NULL ) {
			limit_data = my_user_init(u_data,true);
		}

		ng_logout("start limit \t\t: %llu MByte",limit_data->limit/EINHEIT);
		ng_logout("daily addition \t\t: %llu MByte",limit_data->daily_addition/EINHEIT);
		ng_logout("max limit \t\t: %llu MByte",limit_data->max_limit/EINHEIT);

		ng_logout("current usage \t\t: %llu MByte",u_data->external.bytes/EINHEIT);
	}

	if ((params[0] == "set_limit"))
	{
		if (params.size() != 6)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}
		struct in_addr m_ip;
		if (!inet_aton(params[1].c_str(),&m_ip ))
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}
		if (intparams[2]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}

		if (intparams[3]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}

		if (intparams[4]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}

		if (intparams[5]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}

		unsigned int tmpvlanid = intparams[2];
		struct user_data *u_data = muser_data->get_user(&m_ip.s_addr,&tmpvlanid);
		if (!u_data) 
		{
			ng_logout_not_found("could not find user with ip: %s vlan: %d",inet_ntoa(*(struct in_addr *)&m_ip.s_addr),intparams[2]);
			return;
		}

		struct user_special_limit_data *special_limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
		if ( special_limit_data == NULL ) {
			special_limit_data = my_user_init(u_data,true);
		}

		#define EINHEIT2 1024*1024

		unsigned long long int tmpval,tmpval2,tmpval3;
		tmpval = (unsigned long long int)intparams[3] * (unsigned long long int)EINHEIT2;
		tmpval2 = (unsigned long long int)intparams[4] * (unsigned long long int)EINHEIT2;
		tmpval3 = (unsigned long long int)intparams[5] * (unsigned long long int)EINHEIT2;

		ng_logout_ok("setting new special limit data");
		special_limit_data->limit = tmpval;
		special_limit_data->daily_addition = tmpval2;
		special_limit_data->max_limit = tmpval3;

	}

	if ((params[0] == "set_current_traffic"))
	{
		if (params.size() != 4)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <traffic MB>",params[0].c_str());
			return;
		}
		struct in_addr m_ip;
		if (!inet_aton(params[1].c_str(),&m_ip ))
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <traffic MB>",params[0].c_str());
			return;
		}
		if (intparams[2]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <traffic MB>",params[0].c_str());
			return;
		}

		if (intparams[3]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <traffic MB>",params[0].c_str());
			return;
		}

		unsigned int tmpvlanid = intparams[2];
		struct user_data *u_data = muser_data->get_user(&m_ip.s_addr,&tmpvlanid);
		if (!u_data) 
		{
			ng_logout_not_found("could not find user with ip: %s vlan: %d",inet_ntoa(*(struct in_addr *)&m_ip.s_addr),intparams[2]);
			return;
		}

		#define EINHEIT 1024/1024
		#define EINHEIT2 1024*1024

		unsigned long long int tmpval;

		tmpval = (unsigned long long int)intparams[3] * (unsigned long long int)EINHEIT2;

		u_data->external.bytes = tmpval;
		ng_logout_ok("new traffic successfully set to: %llu MB",u_data->external.bytes/EINHEIT);
	}
}

void NetGuard_Special_Limit::timer_tick() {
}
Esempio n. 22
0
int main(int argc, char **argv)
{
	printf("begining...\n");
	struct timeval start, end;
	long cost_time;

	int param1 = atoi(argv[1]);
	int param2 = atoi(argv[2]);

	int pkeylen = DATALEN[param1];
	int fkeylen = DATALEN[param2];

	printf("malloc space...\n");
	gettimeofday(&start, NULL);
	int *pkeydata = (int*)malloc(sizeof(int) * pkeylen);
	assert(pkeydata);
	int *fkeydata = (int*)malloc(sizeof(int) * fkeylen);
	assert(fkeydata);
	int *hashtable = (int*)malloc(sizeof(int) * TABLESIZE * ZONENUM);
	assert(hashtable);
	memset(hashtable, 0, sizeof(int) * TABLESIZE *ZONENUM);
	gettimeofday(&end, NULL);
	cost_time = 1000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000;
	printf("malloc time = %d\n", cost_time);

	printf("loading data...\n");
	gettimeofday(&start, NULL);
	loaddata(FILENAME, param1, pkeylen, pkeydata);
	loaddata(FILENAME, param2, fkeylen, fkeydata);
	gettimeofday(&end, NULL);
	cost_time = 1000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000;
	printf("loaddata time = %d\n", cost_time);

	printf("hash partition...\n");
	gettimeofday(&start, NULL);

	long s_time = 0;
	Hash_Partition(pkeydata, pkeylen, &s_time);
	printf("S partition time = %d\n", s_time);

	long r_time = 0;
	Hash_Partition(fkeydata, fkeylen, &r_time);
	printf("R partition time = %d\n", r_time);

	gettimeofday(&end, NULL);
	cost_time = 1000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000;
	printf("partition time = %d\n", cost_time);

	printf("hash join...\n");
	
	long b_time = 0;
	long p_time = 0;
#pragma offload target(mic)\
	inout(pkeydata : length(pkeylen))\
	inout(fkeydata : length(fkeylen))\
	inout(hashtable : length(TABLESIZE *ZONENUM))
	Hash_Join(pkeydata, fkeydata, hashtable, pkeylen, fkeylen, &b_time, &p_time);
	printf("buid hash time = %d\n", b_time);
	printf("probe time = %d\n", p_time);
	

	printf("free space...\n");
	free(pkeydata);
	free(fkeydata);
	free(hashtable);

	printf("ending...\n");
	return 0;
}
Esempio n. 23
0
void
setmgvar(		/* set a variable */
char  *fname,
FILE  *fp,
char  *string
)
{
	char  name[128];
	FILE  *fp2;
	register int  i;
	register char  *s;
	register VARIABLE  *vp;

	if (!strncmp(string, "include=", 8)) {	/* include file */
		if ((s = findfile(string+8, libpath)) == NULL) {
			fprintf(stderr, "%s\n", string);
			fprintf(stderr, "%s: %s: File not found: %s\n",
					progname, fname, string+8);
			quit(1);
		}
		strcpy(name, s);
		mgload(name);
		return;
	}
	s = string;
	i = 0;
	while (i < sizeof(name)-1 && isid(*s))
		name[i++] = *s++;
	name[i] = '\0';
	vp = vlookup(name);
	if (vp != NULL) {
		undefine(vp);
		switch (vp->type) {
		case REAL:
		case FUNCTION:
			if ((*s == '(') != (vp->type == FUNCTION)) {
				fprintf(stderr, "%s\n", string);
				fprintf(stderr,
					"%s: %s: Bad %s declaration: %s\n",
					progname, fname,
					vp->type == FUNCTION ?
					"function" : "variable",
					name);
				quit(1);
			}
			scompile(string, fname, 0);
			vp->v.dfn = savestr(string);
			break;
		case STRING:
			if (*s++ != '=') {
				fprintf(stderr, "%s\n", string);
				fprintf(stderr, "%s: %s: Missing '='\n",
						progname, fname);
				quit(1);
			}
			vp->v.s = savestr(s);
			break;
		case DATA:
			if (*s++ != '=') {
				fprintf(stderr, "%s\n", string);
				fprintf(stderr, "%s: %s: Missing '='\n",
						progname, fname);
				quit(1);
			}
			if (!*s) {
				loaddata(fname, fp, &vp->v.d);
			} else if (*s == '!') {
				if ((fp2 = popen(s+1, "r")) == NULL) {
					fprintf(stderr, "%s\n", string);
					fprintf(stderr,
					"%s: %s: Cannot execute: %s\n",
							progname, fname, s+1);
					quit(1);
				}
				loaddata(s, fp2, &vp->v.d);
				pclose(fp2);
			} else {
				if ((fp2 = fopen(s, "r")) == NULL) {
				    fprintf(stderr, "%s\n", string);
				    fprintf(stderr,
					    "%s: %s: Data file not found: %s\n",
					    progname, fname, s);
				    quit(1);
				}
				loaddata(s, fp2, &vp->v.d);
				fclose(fp2);
			}
			break;
		}
		vp->flags |= DEFINED;
	} else
		setivar(name, fname, string);		/* intermediate */
}