Search in sources :

Example 21 with RecordBuffer

use of org.apache.jena.tdb.base.buffer.RecordBuffer in project jena by apache.

the class ExtHash method split.

private HashBucket split(int bucketId, HashBucket bucket) {
    // idx is the array offset to the lower of the bucket point pair.
    if (logging()) {
        log("split: Bucket %d : size: %d; Bucket bitlength %d", bucketId, bucket.getCount(), bucket.getTrieBitLen());
        log("split: %s", bucket);
    }
    // Create new bucket, which will be the upper bucket.
    // Low bucket will have the old hash value, 
    // Lengthen the hash; the new will be one more.
    bucket.incTrieBitLen();
    // Bucket hash value is kept in index-order (i.e. high bits are most significant). 
    int hash1 = bucket.getTrieValue() << 1;
    int hash2 = (bucket.getTrieValue() << 1) | 0x1;
    // Reset, now it's longer
    bucket.setTrieValue(hash1);
    if (logging())
        log("split: bucket hashes 0x%04X 0x%04X", hash1, hash2);
    //        // New bucket
    HashBucket bucket2 = hashBucketMgr.create(hash2, bucket.getTrieBitLen());
    if (logging())
        log("New bucket: %s", bucket2);
    //bucket2.setTrieValue(hash2) ;
    RecordBuffer rBuff1 = bucket.getRecordBuffer();
    RecordBuffer rBuff2 = bucket2.getRecordBuffer();
    // Destination indexes into the above
    int idx1 = 0;
    int idx2 = 0;
    for (int i = 0; i < rBuff1.size(); i++) {
        Record r = rBuff1.get(i);
        // Incremented bit length
        int x = trieKey(r, bucket.getTrieBitLen());
        if (x == hash1) {
            if (logging())
                log("Allocate index %d to bucket1", i);
            // We're shifting down records that saty in this bucket.  
            if (idx1 != i)
                rBuff1.set(idx1, r);
            idx1++;
        } else if (x == hash2) {
            if (logging())
                log("Allocate index %d to bucket2", i);
            rBuff2.add(r);
            idx2++;
        } else
            error("Bad trie for allocation to split buckets");
    }
    if (true)
        rBuff1.clear(idx1, bucket.getCount() - idx1);
    rBuff1.setSize(idx1);
    if (logging()) {
        log("split: Lower bucket: %s", bucket);
        log("split: Upper bucket: %s", bucket2);
    }
    // Check with splitAndReorganise()
    hashBucketMgr.put(bucket);
    hashBucketMgr.put(bucket2);
    return bucket2;
}
Also used : Record(org.apache.jena.tdb.base.record.Record) RecordBuffer(org.apache.jena.tdb.base.buffer.RecordBuffer)

Example 22 with RecordBuffer

use of org.apache.jena.tdb.base.buffer.RecordBuffer in project jena by apache.

the class TestRecordBuffer method recBufferIterate11.

@Test
public void recBufferIterate11() {
    RecordBuffer rb = make(5, 5);
    Iterator<Record> iter = rb.iterator(intToRecord(3), intToRecord(9));
    same(iter, 4, 6, 8);
}
Also used : Record(org.apache.jena.tdb.base.record.Record) RecordLib.intToRecord(org.apache.jena.tdb.base.record.RecordLib.intToRecord) RecordBuffer(org.apache.jena.tdb.base.buffer.RecordBuffer) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 23 with RecordBuffer

use of org.apache.jena.tdb.base.buffer.RecordBuffer in project jena by apache.

the class TestRecordBuffer method recBuffer14.

@Test
public void recBuffer14() {
    RecordBuffer rb = make(5, 5);
    contains(rb, 2, 4, 6, 8, 10);
    RecordBuffer rb2 = make(5, 5);
    contains(rb2, 2, 4, 6, 8, 10);
    rb.copy(0, rb2, 1, 4);
    contains(rb2, 2, 2, 4, 6, 8);
}
Also used : RecordBuffer(org.apache.jena.tdb.base.buffer.RecordBuffer) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 24 with RecordBuffer

use of org.apache.jena.tdb.base.buffer.RecordBuffer in project jena by apache.

the class TestRecordBuffer method recBuffer13.

@Test
public void recBuffer13() {
    RecordBuffer rb = make(5, 5);
    contains(rb, 2, 4, 6, 8, 10);
    rb.clear(1, 3);
    contains(rb, 2, -1, -1, -1, 10);
}
Also used : RecordBuffer(org.apache.jena.tdb.base.buffer.RecordBuffer) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 25 with RecordBuffer

use of org.apache.jena.tdb.base.buffer.RecordBuffer in project jena by apache.

the class TestRecordBuffer method recBufferIterate07.

@Test
public void recBufferIterate07() {
    RecordBuffer rb = make(3, 5);
    Iterator<Record> iter = rb.iterator(null, intToRecord(2));
    same(iter);
}
Also used : Record(org.apache.jena.tdb.base.record.Record) RecordLib.intToRecord(org.apache.jena.tdb.base.record.RecordLib.intToRecord) RecordBuffer(org.apache.jena.tdb.base.buffer.RecordBuffer) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

RecordBuffer (org.apache.jena.tdb.base.buffer.RecordBuffer)34 BaseTest (org.apache.jena.atlas.junit.BaseTest)26 Test (org.junit.Test)26 Record (org.apache.jena.tdb.base.record.Record)14 RecordLib.intToRecord (org.apache.jena.tdb.base.record.RecordLib.intToRecord)11 PtrBuffer (org.apache.jena.tdb.base.buffer.PtrBuffer)3 ByteBuffer (java.nio.ByteBuffer)2 IOException (java.io.IOException)1 RecordBufferPage (org.apache.jena.tdb.base.recordbuffer.RecordBufferPage)1