Guest User

void.h 1.47 by FrozenVoid

a guest
Aug 8th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 15.83 KB | None | 0 0
  1. /* VOID.H - Universal Header File.
  2. void.h ver1.47 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. u4 coutnwords(str,size) counts number of words in string
  23. u4 countlines(str,size) counts number of  lines in string
  24. various bithacks,murmurhash,etc
  25. u4 countnonspaceseq(str,size) counts number of character sequences which don't contains spaces/tabs and newlines(with or withotu feeds)
  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. //Common functions
  103. //BITHACKS
  104. //set,clear,toggle,check bit of integer
  105. //http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/
  106. d setb(o,p) o|=(1<<p)      //byte| 1<< pos  
  107. d clrb(o,p) o&=(~(1<<p))  // byte | 11101111
  108. d togb(o,p) o^=(1<<p)
  109. d chkb(o,p) ((o>>p)&1)
  110. //Turnoff rightmost bit
  111. d offlast1(x) (x&(x-1))
  112. d onlast0(x) (x|(x+1))
  113. d last1(x)  (x&(-x))
  114. d last0(x) ((~x)&(x+1))
  115. //sign of integer
  116. d signof(x) (x>>((sizeof(x)*8)-1)) //-1/0
  117. d even(x) (!(x&1))
  118. d odd(x)  (x&1)
  119. //http://graphics.stanford.edu/~seander/bithacks.html
  120. //absolute values
  121. d abs(x) ((x^(x>>(sizeof(x)*8-1)))-(x>>(sizeof(x)*8-1)))
  122. //minimum and maximum
  123. d min(x,y)  (y ^ ((x ^ y) & -(x < y)))
  124. d max(x,y)  (x ^ ((x ^ y) & -(x < y)))
  125. //is power of 2
  126. d is2pow(x) (x&&(!(x & (x - 1))))
  127. //Conditionally set or clear bits without branching
  128. d scbits(x,bitmask,cond) (x&(~bitmask))|((-cond)&bitmask)
  129. //Conditional negation(if flag is true/1)
  130. d condneg(x,flag) ((x^(-flag))+flag)
  131. //merge bits from x,y from bitmask:1=ybit,0=xbit
  132. d mergebits(x,y,bitmask) (x^((x^y)&mask))
  133. // coutn bit in int32
  134. inline s4 counts4bits(s4 num){
  135. s4 v=num-((num>>1)&0x55555555);
  136. v=(v & 0x33333333) + ((v >> 2) & 0x33333333);
  137. re (((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24);}
  138. inline s8 counts8bits(s8 num){//untested
  139. s4 v=num-((num>>1)&0x5555555555555555ULL);
  140. v=(v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL);
  141. re (((v + (v >> 4) & 0xF0F0F0F0F0F0F0FULL) * 0x101010101010101ULL) >> 56);}
  142.  s4 inline s4parity(s4 num){
  143. s4 v=num;
  144. v^=(v>>16);
  145. v^=(v>>8);
  146. v^=(v>>4);
  147. v&=0xf;
  148. re ((0x6996 >> v) & 1);
  149. }
  150. s1 inline  s1parity(s1 num){
  151. s4 v=num;
  152. v^=(v>>4);
  153. v&=0xf;
  154. re ((0x6996 >> v) & 1);
  155. }
  156. //Random integers 1*,2*,4,8 bytes
  157. //http://en.wikipedia.org/wiki/Xorshift
  158. d DSEC 1 //0 low entropy/faster 1=highentropy
  159. inline u8 rdtsc(){__asm{RDTSC}} //timestamp
  160. uint32_t ru4(v0) {//xor128 RNG
  161.   static uint32_t x = 123456789;
  162.   static uint32_t y = 362436069;
  163.   static uint32_t z = 521288629;
  164.   static uint32_t w = 88675123;
  165.   uint32_t t;
  166.    t = x ^ (x << 11);
  167.   x = y; y = z; z = w;
  168. w = w ^ (w >> 19) ^ (t ^ (t >> 8));
  169.   return w;
  170. }
  171. u8 ru8(v0){
  172. u8 res;u4* h=(u4*)&res;
  173. h[0]=ru4();
  174. h[1]=ru4();
  175. re res;
  176. }
  177.  u1 ru1(v0){
  178. //select 1/4 of int32
  179. u4 r=ru4();
  180. u4 sh=(r&3)<<3;
  181. #ifdef DSEC
  182. re (u1)((ru4()&(0xFF<<(sh)))>>(sh));
  183. #else
  184. re (u1)((r&(0xFF<<(sh)))>>(sh));
  185. #endif
  186. }
  187.  u2 ru2(v0){
  188. u4 r=ru4();u4 sh=(r&1)<<4;
  189. #ifdef DSEC
  190. re (u2)((ru4()&(0xFFFF<<(sh)))>>(sh));
  191. #else
  192. re (u2)((r&(0xFFFF<<(sh)))>>(sh));
  193. #endif
  194. }
  195. /*
  196. random text: 0-x positon in string.
  197. */
  198. u8 rrange(u8 max){
  199. f10 div=((f10)ULLONG_MAX);
  200. u8 r=ru8();if(!r)r++;
  201. f10 d2=(((f10)r)/div)*((f10)max);//0..1 rnd number
  202. u8 res=(u8)d2;
  203. re res;
  204. }
  205. u1* chrgen(u1* str,u8 ressize){
  206. u8 strl=strlen(str);//"12" string index max
  207. u1* res=ma(ressize);u8 i=0;
  208. for(i=0;i<ressize;i++){res[i]=str[rrange(strl)];}
  209. re res;
  210. }
  211. v0 prbin(s4 num){//prints binary value of int32
  212. s4 i;
  213. for(i=31;i>-1;i--){putchar(chkb(num,i)+48);}
  214. }
  215. //return number of words and lines.
  216. 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};
  217. const u1 nonspaceseq[]={1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,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,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,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,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,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,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,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
  218. u4 inline countwords(u1* str,u4 strsize){
  219. u4 reg count=0;u4 reg old=0;u4 reg state=0;
  220. u4 i;
  221. for(i=0;i<strsize;i++){
  222. state=alphanumeric[str[i]];
  223. count+=(old^state);old=state;}
  224. count>>=1;
  225. re count;}
  226. u4 inline countlines(u1* str,u4 strsize){
  227. u4 reg count=1;u4 i=strsize;
  228. wh(i--){count+=(!(str[i]^'\n'));};
  229. re count;
  230. }
  231. u4 inline countnonspaceseq(u1* str,u4 strsize){
  232. u4 reg count=0;u4 reg old=0;u4 reg state=0;
  233. ;u4 i;
  234. for(i=0;i<strsize;i++){
  235. state=nonspaceseq[str[i]];
  236. count+=(old^state);old=state;}
  237. count>>=1;
  238. re count;}
  239. //----------------------------------------------
  240. // ASCII   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
  241. #define epr(...) fprintf(stderr, __VA_ARGS__)
  242. //static assert
  243. #define sas(expr,errmsg) \
  244. int __static_assert(int errmsg##static_assert_failed[(expr)?1:-1])
  245. d getext(filename) strrchr(filename,'.')
  246. d hasdigits(str) strpbrk(str,"0123456789")
  247. d startswithdigits(str) (strcspn(str,"0123456789")==0)
  248. //Transfer file content into a pointer.
  249. u1* getfile(u1* filename,u8* size){
  250. FILE* in=fopen(filename,"rb");
  251. if(in==NULL){size[0]=0;perror("File access failed");return NULL;};
  252. fseek(in,0,SEEK_END);
  253. *size=(u8)ftell(in);rewind(in);
  254. u1* resfile=ma(size[0]);
  255. fread(resfile,size[0],1,in);
  256. fclose(in);
  257. re resfile;
  258. }
  259. //transfer pointer content into a file
  260. u8 putfile(u1* ptr,u8 size,u1* filename){
  261. FILE* out=fopen(filename,"wb");
  262. if(!out){perror("Cannot write to file");return 0;}
  263. u8 res=fwrite(ptr,size,1,out);fclose(out);
  264. re res;}
  265.  
  266. // Entropy calculation
  267. f10 ent(u1* str,u8 size){
  268. f10 entropy=0;f10 prob;f10 ml2=logl(2);
  269. u8 counts[256]={0};
  270. u8 iter=0;
  271. wh(iter<size){counts[str[iter++]]++;};iter=0;
  272. for(iter=0;iter<256;iter++){
  273. if(!counts[iter]){;con;}
  274. prob=1.0*((f10)counts[iter]/(f10)size);
  275. entropy-=prob*(logl(prob)/ml2);;}
  276. re entropy;
  277. }
  278. #undef d
  279. //-------------MurmurHash3
  280. //http://en.wikipedia.org/wiki/MurmurHash
  281. // Platform-specific functions and macros
  282. #ifdef __GNUC__
  283. #define FORCE_INLINE __attribute__((always_inline)) inline
  284. #else
  285. #define FORCE_INLINE
  286. #endif
  287. static inline FORCE_INLINE uint32_t rotl32 ( uint32_t x, int8_t r )
  288. {
  289.   return (x << r) | (x >> (32 - r));
  290. }
  291. static inline FORCE_INLINE uint64_t rotl64 ( uint64_t x, int8_t r )
  292. {
  293.   return (x << r) | (x >> (64 - r));
  294. }
  295. #define ROTL32(x,y) rotl32(x,y)
  296. #define ROTL64(x,y) rotl64(x,y)
  297. #define BIG_CONSTANT(x) (x##LLU)
  298. //-----------------------------------------------------------------------------
  299. // Block read - if your platform needs to do endian-swapping or can only
  300. // handle aligned reads, do the conversion here
  301. #define getblock(p, i) (p[i])
  302. //-----------------------------------------------------------------------------
  303. // Finalization mix - force all bits of a hash block to avalanche
  304. static inline FORCE_INLINE uint32_t fmix32 ( uint32_t h )
  305. {
  306.   h ^= h >> 16;
  307.   h *= 0x85ebca6b;
  308.   h ^= h >> 13;
  309.   h *= 0xc2b2ae35;
  310.   h ^= h >> 16;
  311.   return h;
  312. }
  313. //----------
  314. static inline FORCE_INLINE uint64_t fmix64 ( uint64_t k )
  315. {
  316.   k ^= k >> 33;
  317.   k *= BIG_CONSTANT(0xff51afd7ed558ccd);
  318.   k ^= k >> 33;
  319.   k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
  320.   k ^= k >> 33;
  321.   return k;
  322. }
  323. //-----------------------------------------------------------------------------
  324. void MurmurHash3_x86_32 ( const void * key, int len,
  325.                           uint32_t seed, void * out )
  326. {
  327.   const uint8_t * data = (const uint8_t*)key;
  328.   const int nblocks = len / 4;
  329.   int i;
  330.   uint32_t h1 = seed;
  331.   uint32_t c1 = 0xcc9e2d51;
  332.   uint32_t c2 = 0x1b873593;
  333.   //----------
  334.   // body
  335.   const uint32_t * blocks = (const uint32_t *)(data + nblocks*4);
  336.   for(i = -nblocks; i; i++)
  337.   {
  338.     uint32_t k1 = getblock(blocks,i);
  339.     k1 *= c1;
  340.     k1 = ROTL32(k1,15);
  341.     k1 *= c2;
  342.    
  343.     h1 ^= k1;
  344.     h1 = ROTL32(h1,13);
  345.     h1 = h1*5+0xe6546b64;
  346.   }
  347.   //----------
  348.   // tail
  349.   const uint8_t * tail = (const uint8_t*)(data + nblocks*4);
  350.   uint32_t k1 = 0;
  351.   switch(len & 3)
  352.   {
  353.   case 3: k1 ^= tail[2] << 16;
  354.   case 2: k1 ^= tail[1] << 8;
  355.   case 1: k1 ^= tail[0];
  356.           k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
  357.   };
  358.   //----------
  359.   // finalization
  360.   h1 ^= len;
  361.   h1 = fmix32(h1);
  362.   *(uint32_t*)out = h1;
  363. }
  364. //-----------------------------------------------------------------------------
  365. void MurmurHash3_x86_128 ( const void * key, const int len,
  366.                            uint32_t seed, void * out )
  367. {
  368.   const uint8_t * data = (const uint8_t*)key;
  369.   const int nblocks = len / 16;
  370.   int i;
  371.   uint32_t h1 = seed;
  372.   uint32_t h2 = seed;
  373.   uint32_t h3 = seed;
  374.   uint32_t h4 = seed;
  375.   uint32_t c1 = 0x239b961b;
  376.   uint32_t c2 = 0xab0e9789;
  377.   uint32_t c3 = 0x38b34ae5;
  378.   uint32_t c4 = 0xa1e38b93;
  379.   //----------
  380.   // body
  381.   const uint32_t * blocks = (const uint32_t *)(data + nblocks*16);
  382.   for(i = -nblocks; i; i++)
  383.   {
  384.     uint32_t k1 = getblock(blocks,i*4+0);
  385.     uint32_t k2 = getblock(blocks,i*4+1);
  386.     uint32_t k3 = getblock(blocks,i*4+2);
  387.     uint32_t k4 = getblock(blocks,i*4+3);
  388.     k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
  389.     h1 = ROTL32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
  390.     k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
  391.     h2 = ROTL32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
  392.     k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
  393.     h3 = ROTL32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
  394.     k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
  395.     h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
  396.   }
  397.   //----------
  398.   // tail
  399.   const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
  400.   uint32_t k1 = 0;
  401.   uint32_t k2 = 0;
  402.   uint32_t k3 = 0;
  403.   uint32_t k4 = 0;
  404.   switch(len & 15)
  405.   {
  406.   case 15: k4 ^= tail[14] << 16;
  407.   case 14: k4 ^= tail[13] << 8;
  408.   case 13: k4 ^= tail[12] << 0;
  409.            k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4;
  410.   case 12: k3 ^= tail[11] << 24;
  411.   case 11: k3 ^= tail[10] << 16;
  412.   case 10: k3 ^= tail[ 9] << 8;
  413.   case 9: k3 ^= tail[ 8] << 0;
  414.            k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3;
  415.   case 8: k2 ^= tail[ 7] << 24;
  416.   case 7: k2 ^= tail[ 6] << 16;
  417.   case 6: k2 ^= tail[ 5] << 8;
  418.   case 5: k2 ^= tail[ 4] << 0;
  419.            k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2;
  420.   case 4: k1 ^= tail[ 3] << 24;
  421.   case 3: k1 ^= tail[ 2] << 16;
  422.   case 2: k1 ^= tail[ 1] << 8;
  423.   case 1: k1 ^= tail[ 0] << 0;
  424.            k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
  425.   };
  426.   //----------
  427.   // finalization
  428.   h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
  429.   h1 += h2; h1 += h3; h1 += h4;
  430.   h2 += h1; h3 += h1; h4 += h1;
  431.   h1 = fmix32(h1);
  432.   h2 = fmix32(h2);
  433.   h3 = fmix32(h3);
  434.   h4 = fmix32(h4);
  435.   h1 += h2; h1 += h3; h1 += h4;
  436.   h2 += h1; h3 += h1; h4 += h1;
  437.   ((uint32_t*)out)[0] = h1;
  438.   ((uint32_t*)out)[1] = h2;
  439.   ((uint32_t*)out)[2] = h3;
  440.   ((uint32_t*)out)[3] = h4;
  441. }
  442. //-----------------------------------------------------------------------------
  443. void MurmurHash3_x64_128 ( const void * key, const int len,
  444.                            const uint32_t seed, void * out )
  445. {
  446.   const uint8_t * data = (const uint8_t*)key;
  447.   const int nblocks = len / 16;
  448.   int i;
  449.   uint64_t h1 = seed;
  450.   uint64_t h2 = seed;
  451.   uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
  452.   uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
  453.   //----------
  454.   // body
  455.   const uint64_t * blocks = (const uint64_t *)(data);
  456.   for(i = 0; i < nblocks; i++)
  457.   {
  458.     uint64_t k1 = getblock(blocks,i*2+0);
  459.     uint64_t k2 = getblock(blocks,i*2+1);
  460.     k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
  461.     h1 = ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
  462.     k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
  463.     h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
  464.   }
  465.   //----------
  466.   // tail
  467.   const uint8_t * tail = (const uint8_t*)(data + nblocks*16);
  468.   uint64_t k1 = 0;
  469.   uint64_t k2 = 0;
  470.   switch(len & 15)
  471.   {
  472.   case 15: k2 ^= (uint64_t)(tail[14]) << 48;
  473.   case 14: k2 ^= (uint64_t)(tail[13]) << 40;
  474.   case 13: k2 ^= (uint64_t)(tail[12]) << 32;
  475.   case 12: k2 ^= (uint64_t)(tail[11]) << 24;
  476.   case 11: k2 ^= (uint64_t)(tail[10]) << 16;
  477.   case 10: k2 ^= (uint64_t)(tail[ 9]) << 8;
  478.   case 9: k2 ^= (uint64_t)(tail[ 8]) << 0;
  479.            k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2;
  480.   case 8: k1 ^= (uint64_t)(tail[ 7]) << 56;
  481.   case 7: k1 ^= (uint64_t)(tail[ 6]) << 48;
  482.   case 6: k1 ^= (uint64_t)(tail[ 5]) << 40;
  483.   case 5: k1 ^= (uint64_t)(tail[ 4]) << 32;
  484.   case 4: k1 ^= (uint64_t)(tail[ 3]) << 24;
  485.   case 3: k1 ^= (uint64_t)(tail[ 2]) << 16;
  486.   case 2: k1 ^= (uint64_t)(tail[ 1]) << 8;
  487.   case 1: k1 ^= (uint64_t)(tail[ 0]) << 0;
  488.            k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1;
  489.   };
  490.   //----------
  491.   // finalization
  492.   h1 ^= len; h2 ^= len;
  493.   h1 += h2;
  494.   h2 += h1;
  495.   h1 = fmix64(h1);
  496.   h2 = fmix64(h2);
  497.   h1 += h2;
  498.   h2 += h1;
  499.   ((uint64_t*)out)[0] = h1;
  500.   ((uint64_t*)out)[1] = h2;
  501. }
  502. //===============
  503. u4* hash(u1* text,u8 len){
  504. u4* res=ma(16);
  505. MurmurHash3_x86_128(text,len,0x12345678,res);
  506. re res;
  507. }
Advertisement
Add Comment
Please, Sign In to add comment