Recently looking at interesting programming, found that the algorithm is really a good thing, hehe, I also wrote a simple demo
The code is specific as follows:
#include <stdio.h>#include<string.h>#include<unistd.h>#include<stdint.h>#include<fcntl.h>#include<sys/types.h>#include<sys/stat.h>#defineBsize 255#defineBufSize 4096Staticuint64_t arr[255] ={0};Staticuint64_t hash =0;voidWhash (Char*s) { intLen =strlen (s); inti =0, total =0; while(I <Len) { intindex = s[i]- +; if(Hash & (1<<index)) = =0) {Hash|= (1<<index); Arr[index]++; } Else{Arr[index]++; } I++; }}intBreadChar*file) { intFD = open (File,o_rdonly,0666); structStat St; CharBuf[bufsize] = {' /'}; if(FD = =-1) { return-1; } fstat (FD,&St); size_t Total=st.st_size; while(Total >0) { intleft =read (fd,buf,bufsize); if(Left <0) { Break; } whash (BUF); Total-=Left ; memset (BUF,' /', bufSize); } return 0;}intMainvoid) {printf ("bread =%d\n", Bread ("./SRY.C")); inti =0; for(; I < bsize;i++) { if(Arr[i] >0) {printf ("count (%c) =%d\n", i+ +, Arr[i]); } } return 0;}
The results of the operation are as follows:
[Email protected]:~/code_c_20160101/algorithm/str:./Srybread=0count ()=335Count (") =6Count (#) =9Count (%) =3Count (&) =2Count (') =4Count (() = atcount ())= atCount (*) =2Count (+) =9count (,)= OneCount (-) =4count (.)=TenCount (/) =3Count (0) = theCount (1) =4Count (2) =4Count (3) =2Count (4) =3Count (5) =4Count (6) =6Count (9) =1count (;)= -Count (<) = -Count (=) = +Count (>) =9count (D)=1count (L)=1count (N)=1count (O)=2count (R)=1count (S)=6count (Y)=1count ([)=7count (\)=4count (])=7count (_)=5Count (a)= -count (b)= -count (c)= -count (d)= incount (e)= -count (f)= -count (g)=1count (h)= Acount (i)= Acount (k)=1count (L)= atcount (m)=3count (N)= Acount (o)=Tencount (p)=4count (R)= tocount (s)= -count (t)= -count (U)= atcount (v)=2Count (W)=4count (x)=5count (y)=4count (z)=8count ({)= -Count (|) =1count (})= -
The number of times the Linux implementation has appeared for the text statistic letters (all printable characters)