public Index(File file, int keySize) throws IOException { capacity = (pageSize - Page.START_OFFSET) / (keySize + valueSize); RandomAccessFile raf = new RandomAccessFile(file, "rw"); this.file = raf.getChannel(); settings = this.file.map(MapMode.READ_WRITE, 0, pageSize); if (this.file.size() == pageSize) { this.keySize = keySize; settings.putInt(SIGNATURE, MAGIC); settings.putInt(KEYSIZE, keySize); nextPage = 1; root = allocate(true); root.n = 1; root.set(0, new byte[KEYSIZE], 0); root.write(); } else { if (settings.getInt(SIGNATURE) != MAGIC) throw new IllegalStateException("No Index file, magic is not " + MAGIC); this.keySize = settings.getInt(KEYSIZE); if (keySize != 0 && this.keySize != keySize) throw new IllegalStateException("Invalid key size for Index file. The file is " + this.keySize + " and was expected to be " + this.keySize); root = getPage(1); nextPage = (int) (this.file.size() / pageSize); } }
public Index(File file, int keySize) throws IOException { capacity = (pageSize - Page.START_OFFSET) / (keySize + valueSize); RandomAccessFile raf = new RandomAccessFile(file, "rw"); this.file = raf.getChannel(); settings = this.file.map(MapMode.READ_WRITE, 0, pageSize); if (this.file.size() == pageSize) { this.keySize = keySize; settings.putInt(SIGNATURE, MAGIC); settings.putInt(KEYSIZE, keySize); nextPage = 1; root = allocate(true); root.n = 1; root.set(0, new byte[KEYSIZE], 0); root.write(); } else { if (settings.getInt(SIGNATURE) != MAGIC) throw new IllegalStateException("No Index file, magic is not " + MAGIC); this.keySize = settings.getInt(KEYSIZE); if (keySize != 0 && this.keySize != keySize) throw new IllegalStateException("Invalid key size for Index file. The file is " + this.keySize + " and was expected to be " + this.keySize); root = getPage(1); nextPage = (int) (this.file.size() / pageSize); } }
public Index(File file, int keySize) throws IOException { capacity = (pageSize - Page.START_OFFSET) / (keySize + valueSize); @SuppressWarnings("resource") RandomAccessFile raf = new RandomAccessFile(file, "rw"); this.file = raf.getChannel(); settings = this.file.map(MapMode.READ_WRITE, 0, pageSize); if (this.file.size() == pageSize) { this.keySize = keySize; settings.putInt(SIGNATURE, MAGIC); settings.putInt(KEYSIZE, keySize); nextPage = 1; root = allocate(true); root.n = 1; root.set(0, new byte[KEYSIZE], 0); root.write(); } else { if (settings.getInt(SIGNATURE) != MAGIC) throw new IllegalStateException("No Index file, magic is not " + MAGIC); this.keySize = settings.getInt(KEYSIZE); if (keySize != 0 && this.keySize != keySize) throw new IllegalStateException("Invalid key size for Index file. The file is " + this.keySize + " and was expected to be " + this.keySize); root = getPage(1); nextPage = (int) (this.file.size() / pageSize); } }
void insert(byte[] k, long v) throws IOException { if (n == capacity) { int t = capacity / 2; Page left = allocate(leaf); Page right = allocate(leaf); left.copyFrom(this, 0, t); left.n = t; right.copyFrom(this, t, capacity - t); right.n = capacity - t; leaf = false; set(0, left.k(0), left.number); set(1, right.k(0), right.number); n = 2; left.write(); right.write(); } insertNonFull(k, v); }
void insert(byte[] k, long v) throws IOException { if (n == capacity) { int t = capacity / 2; Page left = allocate(leaf); Page right = allocate(leaf); left.copyFrom(this, 0, t); left.n = t; right.copyFrom(this, t, capacity - t); right.n = capacity - t; leaf = false; set(0, left.k(0), left.number); set(1, right.k(0), right.number); n = 2; left.write(); right.write(); } insertNonFull(k, v); }
void insert(byte[] k, long v) throws IOException { if (n == capacity) { int t = capacity / 2; Page left = allocate(leaf); Page right = allocate(leaf); left.copyFrom(this, 0, t); left.n = t; right.copyFrom(this, t, capacity - t); right.n = capacity - t; leaf = false; set(0, left.k(0), left.number); set(1, right.k(0), right.number); n = 2; left.write(); right.write(); } insertNonFull(k, v); }
Page left = child; int t = capacity / 2; Page right = allocate(child.leaf); right.copyFrom(left, t, capacity - t); right.n = capacity - t;
Page left = child; int t = capacity / 2; Page right = allocate(child.leaf); right.copyFrom(left, t, capacity - t); right.n = capacity - t;
Page left = child; int t = capacity / 2; Page right = allocate(child.leaf); right.copyFrom(left, t, capacity - t); right.n = capacity - t;