提交 ab5883c5 authored 作者: andrei's avatar andrei

code review 3

上级 55b07c4c
...@@ -14,13 +14,13 @@ import java.util.Iterator; ...@@ -14,13 +14,13 @@ import java.util.Iterator;
* @param <V> the value type * @param <V> the value type
*/ */
public final class Cursor<K, V> implements Iterator<K> { public final class Cursor<K, V> implements Iterator<K> {
private final K to; private final K to;
private CursorPos cursorPos; private CursorPos cursorPos;
private CursorPos keeper; private CursorPos keeper;
private K current; private K current;
private K last; private K last;
private V lastValue; private V lastValue;
private Page lastPage; private Page lastPage;
public Cursor(Page root, K from) { public Cursor(Page root, K from) {
this(root, from, null); this(root, from, null);
......
...@@ -941,7 +941,7 @@ public final class DataUtils { ...@@ -941,7 +941,7 @@ public final class DataUtils {
* @return the parsed value * @return the parsed value
* @throws IllegalStateException if parsing fails * @throws IllegalStateException if parsing fails
*/ */
public static long readHexLong(Map<String,?> map, String key, long defaultValue) { public static long readHexLong(Map<String, ?> map, String key, long defaultValue) {
Object v = map.get(key); Object v = map.get(key);
if (v == null) { if (v == null) {
return defaultValue; return defaultValue;
...@@ -1005,7 +1005,7 @@ public final class DataUtils { ...@@ -1005,7 +1005,7 @@ public final class DataUtils {
* @return the parsed value * @return the parsed value
* @throws IllegalStateException if parsing fails * @throws IllegalStateException if parsing fails
*/ */
public static int readHexInt(Map<String,?> map, String key, int defaultValue) { public static int readHexInt(Map<String, ?> map, String key, int defaultValue) {
Object v = map.get(key); Object v = map.get(key);
if (v == null) { if (v == null) {
return defaultValue; return defaultValue;
......
...@@ -172,7 +172,7 @@ public class FreeSpaceBitSet { ...@@ -172,7 +172,7 @@ public class FreeSpaceBitSet {
if (cardinality == 0) { if (cardinality == 0) {
return 0; return 0;
} }
return (int)(100L * cardinality / set.length()); return Math.max(1, (int)(100L * cardinality / set.length()));
} }
/** /**
......
...@@ -39,20 +39,20 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -39,20 +39,20 @@ public class MVMap<K, V> extends AbstractMap<K, V>
/** /**
* Reference to the current root page. * Reference to the current root page.
*/ */
private final AtomicReference<RootReference> root; private final AtomicReference<RootReference> root;
private int id; private int id;
private long createVersion; private long createVersion;
private final DataType keyType; private final DataType keyType;
private final DataType valueType; private final DataType valueType;
/** /**
* Whether the map is closed. Volatile so we don't accidentally write to a * Whether the map is closed. Volatile so we don't accidentally write to a
* closed map in multithreaded mode. * closed map in multithreaded mode.
*/ */
private volatile boolean closed; private volatile boolean closed;
private boolean readOnly; private boolean readOnly;
private boolean isVolatile; private boolean isVolatile;
/** /**
* This designates the "last stored" version for a store which was * This designates the "last stored" version for a store which was
...@@ -72,7 +72,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -72,7 +72,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
// constructor for cloneIt() // constructor for cloneIt()
protected MVMap(MVMap<K,V> source) { protected MVMap(MVMap<K, V> source) {
this(source.store, source.keyType, source.valueType, source.id, source.createVersion, this(source.store, source.keyType, source.valueType, source.id, source.createVersion,
new AtomicReference<>(source.root.get())); new AtomicReference<>(source.root.get()));
} }
...@@ -93,7 +93,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -93,7 +93,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
this.root = root; this.root = root;
} }
protected MVMap<K,V> cloneIt() { protected MVMap<K, V> cloneIt() {
return new MVMap<>(this); return new MVMap<>(this);
} }
...@@ -1356,7 +1356,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1356,7 +1356,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
@Override @Override
public Builder<K,V> valueType(DataType dataType) { public Builder<K, V> valueType(DataType dataType) {
setValueType(dataType); setValueType(dataType);
return this; return this;
} }
......
...@@ -197,7 +197,7 @@ public final class MVStore { ...@@ -197,7 +197,7 @@ public final class MVStore {
* The map of temporarily freed storage space caused by freed pages. * The map of temporarily freed storage space caused by freed pages.
* It contains the number of freed entries per chunk. * It contains the number of freed entries per chunk.
*/ */
private final Map<Integer,Chunk> freedPageSpace = new HashMap<>(); private final Map<Integer, Chunk> freedPageSpace = new HashMap<>();
/** /**
* The metadata map. Write access to this map needs to be synchronized on * The metadata map. Write access to this map needs to be synchronized on
...@@ -524,10 +524,10 @@ public final class MVStore { ...@@ -524,10 +524,10 @@ public final class MVStore {
return map; return map;
} }
public <K,V> MVMap<K,V> getMap(int id) { public <K, V> MVMap<K,V> getMap(int id) {
checkOpen(); checkOpen();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
MVMap<K,V> map = (MVMap<K, V>) maps.get(id); MVMap<K, V> map = (MVMap<K, V>) maps.get(id);
return map; return map;
} }
......
...@@ -736,7 +736,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -736,7 +736,7 @@ public class TestMVTableEngine extends TestBase {
conn.close(); conn.close();
long sizeNew = FileUtils.size(getBaseDir() + "/" + getTestName() long sizeNew = FileUtils.size(getBaseDir() + "/" + getTestName()
+ Constants.SUFFIX_MV_FILE); + Constants.SUFFIX_MV_FILE);
System.out.println("new: " + sizeNew + " old: " + sizeOld); println("new: " + sizeNew + " old: " + sizeOld);
// assertTrue("new: " + sizeNew + " old: " + sizeOld, sizeNew < sizeOld); // assertTrue("new: " + sizeNew + " old: " + sizeOld, sizeNew < sizeOld);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论