public FuzzySet downsize(float targetMaxSaturation){int numBitsSet = filter.cardinality();FixedBitSet rightSizedBitSet = filter;int rightSizedBitSetSize = bloomSize;for (int i = 0; i < usableBitSetSizes.length; i++) {int candidateBitsetSize = usableBitSetSizes[i];float candidateSaturation = (float) numBitsSet/ (float) candidateBitsetSize;if (candidateSaturation <= targetMaxSaturation) {rightSizedBitSetSize = candidateBitsetSize;break;}}if (rightSizedBitSetSize < bloomSize) {rightSizedBitSet = new FixedBitSet(rightSizedBitSetSize + 1);int bitIndex = 0;do {bitIndex = filter.nextSetBit(bitIndex);if (bitIndex != DocIdSetIterator.NO_MORE_DOCS) {int downSizedBitIndex = bitIndex & rightSizedBitSetSize;rightSizedBitSet.set(downSizedBitIndex);bitIndex++;}} while ( (bitIndex >= 0)&&(bitIndex<=bloomSize));} else {return null;}return new FuzzySet(rightSizedBitSet,rightSizedBitSetSize, hashFunction);}

public virtual FuzzySet Downsize(float targetMaxSaturation){var numBitsSet = _filter.Cardinality();FixedBitSet rightSizedBitSet;var rightSizedBitSetSize = _bloomSize;foreach (var candidateBitsetSize in from candidateBitsetSize in _usableBitSetSizeslet candidateSaturation = numBitsSet /(float) candidateBitsetSizewhere candidateSaturation <= targetMaxSaturationselect candidateBitsetSize){rightSizedBitSetSize = candidateBitsetSize;break;}if (rightSizedBitSetSize < _bloomSize){rightSizedBitSet = new FixedBitSet(rightSizedBitSetSize + 1);var bitIndex = 0;do{bitIndex = _filter.NextSetBit(bitIndex);if (bitIndex < 0) continue;var downSizedBitIndex = bitIndex & rightSizedBitSetSize;rightSizedBitSet.Set(downSizedBitIndex);bitIndex++;} while ((bitIndex >= 0) && (bitIndex <= _bloomSize));}else{return null;}return new FuzzySet(rightSizedBitSet, rightSizedBitSetSize, _hashFunction);}
