@@ -13,12 +13,16 @@ public class ProbabilityFuse {
1313 private static final int FUSE_SLOTS = FUSE_SEGMENT_COUNT + FUSE_ARITY - 1 ;
1414
1515 public static void main (String ... args ) {
16- for (int size = 100 ; size < 200000 ; size *= 1.1 ) {
16+ for (int size = 10 ; size < 500000 ; size *= 1.1 ) {
1717 System .out .print ("size " + size );
1818 double start = Math .max (0.1 , Math .min (0.8 , Math .log10 (size / 100 ) /4 ));
19- for (double factor = start + 0.1 ; factor > 0.0 ; factor -= 0.01 ) {
19+ double change = 0.1 ;
20+ int lastDirection = 1 ;
21+ double p = 0 ;
22+ double factor = start + 0.1 ;
23+ for (; factor > 0.0 ;) {
2024 int successCount = 0 ;
21- int testCount = 100 ;
25+ int testCount = Math . max ( 10 , 1000000 / size ) ;
2226 for (int seed = 0 ; seed < testCount ; seed ++) {
2327 long [] keys = new long [size ];
2428 RandomGenerator .createRandomUniqueListFast (keys , seed );
@@ -27,14 +31,50 @@ public static void main(String... args) {
2731 successCount ++;
2832 }
2933 }
30- double p = 1.0 * successCount / testCount ;
31- if (p > 0.9 || factor < 0.15 ) {
32- System .out .printf (Locale .ENGLISH , " %2.2f %2.2f" , factor , start );
34+ p = 1.0 * successCount / testCount ;
35+ if (p < 0.6 && factor > 0.1 ) {
36+ factor -= change ;
37+ if (lastDirection != -1 ) {
38+ lastDirection = -1 ;
39+ change = change / 2 ;
40+ }
41+ } else if (p > 0.61 ) {
42+ if (change < 0.0001 ) {
43+ break ;
44+ }
45+ if (factor > 0.8 ) {
46+ break ;
47+ }
48+ factor += change ;
49+ if (lastDirection != 1 ) {
50+ lastDirection = 1 ;
51+ change = change / 2 ;
52+ }
53+ } else {
3354 break ;
3455 }
56+ // System.out.printf(Locale.ENGLISH, " %2.5f %2.3f %2.20f\n", factor, p, change);
3557 }
36- System .out .println ();
58+ System .out .printf (Locale .ENGLISH , " %2.5f %2.3f\n " , factor , p );
59+ }
60+ }
61+
62+ /**
63+ * Get the fill rate for a certain size for a 95% probability.
64+ *
65+ * @param size the size
66+ * @return the factor
67+ */
68+ public static double getFactor (int size ) {
69+ if (size < 100 ) {
70+ return 0.13 ;
71+ }
72+ if (size > 170000 ) {
73+ return 0.879 ;
3774 }
75+ // this formula is weird, using cosine and log base 10, but it works.
76+ // it was found manually trying to fit the curve
77+ return Math .cos (Math .log10 (size ) / 1.2 - 4.7 ) / 2.7 + 0.5 ;
3878 }
3979
4080 public static boolean testMapping (long [] keys , double factor , long seed ) {
0 commit comments