- 注册时间
- 2009-7-21
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 4489
- 在线时间
- 小时
|
楼主 |
发表于 2010-3-2 21:34:47
|
显示全部楼层
-
- /* compiled by cl of vc2003*/
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <map>
- #include <iostream>
- #define add_key {if((key_recn.find(key))== key_recn.end())key_recn[key]=c++;}
- #define addkey {if((key_recn2.find(key))== key_recn2.end())key_recn2[key]=c++;}
- #define addskey {if((iter=key_recn.find(key))== key_recn.end()){key_recn[key]=c++;int recn=c;k[recn]=key;C[recn]++;v2[recn]+=v1[i];}\
- else{int recn=iter->second;k[recn]=key;C[recn]++;v2[recn]+=v1[i];}}
- /*int recn=key_recn[(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i]];
- k[recn]=(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i];
- C[recn]++;
- v2[recn]=v2[recn]+v1[i];*/
-
- #define adkey(i) {if((key_recn2[i].find(key))== key_recn2[i].end())key_recn2[i][key]=c++;}
- #define sumkey(i) {f[i]++;int recn=key_recn2[i][key]-c_2;k2[recn]=key;C2[recn]+=C2[(iter->second)-c_2];v3[recn]+=v3[(iter->second)-c_2];}
- #define adsmkey(j) {if((iter=key_recn2[j].find(key))== key_recn2[j].end()){key_recn2[j][key]=c++;f[j]++;int recn=c-c_2;k2[recn]=key;C2[recn]+=C[i];v3[recn]+=v2[i];}\
- else{f[j]++;int recn=/*key_recn2[j][key]-c_2*/iter->second-c_2;k2[recn]=key;C2[recn]+=C[i];v3[recn]+=v2[i];}}
-
- #define __int64 long long
- using namespace std;
- struct ltstr
- {
- bool operator()(const char* s1, const char* s2) const
- {
- return strcmp(s1, s2) < 0;
- }
- };
- struct ltint
- {
- bool operator()(const int s1, const int s2) const
- {
- return (s1<s2) ;
- }
- };
- int main()
- {
- int dsize=0;
- int s[3][3]={ {4,5,67},{9,109,19},{9,97,119}};
- //printf("%d,%d",t[0][1],t[1][2]);
- //return 0;
- for(int it=1;it<2;it++)
- for(int r=2;r<3;r++)
- {
- long t=clock();
- long t1=t;
- printf("%d,%d,%d,114,%d\n",s[r][0],s[r][1],s[r][2],s[r][0]*s[r][1]*s[r][2]*114);
- char* c1=(char*)malloc(1E6L);
- char* c2=(char*)malloc(1E6L);
- char* c3=(char*)malloc(1E6L);
- char* c4=(char*)malloc(1E6L);
- int* v1=(int* )malloc(4E6L);
-
- printf("申请源表内存%dms\n",clock()-t);
- t=clock();
-
- __int64* v2;//store sum(v1);
- //FILE *fp=fopen("in.txt","wb");
- //FILE *fp=fopen("in.txt","rb");
- for (int i=0;i<1E6L;i++)
- {
- int j=i+1;
- c1[i]=j%s[r][0];
- c2[i]=j%s[r][1];
- c3[i]=j%s[r][2];
- c4[i]=(j%13?j%113:127);
- v1[i]=j;
- //fscanf(fp,"%d,%d,%d,%d,%d\n",&c1[i],&c2[i],&c3[i],&c4[i],&v1[i]);
- //fprintf(fp,"%d,%d,%d,%d,%d\n",c1[i],c2[i],c3[i],c4[i],v1[i]);
-
- }
- //fclose(fp);
- //return 1;
- map<const int, int, ltint> key_recn;
- map<const int, int, ltint> key_recn2[16];
- map<const int, int,ltint>::iterator iter;
-
- int c=1E6L;
- printf("填充源表数据%dms,recn=%d,每毫秒%d行\n",clock()-t,c,(long)1E6/(clock()-t));
- t=clock();
-
- int *C=(int*)malloc(c*4);//store count(c1)
- int *k=(int*)malloc(c*4);//store key
-
- v2=(__int64*)malloc(c*8);
-
- memset(C,0,c*4); //need?
- memset(v2,0,c*8);
- printf("申请一层内存%dms\n",clock()-t);
- t=clock();
- c=0;
- for (int i=0;i<1E6L;i++)
- {
- int key=(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i];
- //printf("key=%d\n",key);
- addskey;
-
- }
-
- printf("新建一层节点%dms,recn=%d,每毫秒读%d行,每毫秒写%d节点\n",clock()-t,c,(long)1E6/(clock()-t),c/(clock()-t));
- t=clock();
-
- /*
- for (int i=0;i<1E6L;i++)
- {
- int recn=key_recn[(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i]];
- k[recn]=(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i];
- C[recn]++;
- v2[recn]=v2[recn]+v1[i];
-
- }
- */
- //printf("写入一层数据%dms,recn=%d,每毫秒读%d行,每毫秒写%d行\n",clock()-t,c,(long)1E6/(clock()-t),c/(clock()-t));
- t=clock();
- int c_2=c;
- int o[15]={8,4,2,1,9,5,3,6,10,12,13,14,11,7,15};
- int mask[15]={
- 0x00FFFFFF,
- 0xFF00FFFF,
- 0xFFFF00FF,
- 0xFFFFFF00,
- 0x00FFFF00,
- 0xFF00FF00,
- 0xFFFF0000,
- 0xFF0000FF,
- 0x00FF00FF,
- 0x0000FFFF,
- 0x0000FF00,
- 0x000000FF,
- 0x00FF0000,
- 0xFF000000,
- 0x00000000};
-
- int null[15]={
- ((0x80+15)<<24),
- ((0x40)<<24)+(127<<16),
- ((0x20)<<24)+(127<<8),
- ((0x10)<<24)+(127),
- ((0x90+15)<<24)+(127),
- ((0x50)<<24)+(127<<16)+(127),
- ((0x30)<<24)+(127<<8)+(127),
- ((0x60)<<24)+(127<<16)+(127<<8),
- ((0xA0+15)<<24)+(127<<8),
- ((0xC0+15)<<24)+(127<<16),
- ((0xD0+15)<<24)+(127<<16)+(127),
- ((0xE0+15)<<24)+(127<<16)+(127<<8),
- ((0xB0+15)<<24)+(127<<8)+(127),
- ((0x70)<<24)+(127<<16)+(127<<8)+(127),
- ((0xF0+15)<<24)+(127<<16)+(127<<8)+(127)
- };
-
- dsize=c_2;
- int *C2=(int*)malloc((c_2)*4);//store count(c1)
- int *k2=(int*)malloc((c_2)*4);//store key
- __int64* v3=(__int64*)malloc((c_2)*8);
-
- memset(C2,0,(c_2)*4); //need?
- memset(v3,0,(c_2)*8);
- printf("申请后面内存%dms,%d\n",clock()-t,c_2);
- t=clock();
- //goto f;
- int y=0;
- int f[16];
- memset(f,0,16*4);
- for (int i=0;i<c_2;i++)
- {
- if(dsize<c-c_2+4)
- {
- dsize+=dsize;
- C2=(int*)realloc(C2,(dsize)*4);//store count(c1)
- k2=(int*)realloc(k2,(dsize)*4);//store key
- v3=(__int64*)realloc(v3,(dsize)*8);
-
- //memset(C2,0,(c_2)*4); //need?
- //memset(v3,0,(c_2)*8);
- }
- int key=(k[i]&0xFFFFFF)+((0x80+15)<<24);//set c1 null ,gid=8
- adsmkey(8);
-
- key=(k[i]&0xFF00FFFF)+((0x40)<<24)+(127<<16);//set c2 null,gid=4
- adsmkey(4);
-
- key=(k[i]&0xFFFF00FF)+((0x20)<<24)+(127<<8);//set c3 null,gid=2
- adsmkey(2);
-
- key=(k[i]&0xFFFFFF00)+((0x10)<<24)+(127);//set c4 null,gid=1
- adsmkey(1);
-
- /*
- for(int j=0;j<4;j++)
- {
- //int key=(k[i]&mask[j])+null[j];
- //if(key_recn2[o[j]].find(key)!= key_recn2[o[j]].end())
- {f[o[j]]++;
- int recn=key_recn2[o[j]][(k[i]&mask[j])+null[j]]-c_2;
- k2[recn]=(k[i]&mask[j])+null[j];
- C2[recn]+=C[i];
- v3[recn]+=v2[i];
-
- y=recn;
- }
-
- }
-
- key=(k[i]&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
- adkey(9);
-
- key=(k[i]&0xFF00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
- adkey(5);
-
- key=(k[i]&0xFFFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
- adkey(3);
-
- key=(k[i]&0xFF0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
- adkey(6);
-
- key=(k[i]&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
- adkey(10);
-
- key=(k[i]&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
- adkey(12);
-
- key=(k[i]&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
- adkey(13);
-
- key=(k[i]&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
- adkey(14);
-
- key=(k[i]&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
- adkey(11);
-
- key=(k[i]&0xFF000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
- adkey(7);
-
- key=((0xF0+15)<<24)+(127<<16)+(127<<8)+(127);//set c1,c2,c3,c4 null,gid=15
- adkey(15);
- */
- }
-
-
- //map<const int, int,ltint>::iterator iter;
- switch(it)
- {
- case 1:
- for(int i=1;i<7;i++)
- {
- if (i==1)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0x0FFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
- adkey(3);
-
- key=((iter->first)&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
- adkey(9);
-
- key=((iter->first)&0x0F00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
- adkey(5);
-
- }
- if(i==2)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
- adkey(10);
- }
- if(i==4)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0x0F0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
- adkey(6);
-
-
- key=((iter->first)&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
- adkey(12);
- }
- if(i==3)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
- adkey(11);
-
- key=((iter->first)&0x0F000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
- adkey(7);
- }
- if(i==5)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
- adkey(13);
- }
- if(i==6)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
- adkey(14);
- }
- }
- break;
- case 2:
- for(int i=1;i<7;i++)
- {
- if (i==1)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
-
- }
- if(i==2)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0x0FFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
- adkey(3);
-
- key=((iter->first)&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
- adkey(9);
-
- key=((iter->first)&0x0F00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
- adkey(5);
-
- key=((iter->first)&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
- adkey(10);
- }
- if(i==4)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0x0F0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
- adkey(6);
-
-
- key=((iter->first)&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
- adkey(12);
- }
- if(i==3)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
- adkey(11);
-
- key=((iter->first)&0x0F000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
- adkey(7);
- }
- if(i==5)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
- adkey(13);
- }
- if(i==6)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
- adkey(14);
- }
- }
- break;
- default:break;
- }
- int key=((0xF0+15)<<24)+(127<<16)+(127<<8)+(127);//set c1,c2,c3,c4 null,gid=15
- adkey(15);
-
- printf("新建后面节点%dms,recn=%d,每毫秒读%d行key,每毫秒写%d节点\n",clock()-t,c,c_2/(clock()-t),(c-c_2)/(clock()-t));
- for(int i=0;i<16;i++)
- {
- printf("%d,first=%0X,renc=%d\n",i,key_recn2[i].begin()->first,key_recn2[i][key_recn2[i].begin()->first]);
- }
- t=clock();
-
- /*
- for (int i=0;i<c_2;i++)
- {
- for(int j=0;j<4;j++)
- {
- //int key=(k[i]&mask[j])+null[j];
- //if(key_recn2[o[j]].find(key)!= key_recn2[o[j]].end())
- {f[o[j]]++;
- int recn=key_recn2[o[j]][(k[i]&mask[j])+null[j]]-c_2;
- k2[recn]=(k[i]&mask[j])+null[j];
- C2[recn]+=C[i];
- v3[recn]+=v2[i];
-
- y=recn;
- }
- }
- }
- */
- for(int i=1;i<7;i++)
- {
- if (i==1)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0x0FFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
- /* {f[3]++;
- int recn=key_recn2[3][key]-c_2;
- k2[recn]=key;
- C2[recn]+=C2[(iter->second)-c_2];
- v3[recn]+=v3[(iter->second)-c_2];
- }*/
- sumkey(3);
-
- key=((iter->first)&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
- sumkey(9);
-
- key=((iter->first)&0x0F00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
- sumkey(5);
-
- }
- if(i==2)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
- sumkey(10);
- }
-
- if(i==4)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0x0F0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
- sumkey(6);
-
-
- key=((iter->first)&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
- sumkey(12);
- }
- if(i==3)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
- sumkey(11);
-
- key=((iter->first)&0x0F000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
- sumkey(7);
-
- key=((0xF0+15)<<24)+(127<<16)+(127<<8)+(127);//set c1,c2,c3,c4 null,gid=15
- sumkey(15);
- }
- if(i==5)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
- sumkey(13);
- }
- if(i==6)
- for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
- {
- int key=((iter->first)&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
- sumkey(14);
- }
- }
-
- printf("汇总后面节点%dms,recn=%d,每毫秒读%d行,每毫秒写%d行\n",clock()-t,c,c_2/(clock()-t),(c-c_2)/(clock()-t));
- t=clock();
- /*
- printf("%fms,recn=%d,c1=%d,c2=%d,c3=%d,c4=%d,count=%d,sum=%I64d\n",(float)(clock()-t)/CLOCKS_PER_SEC ,c,
- (k2[y]>>24),((k2[y]>>16)&255),((k2[y]>>8)&255),(k2[y]&255),C2[y],v3[y]);
-
-
- FILE *fp=fopen("out.txt","wb");
-
- //fp=fopen("out.txt","wb");
- fprintf(fp,"gid,c1,c2,c3,c4,count,sum\n");
- for (int i=0;i<c_2;i++)
- {
- y=i;
- fprintf(fp,"%d,%d,%d,%d,%d,%d,%I64d\n",
- 0,(k[y]>>24),((k[y]>>16)&255),((k[y]>>8)&255),(k[y]&255),C[y],v2[y]);
-
- }
-
- for (int i=0;i<c-c_2;i++)
- {
- y=i;
- fprintf(fp,"%d,%d,%d,%d,%d,%d,%I64d\n",
- (16+((k2[y]>>24)>>4))&15,(k2[y]>>24)&15,((k2[y]>>16)&255),((k2[y]>>8)&255),(k2[y]&255),C2[y],v3[y]);
-
- }
- fclose(fp);
- printf("保存到文件%dms,recn=%d,每毫秒写%d行\n",clock()-t,c,c/(clock()-t));
- t=clock();
- */
- f:
- free(c1);
- free(c2);
- free(c3);
- free(c4);
- free(v1);
- free(v2);
- free(C);
- free(k);
- free(C2);
- free(k2);
- free(v3);
- printf("释放所有动态内存%dms,%d\n",clock()-t,c);
- for(int i=0;i<16;i++)
- printf("%d,%d\n",i,f[i]);
-
- printf("总时间%dms,%d\n",clock()-t1,c);
-
-
- }
- return 0;
- }
复制代码 |
|