@Test public void generateSamplingBitSetBig() throws Exception { BitSet result = AnalyzeUtils.generateSamplingBitSet(1000000, 990000); assertEquals(result.cardinality(), 990000); assertTrue(result.length() < 1000000); result = AnalyzeUtils.generateSamplingBitSet(1000000000, 5000000); assertEquals(result.cardinality(), 5000000); assertTrue(result.length() < 1000000000); }
static public BitSet generateSamplingBitSet(int poolSize, int sampleSize) { int skip = 0, chosen = 0, curIndex = 0; BitSet bitSet = new BitSet(); if (poolSize <= 0 || sampleSize <= 0) { return bitSet; } if (sampleSize >= poolSize) { LOG.debug("sampling bit map has " + poolSize + " elements (100%)"); bitSet.set(0, poolSize); return bitSet; } skip = (poolSize / sampleSize) + 1; while (chosen < sampleSize) { bitSet.set(curIndex); chosen++; if (chosen == sampleSize) { break; } for (int i = 0; i < skip; ++i) { curIndex = nextClearBitModulo((++curIndex) % poolSize, poolSize, bitSet); if (curIndex == -1) { throw new IllegalArgumentException( "Trying to sample more than pool size " + "(pool size " + poolSize + ", sampling size " + sampleSize); } } } LOG.debug("sampling bit map has " + chosen + " elements:" + bitSet.toString()); return bitSet; }
AnalyzeUtils { static public BitSet generateSamplingBitSet(int poolSize, int sampleSize) { int skip = 0, chosen = 0, curIndex = 0; BitSet bitSet = new BitSet(); if (poolSize <= 0 || sampleSize <= 0) { return bitSet; } if (sampleSize >= poolSize) { LOG.debug("sampling bit map has " + poolSize + " elements (100%)"); bitSet.set(0, poolSize); return bitSet; } skip = (poolSize / sampleSize) + 1; while (chosen < sampleSize) { bitSet.set(curIndex); chosen++; if (chosen == sampleSize) { break; } for (int i = 0; i < skip; ++i) { curIndex = nextClearBitModulo((++curIndex) % poolSize, poolSize, bitSet); if (curIndex == -1) { throw new IllegalArgumentException( "Trying to sample more than pool size " + "(pool size " + poolSize + ", sampling size " + sampleSize); } } } LOG.debug("sampling bit map has " + chosen + " elements:" + bitSet.toString()); return bitSet; } }
AnalyzeUtils { static public BitSet generateSamplingBitSet(int poolSize, int sampleSize) { int skip = 0, chosen = 0, curIndex = 0; BitSet bitSet = new BitSet(); if (poolSize <= 0 || sampleSize <= 0) { return bitSet; } if (sampleSize >= poolSize) { LOG.debug("sampling bit map has " + poolSize + " elements (100%)"); bitSet.set(0, poolSize); return bitSet; } skip = (poolSize / sampleSize) + 1; while (chosen < sampleSize) { bitSet.set(curIndex); chosen++; if (chosen == sampleSize) { break; } for (int i = 0; i < skip; ++i) { curIndex = nextClearBitModulo((++curIndex) % poolSize, poolSize, bitSet); if (curIndex == -1) { throw new IllegalArgumentException( "Trying to sample more than pool size " + "(pool size " + poolSize + ", sampling size " + sampleSize); } } } LOG.debug("sampling bit map has " + chosen + " elements:" + bitSet.toString()); return bitSet; }  }
AnalyzeUtils { static public BitSet generateSamplingBitSet(int poolSize, int sampleSize) { int skip = 0, chosen = 0, curIndex = 0; BitSet bitSet = new BitSet(); if (poolSize <= 0 || sampleSize <= 0) { return bitSet; } if (sampleSize >= poolSize) { LOG.debug("sampling bit map has " + poolSize + " elements (100%)"); bitSet.set(0, poolSize); return bitSet; } skip = (poolSize / sampleSize) + 1; while (chosen < sampleSize) { bitSet.set(curIndex); chosen++; if (chosen == sampleSize) { break; } for (int i = 0; i < skip; ++i) { curIndex = nextClearBitModulo((++curIndex) % poolSize, poolSize, bitSet); if (curIndex == -1) { throw new IllegalArgumentException( "Trying to sample more than pool size " + "(pool size " + poolSize + ", sampling size " + sampleSize); } } } LOG.debug("sampling bit map has " + chosen + " elements:" + bitSet.toString()); return bitSet; }  static List<Fragment> getSampleFragments(List<Fragment> fragments,
                                                    RequestContext context); static BitSet generateSamplingBitSet(int poolSize, int sampleSize); }
AnalyzeUtils { static public BitSet generateSamplingBitSet(int poolSize, int sampleSize) { int skip = 0, chosen = 0, curIndex = 0; BitSet bitSet = new BitSet(); if (poolSize <= 0 || sampleSize <= 0) { return bitSet; } if (sampleSize >= poolSize) { LOG.debug("sampling bit map has " + poolSize + " elements (100%)"); bitSet.set(0, poolSize); return bitSet; } skip = (poolSize / sampleSize) + 1; while (chosen < sampleSize) { bitSet.set(curIndex); chosen++; if (chosen == sampleSize) { break; } for (int i = 0; i < skip; ++i) { curIndex = nextClearBitModulo((++curIndex) % poolSize, poolSize, bitSet); if (curIndex == -1) { throw new IllegalArgumentException( "Trying to sample more than pool size " + "(pool size " + poolSize + ", sampling size " + sampleSize); } } } LOG.debug("sampling bit map has " + chosen + " elements:" + bitSet.toString()); return bitSet; }  static List<Fragment> getSampleFragments(List<Fragment> fragments,
                                                    RequestContext context); static BitSet generateSamplingBitSet(int poolSize, int sampleSize);  }