Search in sources :

Example 11 with MemoryCMARW

use of io.questdb.cairo.vm.api.MemoryCMARW in project questdb by bluestreak01.

the class BinarySearchTest method testFindForwardBeforeRange.

@Test
public void testFindForwardBeforeRange() throws Exception {
    assertMemoryLeak(() -> {
        try (Path path = new Path()) {
            path.of(root).concat("binsearch.d").$();
            try (MemoryCMARW appendMem = Vm.getSmallCMARWInstance(FilesFacadeImpl.INSTANCE, path, MemoryTag.MMAP_DEFAULT)) {
                for (int i = 0; i < 100; i++) {
                    for (int j = 0; j < 3; j++) {
                        appendMem.putLong(i);
                    }
                }
                long max = 100 * 3 - 1;
                try (MemoryMR mem = Vm.getMRInstance(FilesFacadeImpl.INSTANCE, path, 400 * Long.BYTES, MemoryTag.MMAP_DEFAULT)) {
                    long index = BinarySearch.find(mem, -20, 0, max, BinarySearch.SCAN_DOWN);
                    Assert.assertEquals(-1, index);
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) MemoryCMARW(io.questdb.cairo.vm.api.MemoryCMARW) MemoryMR(io.questdb.cairo.vm.api.MemoryMR) Test(org.junit.Test)

Aggregations

MemoryCMARW (io.questdb.cairo.vm.api.MemoryCMARW)11 Path (io.questdb.std.str.Path)10 Test (org.junit.Test)8 MemoryMR (io.questdb.cairo.vm.api.MemoryMR)2 Gson (com.google.gson.Gson)1 Record (io.questdb.cairo.sql.Record)1 RecordCursor (io.questdb.cairo.sql.RecordCursor)1 MemoryCMRImpl (io.questdb.cairo.vm.MemoryCMRImpl)1 LPSZ (io.questdb.std.str.LPSZ)1