public boolean hasNext() { try { if (leaf) return rover < n; while (i == null || i.hasNext() == false) { int c = (int) c(rover++); i = getPage(c).iterator(); } return i.hasNext(); } catch (IOException e) { throw new RuntimeException(e); } }
public boolean hasNext() { try { if (leaf) return rover < n; while (i == null || i.hasNext() == false) { int c = (int) c(rover++); i = getPage(c).iterator(); } return i.hasNext(); } catch (IOException e) { throw new RuntimeException(e); } }
public boolean hasNext() { try { if (leaf) return rover < n; else { while (i == null || i.hasNext() == false) { int c = (int) c(rover++); i = getPage(c).iterator(); } return i.hasNext(); } } catch (IOException e) { throw new RuntimeException(e); } }
public void toString(StringBuilder sb, String indent) throws IOException { for (int i = 0; i < n; i++) { sb.append(String.format("%s %02d:%02d %20s %s %d%n", indent, number, i, hex(k(i), 0, 4), leaf ? "==" : "->", c(i))); if (!leaf) { long c = c(i); Page sub = getPage((int) c); sub.toString(sb, indent + " "); } } }
public void toString(StringBuilder sb, String indent) throws IOException { for (int i = 0; i < n; i++) { sb.append(String.format("%s %02d:%02d %20s %s %d%n", indent, number, i, hex(k(i), 0, 4), leaf ? "==" : "->", c(i))); if (!leaf) { long c = c(i); Page sub = getPage((int) c); sub.toString(sb, indent + " "); } } }
public void toString( StringBuilder sb, String indent ) throws IOException { for (int i = 0; i < n; i++) { sb.append(String.format("%s %02d:%02d %20s %s %d\n", indent, number, i, hex(k(i), 0, 4), leaf ? "==" : "->", c(i))); if (! leaf ) { long c = c(i); Page sub = getPage((int)c); sub.toString(sb,indent+" "); } } }
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); } }
long search(byte[] k) throws Exception { int cmp = 0; int i = n - 1; while (i >= 0 && (cmp = compare(k, i)) < 0) i--; if (leaf) { if (cmp != 0) return -1; return c(i); } long value = c(i); Page child = getPage((int) value); return child.search(k); }
long search(byte[] k) throws Exception { int cmp = 0; int i = n - 1; while (i >= 0 && (cmp = compare(k, i)) < 0) i--; if (leaf) { if (cmp != 0) return -1; return c(i); } long value = c(i); Page child = getPage((int) value); return child.search(k); }
long search(byte[] k) throws Exception { int cmp = 0; int i = n - 1; while (i >= 0 && (cmp = compare(k, i)) < 0) i--; if (leaf) { if (cmp != 0) return -1; else return c(i); } else { long value = c(i); Page child = getPage((int) value); return child.search(k); } }
} else { long value = c(i); Page child = getPage((int) value);
} else { long value = c(i); Page child = getPage((int) value);
} else { long value = c(i); Page child = getPage((int) value);