Search in sources :

Example 1 with B_TreeBuilder

use of suite.btree.impl.B_TreeBuilder in project suite by stupidsing.

the class B_TreeTest method testAccess.

@Test
public void testAccess() throws IOException {
    int pageSize = 4096;
    Path path = Constants.tmp("b_tree-file");
    Files.deleteIfExists(path);
    B_TreeBuilder<Integer, String> builder = new B_TreeBuilder<>(serialize.int_, serialize.string(16));
    shuffleNumbers();
    try (JournalledPageFile jpf = JournalledFileFactory.journalled(path, pageSize);
        B_Tree<Integer, String> b_tree = builder.build(jpf, comparator, pageSize)) {
        b_tree.create();
        testStep0(b_tree);
        jpf.commit();
        jpf.sync();
    }
    shuffleNumbers();
    try (JournalledPageFile jpf = JournalledFileFactory.journalled(path, pageSize);
        B_Tree<Integer, String> b_tree = builder.build(jpf, comparator, pageSize)) {
        testStep1(b_tree);
        jpf.commit();
        jpf.sync();
    }
    try (JournalledPageFile jpf = JournalledFileFactory.journalled(path, pageSize);
        B_Tree<Integer, String> b_tree = builder.build(jpf, comparator, pageSize)) {
        testStep2(b_tree);
        jpf.commit();
        jpf.sync();
        jpf.applyJournal();
    }
}
Also used : Path(java.nio.file.Path) B_TreeBuilder(suite.btree.impl.B_TreeBuilder) JournalledPageFile(suite.file.JournalledPageFile) Test(org.junit.Test)

Example 2 with B_TreeBuilder

use of suite.btree.impl.B_TreeBuilder in project suite by stupidsing.

the class B_TreeTest method testDump.

@Test
public void testDump() throws IOException {
    int pageSize = 4096;
    Path path = Constants.tmp("b_tree-dump");
    Files.deleteIfExists(path);
    B_TreeBuilder<Integer, String> builder = new B_TreeBuilder<>(serialize.int_, serialize.string(16));
    try (JournalledPageFile jpf = JournalledFileFactory.journalled(path, pageSize);
        B_Tree<Integer, String> b_tree = builder.build(jpf, comparator, pageSize)) {
        b_tree.create();
        for (int i = 0; i < 32; i++) b_tree.put(i, Integer.toString(i));
        b_tree.dump(System.out);
        System.out.println(To.list(b_tree.keys(3, 10)));
        jpf.commit();
    }
}
Also used : Path(java.nio.file.Path) B_TreeBuilder(suite.btree.impl.B_TreeBuilder) JournalledPageFile(suite.file.JournalledPageFile) Test(org.junit.Test)

Example 3 with B_TreeBuilder

use of suite.btree.impl.B_TreeBuilder in project suite by stupidsing.

the class B_TreeTest method testInsertPerformance.

@Test
public void testInsertPerformance() throws IOException {
    int nKeys = 16384;
    keys = Ints_.toArray(nKeys, i -> i);
    int pageSize = 4096;
    Path path = Constants.tmp("b_tree-file");
    for (int i = 0; i < nKeys; i++) {
        int j = random.nextInt(nKeys);
        Integer temp = keys[i];
        keys[i] = keys[j];
        keys[j] = temp;
    }
    Files.deleteIfExists(path);
    B_TreeBuilder<Integer, Bytes> builder = new B_TreeBuilder<>(serialize.int_, serialize.bytes(64));
    try (JournalledPageFile jpf = JournalledFileFactory.journalled(path, pageSize);
        B_Tree<Integer, Bytes> b_tree = builder.build(jpf, comparator, 9999)) {
        new Profiler().profile(() -> {
            b_tree.create();
            for (int i = 0; i < nKeys; i++) {
                int key = keys[i];
                b_tree.put(key, To.bytes(Integer.toString(key)));
            }
            jpf.commit();
            jpf.sync();
        });
    }
}
Also used : Object_(suite.util.Object_) B_TreeBuilder(suite.btree.impl.B_TreeBuilder) Files(java.nio.file.Files) Constants(suite.Constants) Bytes(suite.primitive.Bytes) Profiler(suite.sample.Profiler) IOException(java.io.IOException) Random(java.util.Random) Test(org.junit.Test) To(suite.util.To) Serialize(suite.util.Serialize) JournalledPageFile(suite.file.JournalledPageFile) Pair(suite.adt.pair.Pair) Assert.assertNull(org.junit.Assert.assertNull) Ints_(suite.primitive.Ints_) Comparator(java.util.Comparator) Path(java.nio.file.Path) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) JournalledFileFactory(suite.file.impl.JournalledFileFactory) Path(java.nio.file.Path) Bytes(suite.primitive.Bytes) Profiler(suite.sample.Profiler) B_TreeBuilder(suite.btree.impl.B_TreeBuilder) JournalledPageFile(suite.file.JournalledPageFile) Test(org.junit.Test)

Aggregations

Path (java.nio.file.Path)3 Test (org.junit.Test)3 B_TreeBuilder (suite.btree.impl.B_TreeBuilder)3 JournalledPageFile (suite.file.JournalledPageFile)3 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Comparator (java.util.Comparator)1 Random (java.util.Random)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNull (org.junit.Assert.assertNull)1 Before (org.junit.Before)1 Constants (suite.Constants)1 Pair (suite.adt.pair.Pair)1 JournalledFileFactory (suite.file.impl.JournalledFileFactory)1 Bytes (suite.primitive.Bytes)1 Ints_ (suite.primitive.Ints_)1 Profiler (suite.sample.Profiler)1 Object_ (suite.util.Object_)1 Serialize (suite.util.Serialize)1 To (suite.util.To)1