提交 bc08e313 authored 作者: Noel Grandin's avatar Noel Grandin

add entries iterator to ValueHashMap

speeds up this query by about 30%
上级 e241c7b6
......@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
/**
* This class represents a simple SELECT statement.
......@@ -420,10 +421,9 @@ public class Select extends Query {
groupByData.put(defaultGroup,
new Object[Math.max(exprToIndexInGroupByData.size(), expressions.size())]);
}
ArrayList<Value> keys = groupByData.keys();
for (Value v : keys) {
currentGroupsKey = (ValueArray) v;
currentGroupByExprData = groupByData.get(currentGroupsKey);
for (Map.Entry<Value, Object[]> entry : groupByData.entries()) {
currentGroupsKey = (ValueArray) entry.getKey();
currentGroupByExprData = entry.getValue();
Value[] keyValues = currentGroupsKey.getList();
Value[] row = new Value[columnCount];
for (int j = 0; groupIndex != null && j < groupIndex.length; j++) {
......
......@@ -6,7 +6,10 @@
package org.h2.util;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import org.h2.message.DbException;
import org.h2.mvstore.DataUtils;
import org.h2.value.Value;
import org.h2.value.ValueNull;
......@@ -189,6 +192,39 @@ public class ValueHashMap<V> extends HashBase {
return list;
}
public Iterable<Map.Entry<Value, V>> entries() {
return new EntryIterable();
}
private final class EntryIterable implements Iterable<Map.Entry<Value, V>> {
@Override
public Iterator<Map.Entry<Value, V>> iterator() {
return new EntryIterator();
}
}
private final class EntryIterator implements Iterator<Map.Entry<Value, V>> {
int keysIndex = -1;
@Override
public boolean hasNext() {
if (keysIndex >= keys.length)
return false;
do {
keysIndex++;
if (keysIndex >= keys.length)
return false;
if (keys[keysIndex] != null && keys[keysIndex] != ValueNull.DELETED)
return true;
} while (true);
}
@Override
public Map.Entry<Value, V> next() {
return new DataUtils.MapEntry<Value, V>(keys[keysIndex], values[keysIndex]);
}
}
/**
* Get the list of values.
*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论