Search in sources :

Example 1 with MemoryRequestServer

use of com.yahoo.memory.MemoryRequestServer in project sketches-core by DataSketches.

the class DirectQuickSelectSketch method hashUpdate.

//restricted methods
@Override
UpdateReturnState hashUpdate(final long hash) {
    HashOperations.checkHashCorruption(hash);
    mem_.putByte(FLAGS_BYTE, (byte) (mem_.getByte(FLAGS_BYTE) & ~EMPTY_FLAG_MASK));
    final long thetaLong = getThetaLong();
    //The over-theta test
    if (HashOperations.continueCondition(thetaLong, hash)) {
        //signal that hash was rejected due to theta.
        return RejectedOverTheta;
    }
    final int lgArrLongs = getLgArrLongs();
    //The duplicate test
    final int index;
    if (mem_.isResourceReadOnly() && !mem_.isDirect()) {
        index = HashOperations.hashSearchOrInsert(mem_, lgArrLongs, hash, preambleLongs_ << 3);
    } else {
        index = HashOperations.fastHashSearchOrInsert(mem_.getArray(), mem_.getCumulativeOffset(0L), lgArrLongs, hash, preambleLongs_ << 3);
    }
    if (index >= 0) {
        //Duplicate, not inserted
        return RejectedDuplicate;
    }
    //insertion occurred, increment curCount
    final int curCount = getRetainedEntries() + 1;
    //update curCount
    mem_.putInt(RETAINED_ENTRIES_INT, curCount);
    if (curCount > hashTableThreshold_) {
        if (lgArrLongs > lgNomLongs_) {
            //Assumes no dirty values, changes thetaLong, curCount_
            assert (lgArrLongs == (lgNomLongs_ + 1)) : "lgArr: " + lgArrLongs + ", lgNom: " + lgNomLongs_;
            //rebuild, refresh curCount based on # values in the hashtable.
            quickSelectAndRebuild(mem_, preambleLongs_, lgNomLongs_);
        } else //end of rebuild, exit
        {
            //Not at full size, resize. Should not get here if lgRF = 0 and memCap is too small.
            final int lgRF = getLgRF();
            final int actLgRF = actLgResizeFactor(mem_.getCapacity(), lgArrLongs, preambleLongs_, lgRF);
            int tgtLgArrLongs = Math.min(lgArrLongs + actLgRF, lgNomLongs_ + 1);
            if (actLgRF > 0) {
                //Expand in current Memory
                //lgArrLongs will change; thetaLong, curCount will not
                resize(mem_, preambleLongs_, lgArrLongs, tgtLgArrLongs);
                hashTableThreshold_ = setHashTableThreshold(lgNomLongs_, tgtLgArrLongs);
            } else //end of Expand in current memory, exit.
            {
                //Request more memory, then resize. lgArrLongs will change; thetaLong, curCount will not
                final int preBytes = preambleLongs_ << 3;
                tgtLgArrLongs = Math.min(lgArrLongs + lgRF, lgNomLongs_ + 1);
                final int tgtArrBytes = 8 << tgtLgArrLongs;
                final int reqBytes = tgtArrBytes + preBytes;
                final MemoryRequestServer memoryRequestServer = mem_.getMemoryRequestServer();
                final WritableMemory newDstMem = memoryRequestServer.request(reqBytes);
                moveAndResize(mem_, preambleLongs_, lgArrLongs, newDstMem, tgtLgArrLongs, thetaLong);
                mem_ = newDstMem;
                hashTableThreshold_ = setHashTableThreshold(lgNomLongs_, tgtLgArrLongs);
            }
        //end of Request more memory to resize
        }
    //end of resize
    }
    return InsertedCountIncremented;
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) MemoryRequestServer(com.yahoo.memory.MemoryRequestServer)

Example 2 with MemoryRequestServer

use of com.yahoo.memory.MemoryRequestServer in project sketches-core by DataSketches.

the class DirectUpdateDoublesSketch method growCombinedMemBuffer.

//Direct supporting methods
private static WritableMemory growCombinedMemBuffer(final WritableMemory mem, final int itemSpaceNeeded) {
    final long memBytes = mem.getCapacity();
    //+ preamble + min & max
    final int needBytes = (itemSpaceNeeded << 3) + COMBINED_BUFFER;
    assert needBytes > memBytes;
    final MemoryRequestServer memoryRequestServer = mem.getMemoryRequestServer();
    final WritableMemory newMem = memoryRequestServer.request(needBytes);
    mem.copyTo(0, newMem, 0, memBytes);
    return newMem;
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) MemoryRequestServer(com.yahoo.memory.MemoryRequestServer)

Aggregations

MemoryRequestServer (com.yahoo.memory.MemoryRequestServer)2 WritableMemory (com.yahoo.memory.WritableMemory)2