-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1028 lines (894 loc) · 24.7 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//该程序是rectangleBF的源码
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <windows.h>
#include <time.h>
#include <math.h>
#include "key-value.h"
#include "std_bf.h"
#include <fstream>
#include "hash_function.h"
#include "PeacockHash.h"
#include "dleftHash.h"
#include "DoubleHash.h"
#include "LinearHash.h"
#include "LinkHash.h"
#include "RTBHash.h"
#include "cuckooHash.h"
#define HT_STAGE_NUM 6
#define HASH_ENTRY_MAX 500000
#include "md5.h"
#include "sha1.h"
using namespace std;
int counter1=0;
int counter2=0;
int counter3=0;
void finetuning_obverse(unsigned long long element,int index,
unsigned long long M1[],unsigned long long M2[],unsigned long long M3[],
long M_Level1,long M_Level2,long M_Level3,bool flag_1[],bool flag_3[])
{
int tmp=element;
int yushu1=element%M_Level1;
if (0==M1[yushu1] || element==M1[yushu1])//第一级没有冲突
{
M1[yushu1]=element;
}
//else if (0==M1[yushu1+1]||element==M1[yushu1+1])//放在邻接位置
//{
// M1[yushu1+1]=element;
//}
else
{
element=M1[yushu1];
M1[yushu1]=tmp;
int yushu2=element%M_Level2;
if (0==M2[yushu2] || element==M2[yushu2])//第一级冲突,第二级没有冲突
{
M2[yushu2]=element;
}
//else if (0==M2[yushu2+1]||element==M2[yushu2+1])//放在邻接位置
//{
// M2[yushu2+1]=element;
//}
else //两级都冲突
{
int yushu3=element%M_Level3;
if (0==M3[yushu3] || element==M3[yushu3])
{
M3[yushu3]=element;
}
//else if (0==M3[yushu3+1] || element == M3[yushu3+1])//放在邻接位置
//{
// M3[yushu3+1]=element;
//}
else //三级都冲突
{
//cout<<++counter3<<"正面微调失败!!!:"<<element<<"<->"<<M3[yushu3]<<endl;
printf("\r正面微调失败\t%d",counter3++);
//printf("\n%d:still collision:%u<->%ld\n",++counter,element,M3[yushu3]);
//system("pause");
}
}
}
}
void sandGlass(unsigned long long element,int index,
unsigned long long M1[],unsigned long long M2[],unsigned long long M3[],
long M_Level1,long M_Level2,long M_Level3,bool flag_1[],bool flag_3[])
{
if (element<0)
{
printf("\nelement is minus...\n");
return;
}
if (0==index%8 || 1==index%8 || 2==index%8 || 3==index%8)//偶数
{
long yushu1=element%M_Level1;
if (0==M1[yushu1] || element==M1[yushu1])//第一级没有冲突
{
M1[yushu1]=element;
}
else
{
long yushu2=element%M_Level2;
if (0==M2[yushu2] || element==M2[yushu2])//第二级没有冲突
{
M2[yushu2]=element;
}
else //两级都冲突
{
long yushu3=element%M_Level3;
if (0==M3[yushu3] || element==M3[yushu3])
{
M3[yushu3]=element;
}
else //三级都冲突
{
int tmp=M3[yushu3];
M3[yushu3]=element;
element=tmp;
counter1++;
//cout<<"\neven number---"<<++counter<<"still collision:"<<element<<"<->"<<M3[yushu3]<<endl;
finetuning_obverse(element,index,M1,M2,M3,M_Level1,M_Level2,M_Level3,flag_1,flag_3);
//system("pause");
}
}
}
}
else//奇数
{
long yushu3=element%M_Level3;
if (0==M3[yushu3] || element==M3[yushu3])//第三级没有冲突
{
M3[yushu3]=element;
}
else
{
long yushu2=element%M_Level2;
if (0==M2[yushu2] || element==M2[yushu2])//第二级没有冲突
{
M2[yushu2]=element;
}
else
{
long yushu1=element%M_Level1;
if (0==M1[yushu1] || element==M1[yushu1])//第一级没有冲突
{
M1[yushu1]=element;
}
else //三级都冲突
{
counter2++;
//cout<<"\nodd number---"<<++counter<<"still collision:"<<element<<"<->"<<M1[yushu1]<<endl;
finetuning_obverse(element,index,M1,M2,M3,M_Level1,M_Level2,M_Level3,flag_1,flag_3);
//system("pause");
}
}
}
}
}
unsigned long long my_hashFunc(char tohash[])
{
unsigned long long retu=0;
//MD5 md;
//md.reset();
//md.update(tohash);
//string res=md.toString();
//
//for (int i=0;i<8;i++)
//{
// //retu+=(res[i]-'0')*16*i;
// if (res[i]<'a')retu+=(res[i]-'0')*pow(16.0,i);
//
// else
// retu+=(res[i]-'a')*pow(16.0,i);
//}
return retu;
}
//后面写代码记得写备注,不然再次捡起来的时候会非常痛苦!
//这个代码如果没有输入参数,则加载默认值。主要是支持批处理,输入参数为:元素个数、瘦腰比例、装载因子
//读取的用于hash的是形如rrc*.txt的路由表文件。
//只有屏幕输出
void test(int argc, char* argv[])
{
//printf("%d-----",'a'-'0');
int ElementCount;
double ratio,alph;
if (argc<3)
{
printf("输入为空!加载默认值。格式:元素个数、瘦腰比例、装载因子\n");
ElementCount=354641;
ratio=3;
alph=0.5;
}
else
{
ElementCount=atoi(argv[1]);
ratio=atof(argv[2]);
alph=atof(argv[3]);
}
long M_Level2=ElementCount/alph/(2*ratio+1); //第二级hash的bloom长度
long M_Level1=M_Level2*ratio+1; //第1级hash的bloom长度
long M_Level3=M_Level1-2; //第三级
unsigned long long *M1=new unsigned long long[M_Level1+1];
unsigned long long *M2=new unsigned long long[M_Level2+1];
unsigned long long *M3=new unsigned long long[M_Level3+1];
bool *flag_1=new bool[M_Level1+1];
bool *flag_3=new bool[M_Level3+1];
for (int i=0;i<M_Level1+1;i++)
{
M1[i]=0;
flag_3[i]=0;
}
for (int i=0;i<M_Level2+1;i++)M2[i]=0;
for (int i=0;i<M_Level3+1;i++)
{
M3[i]=0;
flag_3[i]=0;
}
system("dir /B /ON rrc*.txt > fileList");
//char strName[200];
FILE * fList=fopen("fileList","r");
while (!feof(fList))
{
char filename[200];
memset(filename,0,sizeof(filename));
fscanf(fList,"%s",filename);
if (strlen(filename)<5)continue;
//FILE * fp=fopen(filename,"r");
ifstream fin(filename);
int index=0;
int jishu_C,oushu_C;
jishu_C=oushu_C=0;
while (!fin.eof())
{
int ip1,ip2,ip3,ip4,maskbit,hop;
ip1=ip2=ip3=ip4=maskbit=hop=-1;
//fscanf(fp,"%d.%d.%d.%d\/%d\t%d",&ip1,&ip2,&ip3,&ip4,&maskbit,&hop);
char str[50];
memset(str,0,sizeof(str));
//sprintf(str,"%d.%d.%d.%d.%d",&ip1,&ip2,&ip3,&ip4,&maskbit);
fin>>str>>hop;
if (-1==maskbit&&-1==hop)continue;
unsigned long long tohash=ip1*256+ip2+ip3*65536+ip4*16777216;
//hashing_cone(tohash,++index);
unsigned long long hash_value=my_hashFunc(str);
sandGlass(hash_value,++index,M1,M2,M3,M_Level1,M_Level2,M_Level3,flag_1,flag_3);
//if (0==index%1000)printf(".");
//printf("%d.%d.%d.%d\/%d\t%d\t...%d\n",ip1,ip2,ip3,ip4,maskbit,hop,tohash);
}
fin.close();
printf("\t未微调冲突:\t%d\t%d\n",counter1,counter2);
}
fclose(fList);
//printf("程序执行完毕!");
//system("pause");
}
//hashentry * readHashEntries(int & readline, char *inputfile)
//{
// hashentry *pHashentries=new hashentry[500000];
// memset(pHashentries,0,sizeof(hashentry)*500000);
//
// char *hashfile=inputfile;
// FILE *fp = fopen(hashfile,"r");
// if (NULL == fp)
// {
// printf("open %s failed", hashfile);
// return NULL;
// }
// while(!feof(fp))
// {
// fscanf(fp, "%s %u", pHashentries[readline].key, &(pHashentries[readline].value));
// if (strlen((const char *)(pHashentries[readline].key))>4)readline++;
// }
// fclose(fp);
//
// //test the correctness of this function, 读出了不少问题啊! 因为没有初始化
// //for (int j=300000; j<readline; j++)
// //{
// // printf("%d:\t%s\t%d\n", j, pHashentries[j].key, pHashentries[j].value);
// //}
//
// return pHashentries;
//}
//void naiveHash(int factor, FILE * f_out, int iFunc, char *inputfile)
//{
// int lines=0;
// int numCollisions=0;
//
// hashentry * pHashentries=readHashEntries(lines, inputfile);
//
// int tablelen = (factor*lines)%2==0 ? factor*lines+3 : factor*lines;
// hashentry * pHashtable=new hashentry[tablelen];
//
// for (int k=0; k<lines; k++)
// {
// memset(pHashtable[k].key,0,KEY_SIZE);
// pHashtable[k].value=0;
// }
//
// for (int i=0; i<lines; i++)
// {
// int len=strlen((const char *)(pHashentries[i].key));
// uint pos=hash_func[iFunc]((const unsigned char *)(pHashentries[i].key), len) % (tablelen);
//
// if (pHashtable[pos].value == 0)
// {
// memcpy(pHashtable[pos].key, pHashentries[i].key, len);
// pHashtable[pos].value=pHashentries[i].value;
// }
// else
// {
// /*static int i=1;
// printf("pos=%d\t, here key_value=%s<->%u, there are %d hash collison...\n",pos, pHashentries[i].key, pHashtable[pos].value, i++);*/
// numCollisions++;
// }
// }
// printf("factor/collisions/ratio:\t%d:\t%d\t%.7f\n",factor, numCollisions, (0.0+numCollisions)/lines);
// fprintf(f_out, "%.7f\t", (0.0+numCollisions)/lines);
//
// delete pHashentries;
// delete pHashtable;
//}
//void multiHash(float factor, FILE * f_out, int iFunc, char *inputfile, int numStage)
//{
// int lines=0;
// int numCollisions=0;
//
// hashentry * pHashentries=readHashEntries(lines, inputfile);
//
// //int tablelen = (factor*lines)%2==0 ? factor*lines+3 : factor*lines;
// int HT_len[HT_STAGE_NUM];
// float tmp=6/factor+0.0;
//
// //等长,0.0577
// //HT_len[0]=lines/tmp-3;
// //HT_len[1]=lines/tmp-2;
// //HT_len[2]=lines/tmp-1;
// //HT_len[3]=lines/tmp;
// //HT_len[4]=lines/tmp+1;
// //HT_len[5]=lines/tmp+2;
//
// //等差长度的更好,哈哈,0.052
// //HT_len[0]=lines/tmp*0.19*6-3;
// //HT_len[1]=lines/tmp*0.18*6-2;
// //HT_len[2]=lines/tmp*0.17*6-1;
// //HT_len[3]=lines/tmp*0.16*6;
// //HT_len[4]=lines/tmp*0.155*6+1;
// //HT_len[5]=lines/tmp*0.145*6+2;
//
// //等差长度的更好,哈哈,0.0407,至今最好结果
// //HT_len[0]=lines/tmp*0.30*6-3;
// //HT_len[1]=lines/tmp*0.24*6-2;
// //HT_len[2]=lines/tmp*0.18*6-1;
// //HT_len[3]=lines/tmp*0.12*6;
// //HT_len[4]=lines/tmp*0.09*6+1;
// //HT_len[5]=lines/tmp*0.07*6+2;
//
// //。。。近似伪等差数列,0.03857
// //HT_len[0]=lines/tmp*0.30*6-3;
// //HT_len[1]=lines/tmp*0.24*6-2;
// //HT_len[2]=lines/tmp*0.18*6-1;
// //HT_len[3]=lines/tmp*0.13*6;
// //HT_len[4]=lines/tmp*0.09*6+1;
// //HT_len[5]=lines/tmp*0.06*6+2;
//
// //。。。严格伪等差数列,0.03839, 至今最好结果
// HT_len[0]=lines/tmp*0.29583*6-3;
// HT_len[1]=lines/tmp*0.23083*6-2;
// HT_len[2]=lines/tmp*0.17583*6-1;
// HT_len[3]=lines/tmp*0.13083*6;
// HT_len[4]=lines/tmp*0.09583*6+1;
// HT_len[5]=lines/tmp*0.07083*6+2;
//
// hashentry * pHT[HT_STAGE_NUM];
// for (int j=0; j<HT_STAGE_NUM; j++)
// {
// pHT[j]=new hashentry[HT_len[j]];
// memset(pHT[j], 0, HT_len[j]*sizeof(hashentry));
// }
//
// //to do...
// //hashentryP * pHT_Tail;
// //define a load factor for each stage...
//
// for (int i=0; i<lines; i++)
// {
// int len=strlen((const char *)(pHashentries[i].key));
// uint hash_value=hash_func[iFunc]((const unsigned char *)(pHashentries[i].key), len);
//
// int kk=0;
// while (kk<6)
// {
// uint pos = hash_value%HT_len[kk];
// if (0==pHT[kk][pos].value)
// {
// memcpy(pHT[kk][pos].key, pHashentries[i].key, len);
// pHT[kk][pos].value=pHashentries[i].value;
// break;
// }
// kk++;
// }
//
// if (6==kk)
// {
// /*static int i=1;
// printf("pos=%d\t, here key_value=%s<->%u, there are %d hash collison...\n",pos, pHashentries[i].key, pHashtable[pos].value, i++);*/
// numCollisions++;
// }
// }
//
// printf("factor/collisions/ratio:\t%f:\t%d\t%.7f\n",factor, numCollisions, (0.0+numCollisions)/lines);
// fprintf(f_out, "%.7f\t", (0.0+numCollisions)/lines);
//
//
// //release the memory...
// delete pHashentries;
// for (int jjj=0; jjj<HT_STAGE_NUM; jjj++)
// {
// if(pHT[jjj])delete pHT[jjj];
// }
//}
//void main_hashCollisionTest(int argc, char* argv[])
//{
// char inputfile[100];
// memset(inputfile, 0, sizeof(inputfile));
// if (argc>1)strcpy(inputfile,argv[1]);
// else strcpy(inputfile,"rib.txt");
//
// printf("\n\nStart to process %s...\n", inputfile);
//
// char outputfile[100];
// memset(outputfile, 0, sizeof(outputfile));
// sprintf(outputfile, "%s.stat", inputfile);
//
// FILE *f_out = fopen(outputfile, "w");
// fprintf(f_out,"BOB1\tJSHash\tOCaml\tOAAT\tPJWHash\tRSHash\tSDBM\tSimple\tSML\tSTL\tAPHash\tBKDR\tDEKHash\tDJBHash\tFNV32\tHsieh\n");
// //for (int i=0; i<16; i++)
// //{
// // for (int factor = 2; factor < 16; factor++)
// // {
// // naiveHash(factor, f_out, i, inputfile);
// // }
// // fprintf(f_out, "\n");
// //}
// //for (int i=0; i<16; i++)
// {
// //printf("hash function %d:\n", i);
// for (float factor = 1; factor < 1.06; factor+=0.01)
// {
// multiHash(factor, f_out, 11, inputfile, HT_STAGE_NUM);
// }
// }
// fclose(f_out);
//
//}
bool linkExperiments(char * fibfile, char * trafficfile, char * updatefile, float ht_times)
{
try
{
int fiblen=getFIBSize(fibfile);
LHash aHashtable;
cout << "successful initial" <<endl;
printf("\n\nStart to process %s...\n", fibfile);
char outputfileInit[100];
memset(outputfileInit, 0, sizeof(outputfileInit));
sprintf(outputfileInit, "%s.link.init", fibfile);
char outputfileSearch[100];
memset(outputfileSearch, 0, sizeof(outputfileSearch));
sprintf(outputfileSearch, "%s.link.search", fibfile);
aHashtable.initialFromFile(fibfile, ht_times);
//test the correctness of initialFromFile
#ifdef _DEBUG
if(aHashtable.test(fibfile) == true)
{
printf("Congratulation! pass test!\n");
}
else
{
printf("not pass test");
}
#endif
aHashtable.report(outputfileInit);
//read the traffic, then search the hash table.
FILE * fp_traffic =fopen(trafficfile,"r");
if (NULL == fp_traffic) //If FilePtr is NULL
{
fprintf(stderr , "fibfile %s open failed!\n", trafficfile);
return false;
}
printf("\nstart traffic query...\n");
char key[KEYLENGTH];
memset(key , 0 , sizeof(key));
int readlines=0;
int val=0;
while(!feof(fp_traffic))
{
fscanf(fp_traffic, "%s", key);
readlines++;
aHashtable.search((const unsigned char *)key, val);
if (readlines%1000==0)
{
printf("\r%.2f%%", 100.0*readlines/fiblen/10);
}
}
printf("val=%d\n",val);
printf("\nafter the traffic query...\n");
aHashtable.report(outputfileSearch);
}
catch(char *s)
{
fprintf(stderr, "error: %s\n",s);
}
printf("Congrats! Traffic query is completed!\n");
return true;
}
bool linearExperiments(char * fibfile, char * trafficfile, char * updatefile, float ht_times)
{
try
{
int fiblen=getFIBSize(fibfile);
LinearHash aHashtable;
cout << "successful initial" <<endl;
printf("\n\nStart to process %s...\n", fibfile);
char outputfileInit[100];
memset(outputfileInit, 0, sizeof(outputfileInit));
sprintf(outputfileInit, "%s.linear.init", fibfile);
char outputfileSearch[100];
memset(outputfileSearch, 0, sizeof(outputfileSearch));
sprintf(outputfileSearch, "%s.linear.search", fibfile);
aHashtable.initialFromFile(fibfile, ht_times);
//test the correctness of initialFromFile
#ifdef _DEBUG
if(aHashtable.test(fibfile) == true)
{
printf("Congratulation! pass test!\n");
}
else
{
printf("not pass test");
}
#endif
aHashtable.report(outputfileInit);
//read the traffic, then search the hash table.
FILE * fp_traffic =fopen(trafficfile,"r");
if (NULL == fp_traffic) //If FilePtr is NULL
{
fprintf(stderr , "fibfile %s open failed!\n", trafficfile);
return false;
}
printf("\nstart traffic query...\n");
char key[KEYLENGTH];
memset(key , 0 , sizeof(key));
int readlines=0;
int val=0;
while(!feof(fp_traffic))
{
fscanf(fp_traffic, "%s", key);
readlines++;
aHashtable.search((const unsigned char *)key, val);
if (readlines%1000==0)
{
printf("\r%.2f%%", 100.0*readlines/fiblen/10);
}
}
printf("val=%d\n",val);
printf("\nafter the traffic query...\n");
aHashtable.report(outputfileSearch);
}
catch(char *s)
{
fprintf(stderr, "error: %s\n",s);
}
printf("Congrats! Traffic query is completed!\n");
return true;
}
bool doubleExperiments(char * fibfile, char * trafficfile, char * updatefile, float ht_times)
{
try
{
int fiblen=getFIBSize(fibfile);
DHash aHashtable;
cout << "successful initial" <<endl;
printf("\n\nStart to process %s...\n", fibfile);
char outputfileInit[100];
memset(outputfileInit, 0, sizeof(outputfileInit));
sprintf(outputfileInit, "%s.double.init", fibfile);
char outputfileSearch[100];
memset(outputfileSearch, 0, sizeof(outputfileSearch));
sprintf(outputfileSearch, "%s.double.search", fibfile);
aHashtable.initialFromFile(fibfile, ht_times);
//test the correctness of initialFromFile
#ifdef _DEBUG
if(aHashtable.test(fibfile) == true)
{
printf("Congratulation! pass test!\n");
}
else
{
printf("not pass test");
}
#endif
aHashtable.report(outputfileInit);
//read the traffic, then search the hash table.
FILE * fp_traffic =fopen(trafficfile,"r");
if (NULL == fp_traffic) //If FilePtr is NULL
{
fprintf(stderr , "fibfile %s open failed!\n", trafficfile);
return false;
}
printf("\nstart traffic query...\n");
char key[KEYLENGTH];
memset(key , 0 , sizeof(key));
int readlines=0;
int val=0;
while(!feof(fp_traffic))
{
fscanf(fp_traffic, "%s", key);
readlines++;
aHashtable.search((const unsigned char *)key, val);
if (readlines%1000==0)
{
printf("\r%.2f%%", 100.0*readlines/fiblen/10);
}
}
printf("val=%d\n",val);
printf("\nafter the traffic query...\n");
aHashtable.report(outputfileSearch);
}
catch(char *s)
{
fprintf(stderr, "error: %s\n",s);
}
printf("Congrats! Traffic query is completed!\n");
return true;
}
bool cuckooExperiments(char * fibfile, char * trafficfile, char * updatefile, float ht_times)
{
try
{
int fiblen=getFIBSize(fibfile);
cuckooHash aHashtable;
cout << "successful initial" <<endl;
printf("\n\nStart to process %s...\n", fibfile);
char * fibfileShort=&(fibfile[4]);
char outputfileInit[100];
memset(outputfileInit, 0, sizeof(outputfileInit));
sprintf(outputfileInit, "%s.cuckoo%.2f.init", fibfileShort, ht_times);
char outputfileSearch[100];
memset(outputfileSearch, 0, sizeof(outputfileSearch));
sprintf(outputfileSearch, "%s.cuckoo%.2f.search", fibfileShort,ht_times);
aHashtable.initialFromFile(fibfile, ht_times);
//test the correctness of initialFromFile
#ifdef _DEBUG
if(aHashtable.test(fibfile) == true)
{
printf("Congratulation! pass test!\n");
}
else
{
printf("not pass test");
}
#endif
//aHashtable.report(outputfileInit);
//read the traffic, then search the hash table.
FILE * fp_traffic =fopen(trafficfile,"r");
if (NULL == fp_traffic) //If FilePtr is NULL
{
fprintf(stderr , "fibfile %s open failed!\n", trafficfile);
return false;
}
printf("\nstart traffic query...\n");
char key[KEYLENGTH];
memset(key , 0 , sizeof(key));
int readlines=0;
int val=0;
while(!feof(fp_traffic))
{
fscanf(fp_traffic, "%s", key);
readlines++;
aHashtable.search((const unsigned char *)key, val);
if (readlines%1000==0)
{
printf("\r%.2f%%", 100.0*readlines/fiblen/10);
}
}
printf("val=%d\n",val);
printf("\nafter the traffic query...\n");
aHashtable.report(outputfileSearch);
}
catch(char *s)
{
fprintf(stderr, "error: %s\n",s);
}
printf("Congrats! Traffic query is completed!\n");
return true;
}
bool peacockExperiments(char * fibfile, char * trafficfile, char * updatefile, float ht_times)
{
try
{
int fiblen=getFIBSize(fibfile);
PeacockHash aHashtable;
cout << "successful initial" <<endl;
printf("\n\nStart to process %s...\n", fibfile);
char outputfileInit[100];
memset(outputfileInit, 0, sizeof(outputfileInit));
sprintf(outputfileInit, "%s.peacock.%.2f.init", fibfile, ht_times);
char outputfileSearch[100];
memset(outputfileSearch, 0, sizeof(outputfileSearch));
sprintf(outputfileSearch, "%s.peacock.%.2f.search", fibfile, ht_times);
aHashtable.initialFromFile(fibfile, ht_times);
//test the correctness of initialFromFile
#ifdef _DEBUG
if(aHashtable.test(fibfile) == true)
{
printf("Congratulation! pass test!\n");
}
else
{
printf("not pass test");
}
#endif
//aHashtable.report(outputfileInit);
//read the traffic, then search the hash table.
FILE * fp_traffic =fopen(trafficfile,"r");
if (NULL == fp_traffic) //If FilePtr is NULL
{
fprintf(stderr , "fibfile %s open failed!\n", trafficfile);
return false;
}
printf("\nstart traffic query...\n");
char key[KEYLENGTH];
memset(key , 0 , sizeof(key));
int readlines=0;
int val=0;
while(!feof(fp_traffic))
{
fscanf(fp_traffic, "%s", key);
readlines++;
aHashtable.search((const unsigned char *)key, val);
if (readlines%1000==0)
{
printf("\r%.2f%%", 100.0*readlines/fiblen/10);
}
}
printf("val=%d\n",val);
printf("\nafter the traffic query...\n");
aHashtable.report(outputfileSearch);
}
catch(char *s)
{
fprintf(stderr, "error: %s\n",s);
}
printf("Congrats! Traffic query is completed!\n");
return true;
}
bool dleftExperiments(char * fibfile, char * trafficfile, char * updatefile, float ht_times)
{
try
{
int fiblen=getFIBSize(fibfile);
dleftHash aHashtable;
cout << "successful initial" <<endl;
printf("\n\nStart to process %s...\n", fibfile);
char outputfileInit[100];
memset(outputfileInit, 0, sizeof(outputfileInit));
sprintf(outputfileInit, "%s.dleft.init", fibfile);
char outputfileSearch[100];
memset(outputfileSearch, 0, sizeof(outputfileSearch));
sprintf(outputfileSearch, "%s.dleft.search", fibfile);
aHashtable.initialFromFile(fibfile, ht_times);
//test the correctness of initialFromFile
#ifdef _DEBUG
if(aHashtable.test(fibfile) == true)
{
printf("Congratulation! pass test!\n");
}
else
{
printf("not pass test");
}
#endif
aHashtable.report(outputfileInit);
//read the traffic, then search the hash table.
FILE * fp_traffic =fopen(trafficfile,"r");
if (NULL == fp_traffic) //If FilePtr is NULL
{
fprintf(stderr , "fibfile %s open failed!\n", trafficfile);
return false;
}
printf("\nstart traffic query...\n");
char key[KEYLENGTH];
memset(key , 0 , sizeof(key));
int readlines=0;
int val=0;
while(!feof(fp_traffic))
{
fscanf(fp_traffic, "%s", key);
readlines++;
aHashtable.search((const unsigned char *)key, val);
if (readlines%1000==0)
{
printf("\r%.2f%%", 100.0*readlines/fiblen/10);
}
}
printf("val=%d\n",val);
printf("\nafter the traffic query...\n");
aHashtable.report(outputfileSearch);
}
catch(char *s)
{
fprintf(stderr, "error: %s\n",s);
}
printf("Congrats! Traffic query is completed!\n");
return true;
}
int RectExperiments(char * fibfile, char * trafficfile, char * updatefile, float ht_times, int blind_kick_num)
{
try
{
//473611, (a+a+7*5000)*4=
int fiblen=getFIBSize(fibfile);
RTBHash aHashtable;
aHashtable.blind_kick_num=blind_kick_num;
cout << "successful initial" <<endl;
printf("\n\nStart to process %s...\n", fibfile);
char * fibfileShort=&(fibfile[4]);
char outputfileInit[100];
memset(outputfileInit, 0, sizeof(outputfileInit));
sprintf(outputfileInit, "%s.rect%d_%.2f.init", fibfileShort, aHashtable.blind_kick_num, ht_times);
char outputfileSearch[100];
memset(outputfileSearch, 0, sizeof(outputfileSearch));
sprintf(outputfileSearch, "%s.rect%d_%.2f.search", fibfileShort, aHashtable.blind_kick_num, ht_times);
aHashtable.initialFromFile(fibfile, ht_times);
printf("\nafter %d Blind kick\n", aHashtable.blind_kick_num);
aHashtable.report(outputfileInit);
return 1;
//read the traffic, then search the hash table.
FILE * fp_traffic =fopen(trafficfile,"r");
if (NULL == fp_traffic) //If FilePtr is NULL
{
fprintf(stderr , "fibfile %s open failed!\n", trafficfile);
return -1;
}
//test the correctness of initialFromFile
#ifdef _DEBUG
if(aHashtable.test(fibfile) == true)
{
printf("Congratulation! pass test!\n");
}
else
{
printf("not pass test");
}
#endif
printf("\nstart traffic query...\n");
char key[KEYLENGTH];
memset(key , 0 , sizeof(key));
int readlines=0;
int val=0;
while(!feof(fp_traffic))
{
fscanf(fp_traffic, "%s", key);
readlines++;
aHashtable.search(key, val);
if (readlines%1000==0)
{
printf("\r%.2f%%", 100.0*readlines/fiblen/10);
}
}
printf("val=%d\n",val);
printf("\nafter the traffic query...\n");
aHashtable.report(outputfileSearch);
}
catch(char *s)
{
fprintf(stderr, "error: %s\n",s);
}
printf("Congrats! Traffic query is completed!\n");
return 1;