找回密码
 欢迎注册
查看: 11061|回复: 9

[擂台] 用过程语言实现group by cube的代码

[复制链接]
发表于 2010-2-25 10:10:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?欢迎注册

×
有100万行数据,要求对c1,c2,c3,c4作各种组合的分组汇总,计算行数和v1的合计,即
  1. 0( c1, c2, c3, c4);
  2. 1( c1, c2, c3,NULL);
  3. 2( c1, c2,NULL, c4);
  4. 3( c1, c2,NULL,NULL);
  5. 4( c1,NULL, c3, c4);
  6. 5( c1,NULL, c3,NULL);
  7. 6( c1,NULL,NULL, c4);
  8. 7( c1,NULL,NULL,NULL);
  9. 8(NULL, c2, c3, c4);
  10. 9(NULL, c2, c3,NULL);
  11. 10(NULL, c2,NULL, c4);
  12. 11(NULL, c2,NULL,NULL);
  13. 12(NULL,NULL, c3, c4);
  14. 13(NULL,NULL, c3,NULL);
  15. 14(NULL,NULL,NULL, c4);
  16. 15(NULL,NULL,NULL,NULL);
  17. /*源数据*/
  18. int main()
  19. {
  20. char* c1=(char*)malloc(1E6L);
  21. char* c2=(char*)malloc(1E6L);
  22. char* c3=(char*)malloc(1E6L);
  23. char* c4=(char*)malloc(1E6L);
  24. int* v1=(int* )malloc(4E6L);
  25. __int64* v2;//store sum(v1);
  26. long t=clock();
  27. for (int i=0;i<1E6L;i++)
  28. {
  29. int j=i+1;
  30. c1[i]=j%4;
  31. c2[i]=j%5;
  32. c3[i]=j%67;
  33. c4[i]=(j%13?j%113:127); //用127模拟NULL
  34. v1[i]=j;
  35. }
复制代码
用尽量少的空间和时间
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2010-2-25 16:44:11 | 显示全部楼层
这种计算空间占用不大,时间很难再优化了(先把相同的行数统计出来,再汇总)
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2010-2-25 20:38:16 | 显示全部楼层
很多地方没有优化,应该还能提高100毫秒
  1. lenovo t61
  2. 453ms,recn=152760
  3. 547ms,recn=234600,c1=-1,c2=127,c3=127,c4=127,count=1000000,sum=500000500000
  4. hp dl360
  5. 483ms,recn=152760
  6. 577ms,recn=234600,c1=-1,c2=127,c3=127,c4=127,count=1000000,sum=500000500000
  7. /* compiled by cl of vc2003*/
  8. #include <time.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <map>
  12. #include <iostream>
  13. #define add_key {if((key_recn.find(key))== key_recn.end())key_recn[key]=c++;}
  14. #define addkey {if((key_recn2.find(key))== key_recn2.end())key_recn2[key]=c++;}
  15. using namespace std;
  16. struct ltstr
  17. {
  18. bool operator()(const char* s1, const char* s2) const
  19. {
  20. return strcmp(s1, s2) < 0;
  21. }
  22. };
  23. struct ltint
  24. {
  25. bool operator()(const int s1, const int s2) const
  26. {
  27. return (s1<s2) ;
  28. }
  29. };
  30. int main()
  31. {
  32. char* c1=(char*)malloc(1E6L);
  33. char* c2=(char*)malloc(1E6L);
  34. char* c3=(char*)malloc(1E6L);
  35. char* c4=(char*)malloc(1E6L);
  36. int* v1=(int* )malloc(4E6L);
  37. __int64* v2;//store sum(v1);
  38. long t=clock();
  39. for (int i=0;i<1E6L;i++)
  40. {
  41. int j=i+1;
  42. c1[i]=j%4;
  43. c2[i]=j%5;
  44. c3[i]=j%67;
  45. c4[i]=(j%13?j%113:127);
  46. v1[i]=j;
  47. }
  48. map<const int, int, ltint> key_recn;
  49. map<const int, int, ltint> key_recn2;
  50. int c=0;
  51. for (int i=0;i<1E6L;i++)
  52. {
  53. int key=(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i];
  54. //printf("key=%d\n",key);
  55. add_key;
  56. }
  57. int *C=(int*)malloc(c*4);//store count(c1)
  58. int *k=(int*)malloc(c*4);//store key
  59. v2=(__int64*)malloc(c*8);
  60. memset(C,0,c*4); //need?
  61. memset(v2,0,c*8);
  62. for (int i=0;i<1E6L;i++)
  63. {
  64. int recn=key_recn[(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i]];
  65. k[recn]=(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i];
  66. C[recn]++;
  67. v2[recn]=v2[recn]+v1[i];
  68. }
  69. printf("%dms,recn=%d\n",clock()-t,c);
  70. t=clock();
  71. int c_2=c;
  72. for (int i=0;i<c_2;i++)
  73. {
  74. int key=(k[i]&0xFFFFFF)+((0x80+15)<<24);//set c1 null ,gid=8
  75. addkey;
  76. key=(k[i]&0xFF00FFFF)+((0x40)<<24)+(127<<16);//set c2 null,gid=4
  77. addkey;
  78. key=(k[i]&0xFFFF00FF)+((0x20)<<24)+(127<<8);//set c3 null,gid=2
  79. addkey;
  80. key=(k[i]&0xFFFFFF00)+((0x10)<<24)+(127);//set c4 null,gid=1
  81. addkey;
  82. key=(k[i]&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
  83. addkey;
  84. key=(k[i]&0xFF00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
  85. addkey;
  86. key=(k[i]&0xFFFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
  87. addkey;
  88. key=(k[i]&0xFF0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
  89. addkey;
  90. key=(k[i]&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
  91. addkey;
  92. key=(k[i]&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
  93. addkey;
  94. key=(k[i]&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
  95. addkey;
  96. key=(k[i]&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
  97. addkey;
  98. key=(k[i]&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
  99. addkey;
  100. key=(k[i]&0xFF000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
  101. addkey;
  102. key=((0xF0+15)<<24)+(127<<16)+(127<<8)+(127);//set c1,c2,c3,c4 null,gid=15
  103. addkey;
  104. }
  105. int mask[15]={
  106. 0x00FFFFFF,
  107. 0xFF00FFFF,
  108. 0xFFFF00FF,
  109. 0xFFFFFF00,
  110. 0x00FFFF00,
  111. 0xFF00FF00,
  112. 0xFFFF0000,
  113. 0xFF0000FF,
  114. 0x00FF00FF,
  115. 0x0000FFFF,
  116. 0x0000FF00,
  117. 0x000000FF,
  118. 0x00FF0000,
  119. 0xFF000000,
  120. 0x00000000};
  121. int null[15]={
  122. ((0x80+15)<<24),
  123. ((0x40)<<24)+(127<<16),
  124. ((0x20)<<24)+(127<<8),
  125. ((0x10)<<24)+(127),
  126. ((0x90+15)<<24)+(127),
  127. ((0x50)<<24)+(127<<16)+(127),
  128. ((0x30)<<24)+(127<<8)+(127),
  129. ((0x60)<<24)+(127<<16)+(127<<8),
  130. ((0xA0+15)<<24)+(127<<8),
  131. ((0xC0+15)<<24)+(127<<16),
  132. ((0xD0+15)<<24)+(127<<16)+(127),
  133. ((0xE0+15)<<24)+(127<<16)+(127<<8),
  134. ((0xB0+15)<<24)+(127<<8)+(127),
  135. ((0x70)<<24)+(127<<16)+(127<<8)+(127),
  136. ((0xF0+15)<<24)+(127<<16)+(127<<8)+(127)
  137. };
  138. int *C2=(int*)malloc((c-c_2)*4);//store count(c1)
  139. int *k2=(int*)malloc((c-c_2)*4);//store key
  140. __int64* v3=(__int64*)malloc((c-c_2)*8);
  141. memset(C2,0,(c-c_2)*4); //need?
  142. memset(v3,0,(c-c_2)*8);
  143. int y=0;
  144. for (int i=0;i<c_2;i++)
  145. {
  146. for(int j=0;j<15;j++)
  147. {
  148. int recn=key_recn2[(k[i]&mask[j])+null[j]]-c_2;
  149. k2[recn]=(k[i]&mask[j])+null[j];
  150. C2[recn]+=C[i];
  151. v3[recn]=v3[recn]+v2[i];
  152. y=recn;
  153. }
  154. }
  155. printf("%dms,recn=%d,c1=%d,c2=%d,c3=%d,c4=%d,count=%d,sum=%I64d",clock()-t,c,
  156. (k2[y]>>24),((k2[y]>>16)&255),((k2[y]>>8)&255),(k2[y]&255),C2[y],v3[y]);
  157. free(c1);
  158. free(c2);
  159. free(c3);
  160. free(c4);
  161. free(v1);
  162. free(v2);
  163. free(C);
  164. free(k);
  165. free(C2);
  166. free(k2);
  167. free(v3);
  168. return 0;
  169. }
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2010-3-1 01:53:19 | 显示全部楼层
  1. /* compiled by cl of vc2003*/
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <map>
  6. #include <iostream>
  7. #define add_key {if((key_recn.find(key))== key_recn.end())key_recn[key]=c++;}
  8. #define addkey {if((key_recn2.find(key))== key_recn2.end())key_recn2[key]=c++;}
  9. #define adkey(i) {if((key_recn2[i].find(key))== key_recn2[i].end())key_recn2[i][key]=c++;}
  10. #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];}
  11. #define __int64 long long
  12. using namespace std;
  13. struct ltstr
  14. {
  15. bool operator()(const char* s1, const char* s2) const
  16. {
  17. return strcmp(s1, s2) < 0;
  18. }
  19. };
  20. struct ltint
  21. {
  22. bool operator()(const int s1, const int s2) const
  23. {
  24. return (s1<s2) ;
  25. }
  26. };
  27. int main()
  28. {
  29. int s[3][3]={ {4,5,67},{9,19,109},{9,97,119}};
  30. //printf("%d,%d",t[0][1],t[1][2]);
  31. //return 0;
  32. for(int r=2;r<3;r++)
  33. {
  34. long t=clock();
  35. 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);
  36. char* c1=(char*)malloc(1E6L);
  37. char* c2=(char*)malloc(1E6L);
  38. char* c3=(char*)malloc(1E6L);
  39. char* c4=(char*)malloc(1E6L);
  40. int* v1=(int* )malloc(4E6L);
  41. printf("申请源表内存%dms\n",clock()-t);
  42. t=clock();
  43. __int64* v2;//store sum(v1);
  44. //FILE *fp=fopen("in.txt","wb");
  45. //FILE *fp=fopen("in.txt","rb");
  46. for (int i=0;i<1E6L;i++)
  47. {
  48. int j=i+1;
  49. c1[i]=j%s[r][0];
  50. c2[i]=j%s[r][1];
  51. c3[i]=j%s[r][2];
  52. c4[i]=(j%13?j%113:127);
  53. v1[i]=j;
  54. //fscanf(fp,"%d,%d,%d,%d,%d\n",&c1[i],&c2[i],&c3[i],&c4[i],&v1[i]);
  55. //fprintf(fp,"%d,%d,%d,%d,%d\n",c1[i],c2[i],c3[i],c4[i],v1[i]);
  56. }
  57. //fclose(fp);
  58. //return 1;
  59. map<const int, int, ltint> key_recn;
  60. map<const int, int, ltint> key_recn2[16];
  61. int c=0;
  62. printf("填充源表数据%dms,recn=%d,每毫秒%d行\n",clock()-t,c,(long)1E6/(clock()-t));
  63. t=clock();
  64. for (int i=0;i<1E6L;i++)
  65. {
  66. int key=(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i];
  67. //printf("key=%d\n",key);
  68. add_key;
  69. }
  70. printf("新建一层节点%dms,recn=%d,每毫秒读%d行,每毫秒写%d节点\n",clock()-t,c,(long)1E6/(clock()-t),c/(clock()-t));
  71. t=clock();
  72. int *C=(int*)malloc(c*4);//store count(c1)
  73. int *k=(int*)malloc(c*4);//store key
  74. v2=(__int64*)malloc(c*8);
  75. memset(C,0,c*4); //need?
  76. memset(v2,0,c*8);
  77. printf("申请一层内存%dms\n",clock()-t);
  78. t=clock();
  79. for (int i=0;i<1E6L;i++)
  80. {
  81. int recn=key_recn[(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i]];
  82. k[recn]=(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i];
  83. C[recn]++;
  84. v2[recn]=v2[recn]+v1[i];
  85. }
  86. printf("写入一层数据%dms,recn=%d,每毫秒读%d行,每毫秒写%d行\n",clock()-t,c,(long)1E6/(clock()-t),c/(clock()-t));
  87. t=clock();
  88. int c_2=c;
  89. for (int i=0;i<c_2;i++)
  90. {
  91. int key=(k[i]&0xFFFFFF)+((0x80+15)<<24);//set c1 null ,gid=8
  92. adkey(8);
  93. key=(k[i]&0xFF00FFFF)+((0x40)<<24)+(127<<16);//set c2 null,gid=4
  94. adkey(4);
  95. key=(k[i]&0xFFFF00FF)+((0x20)<<24)+(127<<8);//set c3 null,gid=2
  96. adkey(2);
  97. key=(k[i]&0xFFFFFF00)+((0x10)<<24)+(127);//set c4 null,gid=1
  98. adkey(1);
  99. /*
  100. key=(k[i]&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
  101. adkey(9);
  102. key=(k[i]&0xFF00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
  103. adkey(5);
  104. key=(k[i]&0xFFFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
  105. adkey(3);
  106. key=(k[i]&0xFF0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
  107. adkey(6);
  108. key=(k[i]&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
  109. adkey(10);
  110. key=(k[i]&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
  111. adkey(12);
  112. key=(k[i]&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
  113. adkey(13);
  114. key=(k[i]&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
  115. adkey(14);
  116. key=(k[i]&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
  117. adkey(11);
  118. key=(k[i]&0xFF000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
  119. adkey(7);
  120. key=((0xF0+15)<<24)+(127<<16)+(127<<8)+(127);//set c1,c2,c3,c4 null,gid=15
  121. adkey(15);
  122. */
  123. }
  124. map<const int, int,ltint>::iterator iter;
  125. for(int i=1;i<7;i++)
  126. {
  127. if (i==1)
  128. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  129. {
  130. int key=((iter->first)&0x0FFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
  131. adkey(3);
  132. key=((iter->first)&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
  133. adkey(9);
  134. key=((iter->first)&0x0F00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
  135. adkey(5);
  136. }
  137. if(i==2)
  138. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  139. {
  140. int key=((iter->first)&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
  141. adkey(10);
  142. }
  143. if(i==4)
  144. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  145. {
  146. int key=((iter->first)&0x0F0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
  147. adkey(6);
  148. key=((iter->first)&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
  149. adkey(12);
  150. }
  151. if(i==3)
  152. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  153. {
  154. int key=((iter->first)&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
  155. adkey(11);
  156. key=((iter->first)&0x0F000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
  157. adkey(7);
  158. }
  159. if(i==5)
  160. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  161. {
  162. int key=((iter->first)&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
  163. adkey(13);
  164. }
  165. if(i==6)
  166. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  167. {
  168. int key=((iter->first)&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
  169. adkey(14);
  170. }
  171. }
  172. int key=((0xF0+15)<<24)+(127<<16)+(127<<8)+(127);//set c1,c2,c3,c4 null,gid=15
  173. adkey(15);
  174. printf("新建后面节点%dms,recn=%d,每毫秒读%d行key,每毫秒写%d节点\n",clock()-t,c,c_2/(clock()-t),(c-c_2)/(clock()-t));
  175. for(int i=0;i<16;i++)
  176. {
  177. printf("%d,first=%0X,renc=%d\n",i,key_recn2[i].begin()->first,key_recn2[i][key_recn2[i].begin()->first]);
  178. }
  179. t=clock();
  180. int o[15]={8,4,2,1,9,5,3,6,10,12,13,14,11,7,15};
  181. int mask[15]={
  182. 0x00FFFFFF,
  183. 0xFF00FFFF,
  184. 0xFFFF00FF,
  185. 0xFFFFFF00,
  186. 0x00FFFF00,
  187. 0xFF00FF00,
  188. 0xFFFF0000,
  189. 0xFF0000FF,
  190. 0x00FF00FF,
  191. 0x0000FFFF,
  192. 0x0000FF00,
  193. 0x000000FF,
  194. 0x00FF0000,
  195. 0xFF000000,
  196. 0x00000000};
  197. int null[15]={
  198. ((0x80+15)<<24),
  199. ((0x40)<<24)+(127<<16),
  200. ((0x20)<<24)+(127<<8),
  201. ((0x10)<<24)+(127),
  202. ((0x90+15)<<24)+(127),
  203. ((0x50)<<24)+(127<<16)+(127),
  204. ((0x30)<<24)+(127<<8)+(127),
  205. ((0x60)<<24)+(127<<16)+(127<<8),
  206. ((0xA0+15)<<24)+(127<<8),
  207. ((0xC0+15)<<24)+(127<<16),
  208. ((0xD0+15)<<24)+(127<<16)+(127),
  209. ((0xE0+15)<<24)+(127<<16)+(127<<8),
  210. ((0xB0+15)<<24)+(127<<8)+(127),
  211. ((0x70)<<24)+(127<<16)+(127<<8)+(127),
  212. ((0xF0+15)<<24)+(127<<16)+(127<<8)+(127)
  213. };
  214. int *C2=(int*)malloc((c-c_2)*4);//store count(c1)
  215. int *k2=(int*)malloc((c-c_2)*4);//store key
  216. __int64* v3=(__int64*)malloc((c-c_2)*8);
  217. memset(C2,0,(c-c_2)*4); //need?
  218. memset(v3,0,(c-c_2)*8);
  219. printf("申请后面内存%dms,%d\n",clock()-t,c);
  220. t=clock();
  221. //goto f;
  222. int y=0;
  223. int f[16];
  224. memset(f,0,15*4);
  225. for (int i=0;i<c_2;i++)
  226. {
  227. for(int j=0;j<4;j++)
  228. {
  229. //int key=(k[i]&mask[j])+null[j];
  230. //if(key_recn2[o[j]].find(key)!= key_recn2[o[j]].end())
  231. {f[o[j]]++;
  232. int recn=key_recn2[o[j]][(k[i]&mask[j])+null[j]]-c_2;
  233. k2[recn]=(k[i]&mask[j])+null[j];
  234. C2[recn]+=C[i];
  235. v3[recn]+=v2[i];
  236. y=recn;
  237. }
  238. }
  239. }
  240. for(int i=1;i<7;i++)
  241. {
  242. if (i==1)
  243. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  244. {
  245. int key=((iter->first)&0x0FFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
  246. /* {f[3]++;
  247. int recn=key_recn2[3][key]-c_2;
  248. k2[recn]=key;
  249. C2[recn]+=C2[(iter->second)-c_2];
  250. v3[recn]+=v3[(iter->second)-c_2];
  251. }*/
  252. sumkey(3);
  253. key=((iter->first)&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
  254. sumkey(9);
  255. key=((iter->first)&0x0F00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
  256. sumkey(5);
  257. }
  258. if(i==2)
  259. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  260. {
  261. int key=((iter->first)&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
  262. sumkey(10);
  263. }
  264. if(i==4)
  265. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  266. {
  267. int key=((iter->first)&0x0F0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
  268. sumkey(6);
  269. key=((iter->first)&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
  270. sumkey(12);
  271. }
  272. if(i==3)
  273. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  274. {
  275. int key=((iter->first)&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
  276. sumkey(11);
  277. key=((iter->first)&0x0F000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
  278. sumkey(7);
  279. key=((0xF0+15)<<24)+(127<<16)+(127<<8)+(127);//set c1,c2,c3,c4 null,gid=15
  280. sumkey(15);
  281. }
  282. if(i==5)
  283. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  284. {
  285. int key=((iter->first)&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
  286. sumkey(13);
  287. }
  288. if(i==6)
  289. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  290. {
  291. int key=((iter->first)&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
  292. sumkey(14);
  293. }
  294. }
  295. printf("汇总后面节点%dms,recn=%d,每毫秒读%d行,每毫秒写%d行\n",clock()-t,c,c_2/(clock()-t),(c-c_2)/(clock()-t));
  296. t=clock();
  297. /*
  298. printf("%fms,recn=%d,c1=%d,c2=%d,c3=%d,c4=%d,count=%d,sum=%I64d\n",(float)(clock()-t)/CLOCKS_PER_SEC ,c,
  299. (k2[y]>>24),((k2[y]>>16)&255),((k2[y]>>8)&255),(k2[y]&255),C2[y],v3[y]);
  300. */
  301. FILE *fp=fopen("out.txt","wb");
  302. //fp=fopen("out.txt","wb");
  303. fprintf(fp,"gid,c1,c2,c3,c4,count,sum\n");
  304. for (int i=0;i<c_2;i++)
  305. {
  306. y=i;
  307. fprintf(fp,"%d,%d,%d,%d,%d,%d,%I64d\n",
  308. 0,(k[y]>>24),((k[y]>>16)&255),((k[y]>>8)&255),(k[y]&255),C[y],v2[y]);
  309. }
  310. for (int i=0;i<c-c_2;i++)
  311. {
  312. y=i;
  313. fprintf(fp,"%d,%d,%d,%d,%d,%d,%I64d\n",
  314. (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]);
  315. }
  316. fclose(fp);
  317. printf("保存到文件%dms,recn=%d,每毫秒写%d行\n",clock()-t,c,c/(clock()-t));
  318. t=clock();
  319. f:
  320. free(c1);
  321. free(c2);
  322. free(c3);
  323. free(c4);
  324. free(v1);
  325. free(v2);
  326. free(C);
  327. free(k);
  328. free(C2);
  329. free(k2);
  330. free(v3);
  331. printf("释放所有动态内存%dms,%d\n",clock()-t,c);
  332. for(int i=0;i<16;i++)
  333. printf("%d,%d\n",i,f[i]);
  334. }
  335. return 0;
  336. }
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2010-3-2 12:48:04 | 显示全部楼层
rollup的选择还是有讲究的
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2010-3-2 21:34:47 | 显示全部楼层
  1. /* compiled by cl of vc2003*/
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <map>
  6. #include <iostream>
  7. #define add_key {if((key_recn.find(key))== key_recn.end())key_recn[key]=c++;}
  8. #define addkey {if((key_recn2.find(key))== key_recn2.end())key_recn2[key]=c++;}
  9. #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];}\
  10. else{int recn=iter->second;k[recn]=key;C[recn]++;v2[recn]+=v1[i];}}
  11. /*int recn=key_recn[(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i]];
  12. k[recn]=(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i];
  13. C[recn]++;
  14. v2[recn]=v2[recn]+v1[i];*/
  15. #define adkey(i) {if((key_recn2[i].find(key))== key_recn2[i].end())key_recn2[i][key]=c++;}
  16. #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];}
  17. #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];}\
  18. 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];}}
  19. #define __int64 long long
  20. using namespace std;
  21. struct ltstr
  22. {
  23. bool operator()(const char* s1, const char* s2) const
  24. {
  25. return strcmp(s1, s2) < 0;
  26. }
  27. };
  28. struct ltint
  29. {
  30. bool operator()(const int s1, const int s2) const
  31. {
  32. return (s1<s2) ;
  33. }
  34. };
  35. int main()
  36. {
  37. int dsize=0;
  38. int s[3][3]={ {4,5,67},{9,109,19},{9,97,119}};
  39. //printf("%d,%d",t[0][1],t[1][2]);
  40. //return 0;
  41. for(int it=1;it<2;it++)
  42. for(int r=2;r<3;r++)
  43. {
  44. long t=clock();
  45. long t1=t;
  46. 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);
  47. char* c1=(char*)malloc(1E6L);
  48. char* c2=(char*)malloc(1E6L);
  49. char* c3=(char*)malloc(1E6L);
  50. char* c4=(char*)malloc(1E6L);
  51. int* v1=(int* )malloc(4E6L);
  52. printf("申请源表内存%dms\n",clock()-t);
  53. t=clock();
  54. __int64* v2;//store sum(v1);
  55. //FILE *fp=fopen("in.txt","wb");
  56. //FILE *fp=fopen("in.txt","rb");
  57. for (int i=0;i<1E6L;i++)
  58. {
  59. int j=i+1;
  60. c1[i]=j%s[r][0];
  61. c2[i]=j%s[r][1];
  62. c3[i]=j%s[r][2];
  63. c4[i]=(j%13?j%113:127);
  64. v1[i]=j;
  65. //fscanf(fp,"%d,%d,%d,%d,%d\n",&c1[i],&c2[i],&c3[i],&c4[i],&v1[i]);
  66. //fprintf(fp,"%d,%d,%d,%d,%d\n",c1[i],c2[i],c3[i],c4[i],v1[i]);
  67. }
  68. //fclose(fp);
  69. //return 1;
  70. map<const int, int, ltint> key_recn;
  71. map<const int, int, ltint> key_recn2[16];
  72. map<const int, int,ltint>::iterator iter;
  73. int c=1E6L;
  74. printf("填充源表数据%dms,recn=%d,每毫秒%d行\n",clock()-t,c,(long)1E6/(clock()-t));
  75. t=clock();
  76. int *C=(int*)malloc(c*4);//store count(c1)
  77. int *k=(int*)malloc(c*4);//store key
  78. v2=(__int64*)malloc(c*8);
  79. memset(C,0,c*4); //need?
  80. memset(v2,0,c*8);
  81. printf("申请一层内存%dms\n",clock()-t);
  82. t=clock();
  83. c=0;
  84. for (int i=0;i<1E6L;i++)
  85. {
  86. int key=(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i];
  87. //printf("key=%d\n",key);
  88. addskey;
  89. }
  90. printf("新建一层节点%dms,recn=%d,每毫秒读%d行,每毫秒写%d节点\n",clock()-t,c,(long)1E6/(clock()-t),c/(clock()-t));
  91. t=clock();
  92. /*
  93. for (int i=0;i<1E6L;i++)
  94. {
  95. int recn=key_recn[(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i]];
  96. k[recn]=(c1[i]<<24)+(c2[i]<<16)+(c3[i]<<8)+c4[i];
  97. C[recn]++;
  98. v2[recn]=v2[recn]+v1[i];
  99. }
  100. */
  101. //printf("写入一层数据%dms,recn=%d,每毫秒读%d行,每毫秒写%d行\n",clock()-t,c,(long)1E6/(clock()-t),c/(clock()-t));
  102. t=clock();
  103. int c_2=c;
  104. int o[15]={8,4,2,1,9,5,3,6,10,12,13,14,11,7,15};
  105. int mask[15]={
  106. 0x00FFFFFF,
  107. 0xFF00FFFF,
  108. 0xFFFF00FF,
  109. 0xFFFFFF00,
  110. 0x00FFFF00,
  111. 0xFF00FF00,
  112. 0xFFFF0000,
  113. 0xFF0000FF,
  114. 0x00FF00FF,
  115. 0x0000FFFF,
  116. 0x0000FF00,
  117. 0x000000FF,
  118. 0x00FF0000,
  119. 0xFF000000,
  120. 0x00000000};
  121. int null[15]={
  122. ((0x80+15)<<24),
  123. ((0x40)<<24)+(127<<16),
  124. ((0x20)<<24)+(127<<8),
  125. ((0x10)<<24)+(127),
  126. ((0x90+15)<<24)+(127),
  127. ((0x50)<<24)+(127<<16)+(127),
  128. ((0x30)<<24)+(127<<8)+(127),
  129. ((0x60)<<24)+(127<<16)+(127<<8),
  130. ((0xA0+15)<<24)+(127<<8),
  131. ((0xC0+15)<<24)+(127<<16),
  132. ((0xD0+15)<<24)+(127<<16)+(127),
  133. ((0xE0+15)<<24)+(127<<16)+(127<<8),
  134. ((0xB0+15)<<24)+(127<<8)+(127),
  135. ((0x70)<<24)+(127<<16)+(127<<8)+(127),
  136. ((0xF0+15)<<24)+(127<<16)+(127<<8)+(127)
  137. };
  138. dsize=c_2;
  139. int *C2=(int*)malloc((c_2)*4);//store count(c1)
  140. int *k2=(int*)malloc((c_2)*4);//store key
  141. __int64* v3=(__int64*)malloc((c_2)*8);
  142. memset(C2,0,(c_2)*4); //need?
  143. memset(v3,0,(c_2)*8);
  144. printf("申请后面内存%dms,%d\n",clock()-t,c_2);
  145. t=clock();
  146. //goto f;
  147. int y=0;
  148. int f[16];
  149. memset(f,0,16*4);
  150. for (int i=0;i<c_2;i++)
  151. {
  152. if(dsize<c-c_2+4)
  153. {
  154. dsize+=dsize;
  155. C2=(int*)realloc(C2,(dsize)*4);//store count(c1)
  156. k2=(int*)realloc(k2,(dsize)*4);//store key
  157. v3=(__int64*)realloc(v3,(dsize)*8);
  158. //memset(C2,0,(c_2)*4); //need?
  159. //memset(v3,0,(c_2)*8);
  160. }
  161. int key=(k[i]&0xFFFFFF)+((0x80+15)<<24);//set c1 null ,gid=8
  162. adsmkey(8);
  163. key=(k[i]&0xFF00FFFF)+((0x40)<<24)+(127<<16);//set c2 null,gid=4
  164. adsmkey(4);
  165. key=(k[i]&0xFFFF00FF)+((0x20)<<24)+(127<<8);//set c3 null,gid=2
  166. adsmkey(2);
  167. key=(k[i]&0xFFFFFF00)+((0x10)<<24)+(127);//set c4 null,gid=1
  168. adsmkey(1);
  169. /*
  170. for(int j=0;j<4;j++)
  171. {
  172. //int key=(k[i]&mask[j])+null[j];
  173. //if(key_recn2[o[j]].find(key)!= key_recn2[o[j]].end())
  174. {f[o[j]]++;
  175. int recn=key_recn2[o[j]][(k[i]&mask[j])+null[j]]-c_2;
  176. k2[recn]=(k[i]&mask[j])+null[j];
  177. C2[recn]+=C[i];
  178. v3[recn]+=v2[i];
  179. y=recn;
  180. }
  181. }
  182. key=(k[i]&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
  183. adkey(9);
  184. key=(k[i]&0xFF00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
  185. adkey(5);
  186. key=(k[i]&0xFFFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
  187. adkey(3);
  188. key=(k[i]&0xFF0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
  189. adkey(6);
  190. key=(k[i]&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
  191. adkey(10);
  192. key=(k[i]&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
  193. adkey(12);
  194. key=(k[i]&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
  195. adkey(13);
  196. key=(k[i]&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
  197. adkey(14);
  198. key=(k[i]&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
  199. adkey(11);
  200. key=(k[i]&0xFF000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
  201. adkey(7);
  202. key=((0xF0+15)<<24)+(127<<16)+(127<<8)+(127);//set c1,c2,c3,c4 null,gid=15
  203. adkey(15);
  204. */
  205. }
  206. //map<const int, int,ltint>::iterator iter;
  207. switch(it)
  208. {
  209. case 1:
  210. for(int i=1;i<7;i++)
  211. {
  212. if (i==1)
  213. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  214. {
  215. int key=((iter->first)&0x0FFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
  216. adkey(3);
  217. key=((iter->first)&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
  218. adkey(9);
  219. key=((iter->first)&0x0F00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
  220. adkey(5);
  221. }
  222. if(i==2)
  223. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  224. {
  225. int key=((iter->first)&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
  226. adkey(10);
  227. }
  228. if(i==4)
  229. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  230. {
  231. int key=((iter->first)&0x0F0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
  232. adkey(6);
  233. key=((iter->first)&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
  234. adkey(12);
  235. }
  236. if(i==3)
  237. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  238. {
  239. int key=((iter->first)&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
  240. adkey(11);
  241. key=((iter->first)&0x0F000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
  242. adkey(7);
  243. }
  244. if(i==5)
  245. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  246. {
  247. int key=((iter->first)&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
  248. adkey(13);
  249. }
  250. if(i==6)
  251. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  252. {
  253. int key=((iter->first)&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
  254. adkey(14);
  255. }
  256. }
  257. break;
  258. case 2:
  259. for(int i=1;i<7;i++)
  260. {
  261. if (i==1)
  262. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  263. {
  264. }
  265. if(i==2)
  266. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  267. {
  268. int key=((iter->first)&0x0FFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
  269. adkey(3);
  270. key=((iter->first)&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
  271. adkey(9);
  272. key=((iter->first)&0x0F00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
  273. adkey(5);
  274. key=((iter->first)&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
  275. adkey(10);
  276. }
  277. if(i==4)
  278. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  279. {
  280. int key=((iter->first)&0x0F0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
  281. adkey(6);
  282. key=((iter->first)&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
  283. adkey(12);
  284. }
  285. if(i==3)
  286. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  287. {
  288. int key=((iter->first)&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
  289. adkey(11);
  290. key=((iter->first)&0x0F000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
  291. adkey(7);
  292. }
  293. if(i==5)
  294. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  295. {
  296. int key=((iter->first)&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
  297. adkey(13);
  298. }
  299. if(i==6)
  300. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  301. {
  302. int key=((iter->first)&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
  303. adkey(14);
  304. }
  305. }
  306. break;
  307. default:break;
  308. }
  309. int key=((0xF0+15)<<24)+(127<<16)+(127<<8)+(127);//set c1,c2,c3,c4 null,gid=15
  310. adkey(15);
  311. printf("新建后面节点%dms,recn=%d,每毫秒读%d行key,每毫秒写%d节点\n",clock()-t,c,c_2/(clock()-t),(c-c_2)/(clock()-t));
  312. for(int i=0;i<16;i++)
  313. {
  314. printf("%d,first=%0X,renc=%d\n",i,key_recn2[i].begin()->first,key_recn2[i][key_recn2[i].begin()->first]);
  315. }
  316. t=clock();
  317. /*
  318. for (int i=0;i<c_2;i++)
  319. {
  320. for(int j=0;j<4;j++)
  321. {
  322. //int key=(k[i]&mask[j])+null[j];
  323. //if(key_recn2[o[j]].find(key)!= key_recn2[o[j]].end())
  324. {f[o[j]]++;
  325. int recn=key_recn2[o[j]][(k[i]&mask[j])+null[j]]-c_2;
  326. k2[recn]=(k[i]&mask[j])+null[j];
  327. C2[recn]+=C[i];
  328. v3[recn]+=v2[i];
  329. y=recn;
  330. }
  331. }
  332. }
  333. */
  334. for(int i=1;i<7;i++)
  335. {
  336. if (i==1)
  337. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  338. {
  339. int key=((iter->first)&0x0FFF0000)+((0x30)<<24)+(127<<8)+(127);//set c3,c4 null,gid=3
  340. /* {f[3]++;
  341. int recn=key_recn2[3][key]-c_2;
  342. k2[recn]=key;
  343. C2[recn]+=C2[(iter->second)-c_2];
  344. v3[recn]+=v3[(iter->second)-c_2];
  345. }*/
  346. sumkey(3);
  347. key=((iter->first)&0xFFFF00)+((0x90+15)<<24)+(127);//set c1,c4 null ,gid=9
  348. sumkey(9);
  349. key=((iter->first)&0x0F00FF00)+((0x50)<<24)+(127<<16)+(127);//set c2,c4 null,gid=5
  350. sumkey(5);
  351. }
  352. if(i==2)
  353. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  354. {
  355. int key=((iter->first)&0x00FF00FF)+((0xA0+15)<<24)+(127<<8);//set c1,c3 null,gid=10
  356. sumkey(10);
  357. }
  358. if(i==4)
  359. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  360. {
  361. int key=((iter->first)&0x0F0000FF)+((0x60)<<24)+(127<<16)+(127<<8);//set c2,c3 null,gid=6
  362. sumkey(6);
  363. key=((iter->first)&0xFFFF)+((0xC0+15)<<24)+(127<<16);//set c1,c2 null,gid=12
  364. sumkey(12);
  365. }
  366. if(i==3)
  367. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  368. {
  369. int key=((iter->first)&0xFF0000)+((0xB0+15)<<24)+(127<<8)+(127);//set c1,c3,c4 null,gid=11
  370. sumkey(11);
  371. key=((iter->first)&0x0F000000)+((0x70)<<24)+(127<<16)+(127<<8)+(127);//set c2,c3,c4 null,gid=7
  372. sumkey(7);
  373. key=((0xF0+15)<<24)+(127<<16)+(127<<8)+(127);//set c1,c2,c3,c4 null,gid=15
  374. sumkey(15);
  375. }
  376. if(i==5)
  377. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  378. {
  379. int key=((iter->first)&0xFF00)+((0xD0+15)<<24)+(127<<16)+(127);//set c1,c2,c4 null,gid=13
  380. sumkey(13);
  381. }
  382. if(i==6)
  383. for(iter=key_recn2[i].begin();iter != key_recn2[i].end(); iter++)
  384. {
  385. int key=((iter->first)&0xFF)+((0xE0+15)<<24)+(127<<16)+(127<<8);//set c1,c2,c3 null,gid=14
  386. sumkey(14);
  387. }
  388. }
  389. printf("汇总后面节点%dms,recn=%d,每毫秒读%d行,每毫秒写%d行\n",clock()-t,c,c_2/(clock()-t),(c-c_2)/(clock()-t));
  390. t=clock();
  391. /*
  392. printf("%fms,recn=%d,c1=%d,c2=%d,c3=%d,c4=%d,count=%d,sum=%I64d\n",(float)(clock()-t)/CLOCKS_PER_SEC ,c,
  393. (k2[y]>>24),((k2[y]>>16)&255),((k2[y]>>8)&255),(k2[y]&255),C2[y],v3[y]);
  394. FILE *fp=fopen("out.txt","wb");
  395. //fp=fopen("out.txt","wb");
  396. fprintf(fp,"gid,c1,c2,c3,c4,count,sum\n");
  397. for (int i=0;i<c_2;i++)
  398. {
  399. y=i;
  400. fprintf(fp,"%d,%d,%d,%d,%d,%d,%I64d\n",
  401. 0,(k[y]>>24),((k[y]>>16)&255),((k[y]>>8)&255),(k[y]&255),C[y],v2[y]);
  402. }
  403. for (int i=0;i<c-c_2;i++)
  404. {
  405. y=i;
  406. fprintf(fp,"%d,%d,%d,%d,%d,%d,%I64d\n",
  407. (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]);
  408. }
  409. fclose(fp);
  410. printf("保存到文件%dms,recn=%d,每毫秒写%d行\n",clock()-t,c,c/(clock()-t));
  411. t=clock();
  412. */
  413. f:
  414. free(c1);
  415. free(c2);
  416. free(c3);
  417. free(c4);
  418. free(v1);
  419. free(v2);
  420. free(C);
  421. free(k);
  422. free(C2);
  423. free(k2);
  424. free(v3);
  425. printf("释放所有动态内存%dms,%d\n",clock()-t,c);
  426. for(int i=0;i<16;i++)
  427. printf("%d,%d\n",i,f[i]);
  428. printf("总时间%dms,%d\n",clock()-t1,c);
  429. }
  430. return 0;
  431. }
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2010-3-3 13:12:14 | 显示全部楼层
源代码 mapp.rar (2.78 KB, 下载次数: 0) 比较结果 comp.gif
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2010-3-3 13:14:13 | 显示全部楼层
酒向知己饮 可惜我不会饮酒,
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2010-3-3 16:40:52 | 显示全部楼层
所有的代码

maps.cpp.rar

193.61 KB, 下载次数: 0, 下载积分: 金币 -1 枚, 经验 1 点, 下载 1 次

毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2010-3-9 16:15:48 | 显示全部楼层
map9d

map9d.rar

8.53 KB, 下载次数: 0, 下载积分: 金币 -1 枚, 经验 1 点, 下载 1 次

毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-11-22 02:05 , Processed in 0.036402 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表