提交 72e65d6f authored 作者: Andrei Tokar's avatar Andrei Tokar

consistency in using getKeyCount()

上级 f0fb7e00
......@@ -699,8 +699,8 @@ public class MVStoreTool {
@Override
public void write(WriteBuffer buff, Object[] obj, int len, boolean key) {
for (Object o : obj) {
write(buff, o);
for (int i = 0; i < len; i++) {
write(buff, obj[i]);
}
}
......@@ -717,12 +717,9 @@ public class MVStoreTool {
@Override
public void read(ByteBuffer buff, Object[] obj, int len, boolean key) {
for (int i = 0; i < obj.length; i++) {
for (int i = 0; i < len; i++) {
obj[i] = read(buff);
}
}
}
}
......@@ -468,7 +468,7 @@ public abstract class Page implements Cloneable
* @return the value or null
*/
int binarySearch(Object key) {
int low = 0, high = keys.length - 1;
int low = 0, high = getKeyCount() - 1;
// the cached index minus one, so that
// for the first time (when cachedCompare is 0),
// the default value is used
......@@ -550,7 +550,7 @@ public abstract class Page implements Cloneable
public abstract long getTotalCount();
/**
* Get the descendant counts for the given child.
* Get the number of key-value pairs for a given child.
*
* @param index the child index
* @return the descendant count
......@@ -621,7 +621,7 @@ public abstract class Page implements Cloneable
final void insertKey(int index, Object key) {
int keyCount = getKeyCount();
assert index <= keyCount : index + " > " + keyCount;
Object[] newKeys = new Object[keyCount + 1];
Object[] newKeys = createKeyStorage(keyCount + 1);
DataUtils.copyWithGap(keys, newKeys, keyCount, index);
keys = newKeys;
......@@ -647,7 +647,7 @@ public abstract class Page implements Cloneable
Object old = getKey(index);
addMemory(-MEMORY_POINTER - keyType.getMemory(old));
}
Object[] newKeys = new Object[keyCount - 1];
Object[] newKeys = createKeyStorage(keyCount - 1);
DataUtils.copyExcept(keys, newKeys, keyCount, index);
keys = newKeys;
}
......@@ -661,7 +661,7 @@ public abstract class Page implements Cloneable
private void read(ByteBuffer buff, int chunkId) {
int pageLength = buff.remaining() + 4; // size of int, since we've read page length already
int len = DataUtils.readVarInt(buff);
keys = new Object[len];
keys = createKeyStorage(len);
int type = buff.get();
if(isLeaf() != ((type & 1) == PAGE_TYPE_LEAF)) {
throw DataUtils.newIllegalStateException(
......@@ -728,7 +728,7 @@ public abstract class Page implements Cloneable
buff.put((byte) type);
writeChildren(buff, true);
int compressStart = buff.position();
map.getKeyType().write(buff, keys, getKeyCount(), true);
map.getKeyType().write(buff, keys, len, true);
writeValues(buff);
MVStore store = map.getStore();
int expLen = buff.position() - compressStart;
......@@ -889,10 +889,11 @@ public abstract class Page implements Cloneable
* @return memory in bytes
*/
protected int calculateMemory() {
int mem = keys.length * MEMORY_POINTER;
int keyCount = getKeyCount();
int mem = keyCount * MEMORY_POINTER;
DataType keyType = map.getKeyType();
for (Object key : keys) {
mem += keyType.getMemory(key);
for (int i = 0; i < keyCount; i++) {
mem += keyType.getMemory(keys[i]);
}
return mem;
}
......@@ -1472,6 +1473,7 @@ public abstract class Page implements Cloneable
long getCounts(int index) {
throw new UnsupportedOperationException();
}
@Override
public void setChild(int index, Page c) {
throw new UnsupportedOperationException();
......@@ -1510,6 +1512,7 @@ public abstract class Page implements Cloneable
}
}
}
@Override
public void insertNode(int index, Object key, Page childPage) {
throw new UnsupportedOperationException();
......@@ -1573,11 +1576,11 @@ public abstract class Page implements Cloneable
@Override
protected int calculateMemory() {
int mem = super.calculateMemory() + PAGE_LEAF_MEMORY +
values.length * MEMORY_POINTER;
int keyCount = getKeyCount();
int mem = super.calculateMemory() + PAGE_LEAF_MEMORY + keyCount * MEMORY_POINTER;
DataType valueType = map.getValueType();
for (Object value : values) {
mem += valueType.getMemory(value);
for (int i = 0; i < keyCount; i++) {
mem += valueType.getMemory(values[i]);
}
return mem;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论