Guest User

void.h 1.45 by FrozenVoid

a guest
Aug 8th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 18.45 KB | None | 0 0
  1. /* VOID.H - Universal Header File.
  2. void.h ver1.45 for Digital Mars C by FrozenVoid original content licensed under UFIL1.02 http://pastebin.com/L3p9XK3T
  3. portions of file are licensed under other licenses(check source of content)
  4. @..\dmc  -gg -Nc -Jm  -o+all -o-dv %1.c -o%1.exe
  5. */
  6. /* Features:
  7. #include default C libraries.
  8. short syntax for type declarations [type][bytes]([p=restrict pointer]*Level)
  9. short syntax for main/exitmain
  10. short syntax for common keywords
  11. u8 rdtsc() return 64bit CPU cycle counter.
  12. u[num] ru[num]() returns num random bytes
  13. u8 rrange(u8 max) return random u8 number in range 0<>max
  14. u1* chrgen(resstr,size) return a random string of [size] bytes composed from random characters in resstr.
  15.  sas(expr,errmsg) static(compile time) assert wil fail if expr isn't true with errmsg
  16. u1* getfile(u1* filename,u8* size) copy file co
  17. ntent to pointer and set size to filesize.
  18. u8 putfile(u1* ptr,u8 size,u1* filename)  copy content to filename, return number of bytes written
  19. u4* hash(u1* text,u8 len) return 16byte MurmurHash3 of string, len is length of string/text;
  20. f10 ent(u1* str,u8 size)  return entropy of string(size of string)
  21. v0 prbin(s4 num) print binary value of int32
  22. various bithacks,murmurhash,etc
  23.  
  24.  
  25. */
  26.  
  27. #ifndef __DMC__
  28. #error "This header contains Digital Mars C-only code."
  29. #endif
  30. #pragma once
  31. //void.h default includes
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <assert.h>
  35. #include <errno.h>
  36. #include <ctype.h>
  37. #include <fenv.h>
  38. #include <float.h>
  39. #include <inttypes.h>
  40. #include <limits.h>
  41. #include <math.h>
  42. #include <setjmp.h>
  43. #include <signal.h>
  44. #include <stdarg.h>
  45. #include <stddef.h>
  46. #include <stdbool.h>
  47. #include <stdint.h>
  48. #include <time.h>
  49. #include <string.h>
  50. #define d #define
  51. // Typedefs
  52. d td typedef
  53. td uint8_t u1;
  54. td uint16_t u2;
  55. td uint32_t u4;
  56. td uint64_t u8;
  57. td int8_t s1;
  58. td int16_t s2;
  59. td int32_t s4;
  60. td int64_t s8;
  61. td float f4;
  62. td double f8;
  63. td long double f10;
  64. td void v0;
  65. //Pointers restrict+unsigned 3levels
  66. td restrict u1* u1p;
  67. td restrict u1** u1pp;
  68. td restrict u1*** u1ppp;
  69. td restrict u2* u2p;
  70. td restrict u2** u2pp;
  71. td restrict u2*** u2ppp;
  72. td restrict u4* u4p;
  73. td restrict u4** u4pp;
  74. td restrict u4*** u4ppp;
  75. td restrict u8* u8p;
  76. td restrict u8** u8pp;
  77. td restrict u8*** u8ppp;
  78. td restrict v0* v0p;
  79. td restrict v0** v0pp;
  80. td restrict v0*** v0ppp;
  81. //aliases
  82. d STDSTART s4 main(s4 argc,u1**argv){;
  83. d STDEND ;return 0;};
  84. d FASTSTART v0 main(v0){;
  85. d FASTEND ;};
  86. d pr printf
  87. d ma malloc
  88. d go goto
  89. d wh while
  90. d br break;
  91. d sw switch
  92. d el else
  93. d st struct
  94. d ts typedef struct
  95. d re return
  96. d sta static
  97. d reg register
  98. d con continue
  99. d iv inline void
  100. d ln(x) (_msize(x))//object size in malloced bytes
  101. // constants
  102.  
  103.  
  104. //Common functions
  105. //BITHACKS
  106.  
  107. //set,clear,toggle,check bit of integer
  108. //http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/
  109. d setb(o,p) o|=(1<<p)      //byte| 1<< pos  
  110. d clrb(o,p) o&=(~(1<<p))  // byte | 11101111
  111. d togb(o,p) o^=(1<<p)
  112. d chkb(o,p) ((o>>p)&1)
  113. //Turnoff rightmost bit
  114. d offlast1(x) (x&(x-1))
  115. d onlast0(x) (x|(x+1))
  116. d last1(x)  (x&(-x))
  117. d last0(x) ((~x)&(x+1))
  118. //sign of integer
  119. d signof(x) (x>>((sizeof(x)*8)-1)) //-1/0
  120. d even(x) (!(x&1))
  121. d odd(x)  (x&1)
  122.  
  123. //http://graphics.stanford.edu/~seander/bithacks.html
  124. //absolute values
  125. d abs(x) ((x^(x>>(sizeof(x)*8-1)))-(x>>(sizeof(x)*8-1)))
  126. //minimum and maximum
  127. d min(x,y)  (y ^ ((x ^ y) & -(x < y)))
  128. d max(x,y)  (x ^ ((x ^ y) & -(x < y)))
  129. //is power of 2
  130. d is2pow(x) (x&&(!(x & (x - 1))))
  131. //Conditionally set or clear bits without branching
  132. d scbits(x,bitmask,cond) (x&(~bitmask))|((-cond)&bitmask)
  133. //Conditional negation(if flag is true/1)
  134. d condneg(x,flag) ((x^(-flag))+flag)
  135. //merge bits from x,y from bitmask:1=ybit,0=xbit
  136. d mergebits(x,y,bitmask) (x^((x^y)&mask))
  137. // coutn bit in int32
  138. inline s4 counts4bits(s4 num){
  139. s4 v=num-((num>>1)&0x55555555);
  140. v=(v & 0x33333333) + ((v >> 2) & 0x33333333);
  141. re (((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24);}
  142. inline s8 counts8bits(s8 num){//untested
  143. s4 v=num-((num>>1)&0x5555555555555555ULL);
  144. v=(v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL);
  145. re (((v + (v >> 4) & 0xF0F0F0F0F0F0F0FULL) * 0x101010101010101ULL) >> 56);}
  146.  s4 inline s4parity(s4 num){
  147. s4 v=num;
  148. v^=(v>>16);
  149. v^=(v>>8);
  150. v^=(v>>4);
  151. v&=0xf;
  152. re ((0x6996 >> v) & 1);
  153. }
  154. s1 inline  s1parity(s1 num){
  155. s4 v=num;
  156. v^=(v>>4);
  157. v&=0xf;
  158. re ((0x6996 >> v) & 1);
  159. }
  160.  
  161.  
  162. //Random integers 1*,2*,4,8 bytes
  163. //http://en.wikipedia.org/wiki/Xorshift
  164. d DSEC 1 //0 low entropy/faster 1=highentropy
  165. inline u8 rdtsc(){__asm{RDTSC}} //timestamp
  166. uint32_t ru4(v0) {//xor128 RNG
  167.   static uint32_t x = 123456789;
  168.   static uint32_t y = 362436069;
  169.   static uint32_t z = 521288629;
  170.   static uint32_t w = 88675123;
  171.   uint32_t t;
  172.    t = x ^ (x << 11);
  173.   x = y; y = z; z = w;
  174. w = w ^ (w >> 19) ^ (t ^ (t >> 8));
  175.   return w;
  176. }
  177. u8 ru8(v0){
  178. u8 res;u4* h=(u4*)&res;
  179. h[0]=ru4();
  180. h[1]=ru4();
  181. re res;
  182. }
  183.  u1 ru1(v0){
  184. //select 1/4 of int32
  185. u4 r=ru4();
  186. u4 sh=(r&3)<<3;
  187. #ifdef DSEC
  188.  
  189. re (u1)((ru4()&(0xFF<<(sh)))>>(sh));
  190. #else
  191.  
  192. re (u1)((r&(0xFF<<(sh)))>>(sh));
  193. #endif
  194. }
  195.  
  196.  u2 ru2(v0){
  197. u4 r=ru4();u4 sh=(r&1)<<4;
  198. #ifdef DSEC
  199. re (u2)((ru4()&(0xFFFF<<(sh)))>>(sh));
  200. #else
  201. re (u2)((r&(0xFFFF<<(sh)))>>(sh));
  202. #endif
  203. }
  204. /*
  205. random text: 0-x positon in string.
  206. */
  207. u8 rrange(u8 max){
  208. f10 div=((f10)ULLONG_MAX);
  209. u8 r=ru8();if(!r)r++;
  210. f10 d2=(((f10)r)/div)*((f10)max);//0..1 rnd number
  211. u8 res=(u8)d2;
  212. re res;
  213. }
  214. u1* chrgen(u1* str,u8 ressize){
  215. u8 strl=strlen(str);//"12" string index max
  216. u1* res=ma(ressize);u8 i=0;
  217. for(i=0;i<ressize;i++){res[i]=str[rrange(strl)];}
  218. re res;
  219. }
  220.  
  221.  
  222. v0 prbin(s4 num){//prints binary value of int32
  223. s4 i;
  224. for(i=31;i>-1;i--){putchar(chkb(num,i)+48);}
  225. }
  226.  
  227.  
  228. const u1 alphanumeric[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  229.  
  230. u4 inline countwords(u1* str,u4 strsize){
  231. u4 reg count=0;u4 reg old=0;u4 reg state=0;
  232. u4 i;
  233. for(i=0;i<strsize;i++){
  234. state=alphanumeric[str[i]];
  235. count+=(old^state);old=state;}
  236. count>>=1;
  237. re count;}
  238.  
  239. u4 inline countlines(u1* str,u4 strsize){
  240. u4 reg count=1;u4 i=strsize;
  241. wh(i--){count+=(!(str[i]^'\n'));};
  242. re count;
  243. }
  244.  
  245.  
  246.  
  247.  
  248. //----------------------------------------------
  249. //Debug error in0,out1,err2
  250. // ASCII   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
  251. #define epr(...) fprintf(stderr, __VA_ARGS__)
  252. //static assert
  253. #define sas(expr,errmsg) \
  254. int __static_assert(int errmsg##static_assert_failed[(expr)?1:-1])
  255. d getext(filename) strrchr(filename,'.')
  256. d hasdigits(str) strpbrk(str,"0123456789")
  257. d startswithdigits(str) (strcspn(str,"0123456789")==0)
  258.  
  259. //Transfer file content into a pointer.
  260. u1* getfile(u1* filename,u8* size){
  261. FILE* in=fopen(filename,"rb");
  262. if(in==NULL){size[0]=0;perror("File access failed");return NULL;};
  263. fseek(in,0,SEEK_END);
  264. *size=(u8)ftell(in);rewind(in);
  265. u1* resfile=ma(size[0]);
  266. fread(resfile,size[0],1,in);
  267. fclose(in);
  268. re resfile;
  269. }
  270. //transfer pointer content into a file
  271. u8 putfile(u1* ptr,u8 size,u1* filename){
  272. FILE* out=fopen(filename,"wb");
  273. if(!out){perror("Cannot write to file");return 0;}
  274. u8 res=fwrite(ptr,size,1,out);fclose(out);
  275. re res;}
  276.  
  277. // Entropy calculation
  278. f10 ent(u1* str,u8 size){
  279. f10 entropy=0;f10 prob;f10 ml2=logl(2);
  280. u8 counts[256]={0};
  281. u8 iter=0;
  282. wh(iter<size){counts[str[iter++]]++;};iter=0;
  283.  
  284. for(iter=0;iter<256;iter++){
  285. if(!counts[iter]){;con;}
  286. prob=1.0*((f10)counts[iter]/(f10)size);
  287. entropy-=prob*(logl(prob)/ml2);;}
  288.  
  289. re entropy;
  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.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404.  
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529.  
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.  
  1594.  
  1595.  
  1596.  
  1597.  
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.  
  1688.  
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
  1797.  
  1798.  
  1799.  
  1800.  
  1801.  
  1802.  
  1803.  
  1804.  
  1805.  
  1806.  
  1807.  
  1808.  
  1809.  
  1810.  
  1811.  
  1812.  
  1813.  
  1814.  
  1815.  
  1816.  
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.  
  1857.  
  1858.  
  1859.  
  1860.  
  1861.  
  1862.  
  1863.  
  1864.  
  1865.  
  1866.  
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.  
  1922.  
  1923.  
  1924.  
  1925.  
  1926.  
  1927.  
  1928.  
  1929.  
  1930.  
  1931.  
  1932.  
  1933.  
  1934.  
  1935.  
  1936.  
  1937.  
  1938.  
  1939.  
  1940.  
  1941.  
  1942.  
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948.  
  1949.  
  1950.  
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.  
  1988.  
  1989.  
  1990.  
  1991.  
  1992.  
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034. #undef d
  2035. //-------------MurmurHash3
  2036. //http://en.wikipedia.org/wiki/MurmurHash
  2037. // Platform-specific functions and macros
  2038.  
  2039. #ifdef __GNUC__
  2040. #define FORCE_INLINE __attribute__((always_inline)) inline
  2041. #else
  2042. #define FORCE_INLINE
  2043. #endif
  2044.  
  2045. static inline FORCE_INLINE uint32_t rotl32 ( uint32_t x, int8_t r )
  2046. {
  2047.   return (x << r) | (x >> (32 - r));
  2048. }
  2049.  
  2050. static inline FORCE_INLINE uint64_t rotl64 ( uint64_t x, int8_t r )
  2051. {
  2052.   return (x << r) | (x >> (64 - r));
  2053. }
  2054.  
  2055. #define ROTL32(x,y) rotl32(x,y)
  2056. #define ROTL64(x,y) rotl64(x,y)
  2057.  
  2058. #define BIG_CONSTANT(x) (x##LLU)
  2059.  
  2060. //-----------------------------------------------------------------------------
  2061. // Block read - if your platform needs to do endian-swapping or can only
  2062. // handle aligned reads, do the conversion here
  2063.  
  2064. #define getblock(p, i) (p[i])
  2065.  
  2066. //-----------------------------------------------------------------------------
  2067. // Finalization mix - force all bits of a hash block to avalanche
  2068.  
  2069. static inline FORCE_INLINE uint32_t fmix32 ( uint32_t h )
  2070. {
  2071.   h ^= h >> 16;
  2072.   h *= 0x85ebca6b;
  2073.   h ^= h >> 13;
  2074.   h *= 0xc2b2ae35;
  2075.   h ^= h >> 16;
  2076.  
  2077.   return h;
  2078. }
  2079.  
  2080. //----------
  2081.  
  2082. static inline FORCE_INLINE uint64_t fmix64 ( uint64_t k )
  2083. {
  2084.   k ^= k >> 33;
  2085.   k *= BIG_CONSTANT(0xff51afd7ed558ccd);
  2086.   k ^= k >> 33;
  2087.   k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
  2088.   k ^= k >> 33;
  2089.  
  2090.   return k;
  2091. }
  2092.  
  2093. //-----------------------------------------------------------------------------
  2094.  
  2095. void MurmurHash3_x86_32 ( const void * key, int len,
  2096.                           uint32_t seed, void * out )
  2097. {
  2098.   const uint8_t * data = (const uint8_t*)key;
  2099.   const int nblocks = len / 4;
  2100.   int i;
  2101.  
  2102.   uint32_t h1 = seed;
  2103.  
  2104.   uint32_t c1 = 0xcc9e2d51;
  2105.   uint32_t c2 = 0x1b873593;
  2106.  
  2107.   //----------
  2108.   // body
  2109.  
  2110.   const uint32_t * blocks = (const uint32_t *)(data + nblocks*4);
  2111.  
  2112.   for(i = -nblocks; i; i++)
  2113.   {
  2114.     uint32_t k1 = getblock(blocks,i);
  2115.  
  2116.     k1 *= c1;
  2117.     k1 = ROTL32(k1,15);
  2118.     k1 *= c2;
  2119.    
  2120.     h1 ^= k1;
  2121.     h1 = ROTL32(h1,13);
  2122.     h1 = h1*5+0xe6546b64;
  2123.   }
  2124.  
  2125.   //----------
  2126.   // tail
  2127.  
  2128.   const uint8_t * tail = (const uint8_t*)(data + nblocks*4);
  2129.  
  2130.   uint32_t k1 = 0;
  2131.  
  2132.   switch(len & 3)
  2133.   {
  2134.   case 3: k1 ^= tail[2] << 16;
  2135.   case 2: k1 ^= tail[1] << 8;
  2136.   case 1: k1 ^= tail[0];
  2137.           k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
  2138.   };
  2139.  
  2140.   //----------
  2141.   // finalization
  2142.  
  2143.   h1 ^= len;
  2144.  
  2145.   h1 = fmix32(h1);
  2146.  
  2147.   *(uint32_t*)out = h1;
  2148. }
  2149.  
  2150. //-----------------------------------------------------------------------------
  2151.  
  2152. void MurmurHash3_x86_128 ( const void * key, const int len,
  2153.                            uint32_t seed, void * out )
  2154. {
  2155.   const uint8_t * data = (const uint8_t*)key;
  2156.   const int nblocks = len / 16;
  2157.   int i;
  2158.  
  2159.   uint32_t h1 = seed;
  2160.   uint32_t h2 = seed;
  2161.   uint32_t h3 = seed;
  2162.   uint32_t h4 = seed;
  2163.  
  2164.   uint32_t c1 = 0x239b961b;
  2165.   uint32_t c2 = 0xab0e9789;
  2166.   uint32_t c3 = 0x38b34ae5;
  2167.   uint32_t c4 = 0xa1e38b93;
  2168.  
  2169.   //----------
  2170.   // body
  2171.  
  2172.   const uint32_t * blocks = (const uint32_t *)(data + nblocks*16);
  2173.  
  2174.   for(i = -nblocks; i; i++)
  2175.   {
  2176.     uint32_t k1 = getblock(blocks,i*4+0);
  2177.     uint32_t k2 = getblock(blocks,i*4+1);
  2178.     uint32_t k3 = getblock(blocks,i*4+2);
  2179.     uint32_t k4 = getblock(blocks,i*4+3);
  2180.  
  2181.     k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
  2182.  
  2183.     h1 = ROTL32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
  2184.  
  2185.     k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
  2186.  
  2187.     h2 = ROTL32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
  2188.  
  2189.     k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
  2190.  
  2191.     h3 = ROTL32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
  2192.  
  2193.     k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
  2194.  
  2195.     h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
  2196.   }
  2197.  
  2198.   //----------
  2199.   // tail
  2200.  
  2201.   const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
  2202.  
  2203.   uint32_t k1 = 0;
  2204.   uint32_t k2 = 0;
  2205.   uint32_t k3 = 0;
  2206.   uint32_t k4 = 0;
  2207.  
  2208.   switch(len & 15)
  2209.   {
  2210.   case 15: k4 ^= tail[14] << 16;
  2211.   case 14: k4 ^= tail[13] << 8;
  2212.   case 13: k4 ^= tail[12] << 0;
  2213.            k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
  2214.  
  2215.   case 12: k3 ^= tail[11] << 24;
  2216.   case 11: k3 ^= tail[10] << 16;
  2217.   case 10: k3 ^= tail[ 9] << 8;
  2218.   case 9: k3 ^= tail[ 8] << 0;
  2219.            k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
  2220.  
  2221.   case 8: k2 ^= tail[ 7] << 24;
  2222.   case 7: k2 ^= tail[ 6] << 16;
  2223.   case 6: k2 ^= tail[ 5] << 8;
  2224.   case 5: k2 ^= tail[ 4] << 0;
  2225.            k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
  2226.  
  2227.   case 4: k1 ^= tail[ 3] << 24;
  2228.   case 3: k1 ^= tail[ 2] << 16;
  2229.   case 2: k1 ^= tail[ 1] << 8;
  2230.   case 1: k1 ^= tail[ 0] << 0;
  2231.            k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
  2232.   };
  2233.  
  2234.   //----------
  2235.   // finalization
  2236.  
  2237.   h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
  2238.  
  2239.   h1 += h2; h1 += h3; h1 += h4;
  2240.   h2 += h1; h3 += h1; h4 += h1;
  2241.  
  2242.   h1 = fmix32(h1);
  2243.   h2 = fmix32(h2);
  2244.   h3 = fmix32(h3);
  2245.   h4 = fmix32(h4);
  2246.  
  2247.   h1 += h2; h1 += h3; h1 += h4;
  2248.   h2 += h1; h3 += h1; h4 += h1;
  2249.  
  2250.   ((uint32_t*)out)[0] = h1;
  2251.   ((uint32_t*)out)[1] = h2;
  2252.   ((uint32_t*)out)[2] = h3;
  2253.   ((uint32_t*)out)[3] = h4;
  2254. }
  2255.  
  2256. //-----------------------------------------------------------------------------
  2257.  
  2258. void MurmurHash3_x64_128 ( const void * key, const int len,
  2259.                            const uint32_t seed, void * out )
  2260. {
  2261.   const uint8_t * data = (const uint8_t*)key;
  2262.   const int nblocks = len / 16;
  2263.   int i;
  2264.  
  2265.   uint64_t h1 = seed;
  2266.   uint64_t h2 = seed;
  2267.  
  2268.   uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
  2269.   uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
  2270.  
  2271.   //----------
  2272.   // body
  2273.  
  2274.   const uint64_t * blocks = (const uint64_t *)(data);
  2275.  
  2276.   for(i = 0; i < nblocks; i++)
  2277.   {
  2278.     uint64_t k1 = getblock(blocks,i*2+0);
  2279.     uint64_t k2 = getblock(blocks,i*2+1);
  2280.  
  2281.     k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
  2282.  
  2283.     h1 = ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
  2284.  
  2285.     k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
  2286.  
  2287.     h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
  2288.   }
  2289.  
  2290.   //----------
  2291.   // tail
  2292.  
  2293.   const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
  2294.  
  2295.   uint64_t k1 = 0;
  2296.   uint64_t k2 = 0;
  2297.  
  2298.   switch(len & 15)
  2299.   {
  2300.   case 15: k2 ^= (uint64_t)(tail[14]) << 48;
  2301.   case 14: k2 ^= (uint64_t)(tail[13]) << 40;
  2302.   case 13: k2 ^= (uint64_t)(tail[12]) << 32;
  2303.   case 12: k2 ^= (uint64_t)(tail[11]) << 24;
  2304.   case 11: k2 ^= (uint64_t)(tail[10]) << 16;
  2305.   case 10: k2 ^= (uint64_t)(tail[ 9]) << 8;
  2306.   case 9: k2 ^= (uint64_t)(tail[ 8]) << 0;
  2307.            k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
  2308.  
  2309.   case 8: k1 ^= (uint64_t)(tail[ 7]) << 56;
  2310.   case 7: k1 ^= (uint64_t)(tail[ 6]) << 48;
  2311.   case 6: k1 ^= (uint64_t)(tail[ 5]) << 40;
  2312.   case 5: k1 ^= (uint64_t)(tail[ 4]) << 32;
  2313.   case 4: k1 ^= (uint64_t)(tail[ 3]) << 24;
  2314.   case 3: k1 ^= (uint64_t)(tail[ 2]) << 16;
  2315.   case 2: k1 ^= (uint64_t)(tail[ 1]) << 8;
  2316.   case 1: k1 ^= (uint64_t)(tail[ 0]) << 0;
  2317.            k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
  2318.   };
  2319.  
  2320.   //----------
  2321.   // finalization
  2322.  
  2323.   h1 ^= len; h2 ^= len;
  2324.  
  2325.   h1 += h2;
  2326.   h2 += h1;
  2327.  
  2328.   h1 = fmix64(h1);
  2329.   h2 = fmix64(h2);
  2330.  
  2331.   h1 += h2;
  2332.   h2 += h1;
  2333.  
  2334.   ((uint64_t*)out)[0] = h1;
  2335.   ((uint64_t*)out)[1] = h2;
  2336. }
  2337.  
  2338. //===============
  2339. u4* hash(u1* text,u8 len){
  2340. u4* res=ma(16);
  2341. MurmurHash3_x86_128(text,len,0x12345678,res);
  2342. re res;
  2343. }
Advertisement
Add Comment
Please, Sign In to add comment