LUCENE-3468: Replaced last() and remove() with pollLast() in FirstPassGroupingCollector

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1177008 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Martijn van Groningen 2011-09-28 18:40:22 +00:00
parent 534d8abed0
commit 7cbcf2a2de
3 changed files with 13 additions and 28 deletions

View File

@ -0,0 +1,11 @@
Grouping Module Change Log
For more information on past and future Lucene versions, please see:
http://s.apache.org/luceneversions
======================= Trunk (not yet released) =======================
Optimizations
LUCENE-3468: Replaced last() and remove() with pollLast() in
FirstPassGroupingCollector (Martijn van Groningen)

View File

@ -213,9 +213,7 @@ abstract public class AbstractFirstPassGroupingCollector<GROUP_VALUE_TYPE> exten
// We already tested that the document is competitive, so replace // We already tested that the document is competitive, so replace
// the bottom group with this new group. // the bottom group with this new group.
final CollectedSearchGroup<GROUP_VALUE_TYPE> bottomGroup = orderedGroups.pollLast();
// java 6-only: final CollectedSearchGroup bottomGroup = orderedGroups.pollLast();
final CollectedSearchGroup<GROUP_VALUE_TYPE> bottomGroup = pollLast();
assert orderedGroups.size() == topNGroups -1; assert orderedGroups.size() == topNGroups -1;
groupMap.remove(bottomGroup.groupValue); groupMap.remove(bottomGroup.groupValue);
@ -351,13 +349,5 @@ abstract public class AbstractFirstPassGroupingCollector<GROUP_VALUE_TYPE> exten
*/ */
protected abstract GROUP_VALUE_TYPE copyDocGroupValue(GROUP_VALUE_TYPE groupValue, GROUP_VALUE_TYPE reuse); protected abstract GROUP_VALUE_TYPE copyDocGroupValue(GROUP_VALUE_TYPE groupValue, GROUP_VALUE_TYPE reuse);
protected CollectedSearchGroup<GROUP_VALUE_TYPE> pollLast() {
// java 6-only: final CollectedSearchGroup bottomGroup = orderedGroups.pollLast();
final CollectedSearchGroup<GROUP_VALUE_TYPE> bottomGroup = orderedGroups.last();
orderedGroups.remove(bottomGroup);
return bottomGroup;
}
} }

View File

@ -666,7 +666,7 @@ public class Grouping {
} }
sort = sort == null ? Sort.RELEVANCE : sort; sort = sort == null ? Sort.RELEVANCE : sort;
firstPass = new TermFirstPassGroupingCollectorJava6(groupBy, sort, actualGroupsToFind); firstPass = new TermFirstPassGroupingCollector(groupBy, sort, actualGroupsToFind);
return firstPass; return firstPass;
} }
@ -1013,22 +1013,6 @@ public class Grouping {
filler = docValues.getValueFiller(); filler = docValues.getValueFiller();
mval = filler.getValue(); mval = filler.getValue();
} }
@Override
protected CollectedSearchGroup<MutableValue> pollLast() {
return orderedGroups.pollLast();
}
}
static class TermFirstPassGroupingCollectorJava6 extends TermFirstPassGroupingCollector {
public TermFirstPassGroupingCollectorJava6(String groupField, Sort groupSort, int topNGroups) throws IOException {
super(groupField, groupSort, topNGroups);
}
@Override
protected CollectedSearchGroup<BytesRef> pollLast() {
return orderedGroups.pollLast();
}
} }
static class FunctionSecondPassGroupingCollector extends AbstractSecondPassGroupingCollector<MutableValue> { static class FunctionSecondPassGroupingCollector extends AbstractSecondPassGroupingCollector<MutableValue> {