From 6e60ee82fd5e8a4e18540b474ef72b2ffdec7469 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2011 15:04:33 +0400 Subject: [PATCH] cleanup --- .../com/intellij/util/io/IntToIntBtree.java | 19 ++++++++----- .../util/io/PersistentBTreeEnumerator.java | 27 ++++++++++--------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/platform/util/src/com/intellij/util/io/IntToIntBtree.java b/platform/util/src/com/intellij/util/io/IntToIntBtree.java index 40df880bb5f3..8671e4b92a43 100644 --- a/platform/util/src/com/intellij/util/io/IntToIntBtree.java +++ b/platform/util/src/com/intellij/util/io/IntToIntBtree.java @@ -27,7 +27,7 @@ abstract class IntToIntBtree { private final TIntObjectHashMap pagesCache = new TIntObjectHashMap(100); private boolean isLarge = true; - public IntToIntBtree(int _pageSize, int rootAdress) { + public IntToIntBtree(int _pageSize, int rootAdress, boolean initial) { pageSize = _pageSize; buffer = new byte[_pageSize]; root = new BtreeIndexNodeView(this); @@ -37,19 +37,24 @@ abstract class IntToIntBtree { assert i < Short.MAX_VALUE && i % 2 == 0; maxInteriorNodes = (short)i; pagesCount = 1; + + if (initial) { + root.setIndexLeaf(true); + root.sync(); + } } - protected abstract int allocPage(); + protected abstract int allocEmptyPage(); private int nextPage() { - int address = allocPage(); + int address = allocEmptyPage(); ++pagesCount; return address; } - protected abstract void saveBytes(int address, byte[] buffer, int offset, int length); + protected abstract void savePage(int address, byte[] pageBuffer); - protected abstract void loadBytes(int address, byte[] buffer, int offset, int length); + protected abstract void loadPageContent(int address, byte[] pageBuffer); public int get(int key) { BtreeIndexNodeView currentIndexNode = new BtreeIndexNodeView(this); @@ -173,7 +178,7 @@ abstract class IntToIntBtree { buffer = bytes; } else { buffer = new byte[btree.pageSize]; - btree.loadBytes(address, buffer, 0, btree.pageSize); + btree.loadPageContent(address, buffer); btree.pagesCache.put(address, buffer); } } @@ -188,7 +193,7 @@ abstract class IntToIntBtree { void sync() { if (buffer != null) { - btree.saveBytes(address, buffer, 0, buffer.length); + btree.savePage(address, buffer); } } diff --git a/platform/util/src/com/intellij/util/io/PersistentBTreeEnumerator.java b/platform/util/src/com/intellij/util/io/PersistentBTreeEnumerator.java index 52445e3d2db1..c24a013b885f 100644 --- a/platform/util/src/com/intellij/util/io/PersistentBTreeEnumerator.java +++ b/platform/util/src/com/intellij/util/io/PersistentBTreeEnumerator.java @@ -45,25 +45,27 @@ public class PersistentBTreeEnumerator extends PersistentEnumeratorBase extends PersistentEnumeratorBase extends PersistentEnumeratorBase extends PersistentEnumeratorBase