10 fprint(2, "usage: fmtbloom [-s size] [-n nblocks | -N nhash] file\n");
15 threadmain(int argc, char *argv[])
19 vlong bits, size, size2;
33 nblocks = unittoull(EARGF(usage()));
38 nhash = unittoull(EARGF(usage()));
39 if(nhash > BloomMaxHash){
40 fprint(2, "maximum possible is -N %d", BloomMaxHash);
45 size = unittoull(ARGF());
59 part = initpart(file, ORDWR|ODIRECT);
61 sysfatal("can't open partition %s: %r", file);
67 sysfatal("bloom filter too small");
69 if(size > MaxBloomSize){
70 fprint(2, "warning: not using entire %,lld bytes; using only %,lld bytes\n",
71 size, (vlong)MaxBloomSize);
75 for(size2=1; size2<size; size2*=2)
78 fprint(2, "warning: size not a power of 2; only using %lldMB\n", size/1024/1024);
83 * no use for more than 32 bits per block
84 * shoot for less than 64 bits per block
87 while(size2*8 >= nblocks*64)
91 fprint(2, "warning: using only %lldMB - not enough blocks to warrant more\n",
96 * optimal is to use ln 2 times as many hash functions as we have bits per blocks.
98 bits = (8*size)/nblocks;
100 if(nhash > BloomMaxHash)
101 nhash = BloomMaxHash;
104 nhash = BloomMaxHash;
105 if(bloominit(&b, size, nil) < 0)
106 sysfatal("bloominit: %r");
109 nblocks = (8*size)/bits;
110 fprint(2, "fmtbloom: using %lldMB, %d hashes/score, best up to %,lld blocks\n", size, nhash, nblocks);
111 b.data = vtmallocz(size);
113 if(writebloom(&b) < 0)
114 sysfatal("writing %s: %r", file);