Search in sources :

Example 6 with LongList

use of io.questdb.std.LongList in project questdb by bluestreak01.

the class IntervalUtilsTest method testIntersectRandomInplaceVsNonInplace.

@Test
public void testIntersectRandomInplaceVsNonInplace() {
    long seed = System.currentTimeMillis();
    Random r = new Random(seed);
    LongList intervals = new LongList();
    int aSize = r.nextInt(100) + 10;
    int bSize = r.nextInt(100);
    long aPos = r.nextInt(1000) - r.nextInt(1000);
    long bPos = r.nextInt(1000) - r.nextInt(1000);
    // A
    for (int i = 0; i < aSize; i++) {
        add(intervals, aPos, aPos += r.nextInt(100));
        aPos += r.nextInt(100);
    }
    // B
    LongList bItervals = new LongList();
    for (int i = 0; i < bSize; i++) {
        add(bItervals, bPos, bPos += r.nextInt(100));
        bPos += r.nextInt(100);
    }
    LongList expected = new LongList();
    // non-in place algo, supposed to be correct
    intersect(intervals, bItervals, expected);
    String expectedStr = toIntervalString(expected, 0);
    intervals.add(bItervals);
    runTestIntersectInplace(intervals, aSize * 2, expectedStr);
}
Also used : Random(java.util.Random) LongList(io.questdb.std.LongList) Test(org.junit.Test)

Example 7 with LongList

use of io.questdb.std.LongList in project questdb by bluestreak01.

the class IntervalUtilsTest method testUnionInplaceSimple2.

@Test
public void testUnionInplaceSimple2() {
    LongList intervals = new LongList();
    // A
    add(intervals, -1, 1);
    add(intervals, 2, 3);
    // B
    add(intervals, 1, 2);
    add(intervals, 3, 4);
    add(intervals, 6, 7);
    runTestUnionInplace(intervals, 4, "[-1,4], [6,7]");
}
Also used : LongList(io.questdb.std.LongList) Test(org.junit.Test)

Example 8 with LongList

use of io.questdb.std.LongList in project questdb by bluestreak01.

the class IntervalUtilsTest method testIntersectInplaceLong.

@Test
public void testIntersectInplaceLong() {
    LongList intervals = new LongList();
    // A
    add(intervals, -1, 10);
    add(intervals, 12, 13);
    // B
    add(intervals, 1, 2);
    add(intervals, 4, 5);
    add(intervals, 7, 7);
    add(intervals, 9, 12);
    runTestIntersectInplace(intervals, 4, "[1,2], [4,5], [7,7], [9,10], [12,12]");
}
Also used : LongList(io.questdb.std.LongList) Test(org.junit.Test)

Example 9 with LongList

use of io.questdb.std.LongList in project questdb by bluestreak01.

the class IntervalUtilsTest method testIntersectInplace3.

@Test
public void testIntersectInplace3() {
    LongList intervals = new LongList();
    // A
    add(intervals, -5, -3);
    add(intervals, -1, 10);
    add(intervals, 12, 13);
    // B
    add(intervals, -20, -10);
    add(intervals, 1, 2);
    add(intervals, 4, 5);
    add(intervals, 7, 7);
    add(intervals, 9, 12);
    runTestIntersectInplace(intervals, 6, "[1,2], [4,5], [7,7], [9,10], [12,12]");
}
Also used : LongList(io.questdb.std.LongList) Test(org.junit.Test)

Example 10 with LongList

use of io.questdb.std.LongList in project questdb by bluestreak01.

the class IntervalUtilsTest method runTestUnionInplace.

private void runTestUnionInplace(LongList intervals, int divider, String expected) {
    LongList copy = new LongList();
    copy.add(intervals, divider, intervals.size());
    copy.add(intervals, 0, divider);
    IntervalUtils.unionInplace(intervals, divider);
    TestUtils.assertEquals(expected, toIntervalString(intervals, 0));
    IntervalUtils.unionInplace(copy, copy.size() - divider);
    TestUtils.assertEquals(expected, toIntervalString(copy, 0));
}
Also used : LongList(io.questdb.std.LongList)

Aggregations

LongList (io.questdb.std.LongList)30 Test (org.junit.Test)25 LongTreeSet (io.questdb.griffin.engine.table.LongTreeSet)3 Rnd (io.questdb.std.Rnd)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 GriffinParserTestUtils.intervalToString (io.questdb.griffin.GriffinParserTestUtils.intervalToString)1 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)1 ObjList (io.questdb.std.ObjList)1 Random (java.util.Random)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1