Search in sources :

Example 1 with MutableInt

use of org.antlr.v4.misc.MutableInt in project antlr4 by tunnelvisionlabs.

the class ElementFrequenciesVisitor method combineMax.

/*
	 * Common
	 */
/**
 * Generate a frequency set as the union of two input sets. If an
 * element is contained in both sets, the value for the output will be
 * the maximum of the two input values.
 *
 * @param a The first set.
 * @param b The second set.
 * @return The union of the two sets, with the maximum value chosen
 * whenever both sets contain the same key.
 */
protected static FrequencySet<String> combineMax(FrequencySet<String> a, FrequencySet<String> b) {
    FrequencySet<String> result = combineAndClip(a, b, 1);
    for (Map.Entry<String, MutableInt> entry : a.entrySet()) {
        result.get(entry.getKey()).v = entry.getValue().v;
    }
    for (Map.Entry<String, MutableInt> entry : b.entrySet()) {
        MutableInt slot = result.get(entry.getKey());
        slot.v = Math.max(slot.v, entry.getValue().v);
    }
    return result;
}
Also used : MutableInt(org.antlr.v4.misc.MutableInt) Map(java.util.Map)

Example 2 with MutableInt

use of org.antlr.v4.misc.MutableInt in project antlr4 by antlr.

the class ElementFrequenciesVisitor method combineMax.

/*
	 * Common
	 */
/**
 * Generate a frequency set as the union of two input sets. If an
 * element is contained in both sets, the value for the output will be
 * the maximum of the two input values.
 *
 * @param a The first set.
 * @param b The second set.
 * @return The union of the two sets, with the maximum value chosen
 * whenever both sets contain the same key.
 */
protected static FrequencySet<String> combineMax(FrequencySet<String> a, FrequencySet<String> b) {
    FrequencySet<String> result = combineAndClip(a, b, 1);
    for (Map.Entry<String, MutableInt> entry : a.entrySet()) {
        result.get(entry.getKey()).v = entry.getValue().v;
    }
    for (Map.Entry<String, MutableInt> entry : b.entrySet()) {
        MutableInt slot = result.get(entry.getKey());
        slot.v = Math.max(slot.v, entry.getValue().v);
    }
    return result;
}
Also used : MutableInt(org.antlr.v4.misc.MutableInt) Map(java.util.Map)

Aggregations

Map (java.util.Map)2 MutableInt (org.antlr.v4.misc.MutableInt)2