public static Histogram constantRangeHistogram(Histogram hist,
			Map<String, ConstantRange> cRanges) {
		if (Double.compare(hist.recordsOutput(), 1.0) < 0)
			return new Histogram(hist.fields());

		Histogram crHist = new Histogram(hist);
		for (String fld : cRanges.keySet()) {
			Collection<Bucket> crBkts = new ArrayList<Bucket>(crHist.buckets(
					fld).size());
			ConstantRange cr = cRanges.get(fld);
			double freqSum = 0.0;
			for (Bucket bkt : crHist.buckets(fld)) {
				Bucket crBkt = constantRangeBucket(bkt, cr);
				if (crBkt != null) {
					crBkts.add(crBkt);
					freqSum += crBkt.frequency();
				}
			}
			if (Double.compare(freqSum, 1.0) < 0) // no bucket in range
				return new Histogram(hist.fields());
			double crReduction = freqSum / crHist.recordsOutput();
			if (Double.compare(crReduction, 1.0) == 0)
				continue;
			// update this field's buckets
			crHist.setBuckets(fld, crBkts);
			/*
			 * update other fields' buckets to ensure that all fields have the
			 * same total frequencies.
			 */
			for (String restFld : crHist.fields()) {
				if (restFld.equals(fld))
					continue;
				Collection<Bucket> restBkts = new ArrayList<Bucket>(crHist
						.buckets(restFld).size());
				for (Bucket bkt : crHist.buckets(restFld)) {
					double restFreq = bkt.frequency() * crReduction;
					if (Double.compare(restFreq, 1.0) < 0)
						continue;
					double restDistVals = Math.min(bkt.distinctValues(),
							restFreq);
					Bucket restBkt = new Bucket(bkt.valueRange(), restFreq,
							restDistVals, bkt.valuePercentiles());
					restBkts.add(restBkt);
				}
				crHist.setBuckets(restFld, restBkts);
			}
		}
		return syncHistogram(crHist);
	}
public static Histogram constantRangeHistogram ( Histogram hist , Map < String , ConstantRange > cRanges ) { if ( Double . compare ( hist . recordsOutput ( ) , 1.0 ) < 0 ) return new Histogram ( hist . fields ( ) ) ; Histogram crHist = new Histogram ( hist ) ; for ( String fld : cRanges . keySet ( ) ) { Collection < Bucket > crBkts = new ArrayList < Bucket > ( crHist . buckets ( fld ) . size ( ) ) ; ConstantRange cr = cRanges . get ( fld ) ; double freqSum = 0.0 ; for ( Bucket bkt : crHist . buckets ( fld ) ) { Bucket crBkt = constantRangeBucket ( bkt , cr ) ; if ( crBkt != null ) { crBkts . add ( crBkt ) ; freqSum += crBkt . frequency ( ) ; } } if ( Double . compare ( freqSum , 1.0 ) < 0 ) return new Histogram ( hist . fields ( ) ) ; double crReduction = freqSum / crHist . recordsOutput ( ) ; if ( Double . compare ( crReduction , 1.0 ) == 0 ) continue ; crHist . setBuckets ( fld , crBkts ) ; for ( String restFld : crHist . fields ( ) ) { if ( restFld . equals ( fld ) ) continue ; Collection < Bucket > restBkts = new ArrayList < Bucket > ( crHist . buckets ( restFld ) . size ( ) ) ; for ( Bucket bkt : crHist . buckets ( restFld ) ) { double restFreq = bkt . frequency ( ) * crReduction ; if ( Double . compare ( restFreq , 1.0 ) < 0 ) continue ; double restDistVals = Math . min ( bkt . distinctValues ( ) , restFreq ) ; Bucket restBkt = new Bucket ( bkt . valueRange ( ) , restFreq , restDistVals , bkt . valuePercentiles ( ) ) ; restBkts . add ( restBkt ) ; } crHist . setBuckets ( restFld , restBkts ) ; } } return syncHistogram ( crHist ) ; }
Returns a histogram that, for each field, approximates the distribution
of values from the specified histogram falling within the specified
search range.

<p>
Assumes that:
<ul>
<li>Equality selection always finds matching records</li>
<li>Values in a bucket have the same frequency (uniform frequency)</li>
<li>Distributions of values in different fields are independent with each
other</li>
</ul>

@param hist
the input histogram
@param cRanges
a map from fields to search ranges
@return a histogram that, for each field, approximates the distribution
of values from the specified histogram falling within the
specified search range