本文整理汇总了Java中org.mellowtech.core.collections.KeyValue类的典型用法代码示例。如果您正苦于以下问题:Java KeyValue类的具体用法?Java KeyValue怎么用?Java KeyValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KeyValue类属于org.mellowtech.core.collections包,在下文中一共展示了KeyValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: next
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
public KeyValue<CBInt, CBString> next() {
// TODO: how to handle no more next?
String line;
if (cachedLine != null) {
line = cachedLine;
cachedLine = null;
} else {
try {
line = br.readLine();
if (line == null) {
end = true;
return null;
}
} catch (IOException ignore) {
end = true;
return null;
}
}
// parse the line and return value
String[] splits = line.split("\\t");
// LOGGER.info(line); // line is also working
Integer key = Integer.valueOf(splits[0]);
// LOGGER.info("key is " + key);
return new KeyValue<CBInt, CBString>(new CBInt(key),
new CBString(line));
}
示例2: put
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
public void put(A key, B value) throws IOException{
KeyValue<A,B> kv = new KeyValue <> (key,value);
if (kvCodec.byteSize(kv) > bucketSize / 10)
throw new IOException("size of key value too large. you should increase bucket size");
int rrn = find(kv);
BBuffer <KeyValue<A,B>> bucket = readBucket(rrn);
//delete any previous key
if(bucket.contains(kv)){
bucket.delete(kv);
size--;
}
if(bucket.fits(kv)){
size++;
bucket.insert(kv);
writeBucket(rrn, bucket);
} else {
logger.trace("slitting bucker {} {}", rrn, this);
splitBucket(bucket);
logger.trace(this.toString());
put(key, value);
}
}
示例3: combineBucket
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
private void combineBucket(BBuffer <KeyValue<A,B>> bucket, int rrn) throws IOException {
int bAdress = findBuddy(bucket);
if (bAdress == -1)
return;
int brrn = directory[bAdress];
BBuffer <KeyValue<A,B>> bBucket = readBucket(brrn);
if(bucket.fits(bBucket)){
bucket.merge(bBucket);
directory[bAdress] = rrn;
int ndepth = readBucketDepth(bucket);
writeBucketDepth(bucket, ndepth-1);
writeBucket(rrn, bucket);
deleteBucket(brrn);
if(collapseDir()){
combineBucket(bucket, rrn);
}
}
}
示例4: splitBucket
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
private void splitBucket(BBuffer <KeyValue<A,B>> bucket) throws IOException {
int bucketAddr = find(bucket.get(0));
logger.trace(DataTypeUtils.printBits((short) find(bucket.get(0))) + " " + (bucket.get(0)).getKey());
if (this.readBucketDepth(bucket) == dirDepth) {
doubleDir();
}
BlockRecord newBucket = createNewBucket();
Range r = findRange(bucket);
insertBucket(newBucket.record, r);
writeBucketDepth(bucket, readBucketDepth(bucket)+1);
writeBucketDepth(newBucket.block, readBucketDepth(bucket));
redistribute(bucket, newBucket.block, bucketAddr);
writeBucket(bucketAddr, bucket);
writeBucket(newBucket.record, newBucket.block);
writeDirectory(directory);
}
示例5: getFilePositionNoStrict
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
private TreePosition getFilePositionNoStrict(A key, int bNo)
throws IOException {
if (values.size() == 0)
return null;
BBuffer<KeyValue<A,B>> sb = getBlock(bNo);
int smallerInBlock = sb.search(new KeyValue<>(key));
boolean exists = true;
if (smallerInBlock < 0) { //not found
exists = false;
smallerInBlock = Math.abs(smallerInBlock);
smallerInBlock--; //readjust
}
int elementsInBlock = sb.getNumberOfElements();
int elements = (int) size;
Map.Entry<Integer, Integer> cnt = countKeyValues(bNo);
int smaller = cnt.getValue() + smallerInBlock;
return new TreePosition(smaller, elements, smallerInBlock, elementsInBlock, exists);
}
示例6: getNext
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
private void getNext() {
if (sbIterator == null) {
next = null;
return;
}
KeyValue<A,B> toRet = sbIterator.next();
if (toRet == null) {
sbIterator = null;
next = null;
} else {
if (!checkEnd(toRet)) {
sbIterator = null;
next = null;
} else {
next = toRet;
if (!sbIterator.hasNext()) {
nextIter(null);
}
}
}
}
示例7: BTreeIterator
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
BTreeIterator(BTreeImp<A,B> tree, boolean reverse,
A from, boolean inclusive,
A to, boolean endInclusive) {
this.tree = tree;
this.inclusive = inclusive;
this.reverse = reverse;
this.end = to == null ? null : new KeyValue<>(to, null);
this.endInclusive = endInclusive;
initPtrs();
setCurrentBlock(from);
nextIter(from);
//Hack for now
if(sbIterator != null && !sbIterator.hasNext()) //can happen when from not included
nextIter(null);
getNext();
}
示例8: getNext
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
private void getNext() {
if (sbIterator == null) {
next = null;
return;
}
KeyValue<A,B> toRet = sbIterator.next();
if (toRet == null) {
sbIterator = null;
next = null;
} else {
if (!checkEnd(toRet)) {
sbIterator = null;
next = null;
} else {
next = toRet;
if (!sbIterator.hasNext()) {
nextIter(null);
}
}
}
}
示例9: prevBlock
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
private void prevBlock(A from) {
if (currblock < 0)
sbIterator = null;
else {
try {
sbIterator = from == null ?
tree.getValueBlock(blocks.get(currblock)).iterator(true) :
tree.getValueBlock(blocks.get(currblock)).iterator(true,
new KeyValue<>(from, null), inclusive, null, false);
currblock--;
} catch (IOException e) {
logger.warn("Could not retrieve block", e);
throw new Error(e);
}
}
}
示例10: nextBlock
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
private void nextBlock(A from) {
if (currblock >= blocks.size())
sbIterator = null;
else {
try {
sbIterator = from == null ?
tree.getValueBlock(blocks.get(currblock)).iterator() :
tree.getValueBlock(blocks.get(currblock)).iterator(false,
new KeyValue<>(from, null), inclusive, null, false);
currblock++;
} catch (IOException e) {
logger.warn("Could not retrieve block", e);
throw new Error(e);
}
}
}
示例11: next
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
@Override
public KeyValue<A, BlobPointer> next() {
KeyValue <A,B> n = iter.next();
if(n == null) return null;
int size = valueCodec.byteSize(n.getValue());
try{
long fpos = fc.size();
BlobPointer bp = new BlobPointer(fpos, size);
ByteBuffer bb = valueCodec.to(n.getValue()); bb.flip();
fc.write(bb, fpos);
return new KeyValue <>(n.getKey(),bp);
} catch(IOException e){
throw new Error("could not store");
}
}
示例12: getKey
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
@Override
public A getKey(int pos) throws IOException {
if (pos < 0 || pos >= size)
throw new IOException("position out of bounds");
List<Integer> blocks = getLogicalBlocks(rootPage, leafLevel);
int curr = 0;
for (; curr < blocks.size(); curr++) {
int bNo = blocks.get(curr);
BBuffer<KeyValue<A,B>> sb = getValueBlock(bNo);
if (pos < sb.getNumberOfElements()) {
return sb.get(pos).getKey();
}
pos -= sb.getNumberOfElements();
}
return null;
}
示例13: countValueBlock
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
private boolean countValueBlock(int stopBlock, MapEntry<Integer, Integer> entry,
BBuffer<BTreeKey<A>> sb) throws IOException {
boolean foundStop = false;
BTreeKey<A> bKey;
for (int i = 0; i < sb.getNumberOfElements(); i++) {
bKey = sb.get(i);
if (bKey.leftNode == stopBlock) {
foundStop = true;
break;
}
BBuffer<KeyValue<A,B>> valBlock = getValueBlock(bKey.leftNode);
entry.setValue(entry.getValue() + valBlock.getNumberOfElements());
entry.setKey(entry.getKey() + 1);
if (i + 1 == sb.getNumberOfElements()) {
int last = getLastPointer(sb);
if (last == stopBlock) {
foundStop = true;
break;
}
valBlock = getValueBlock(bKey.leftNode);
entry.setValue(entry.getValue() + valBlock.getNumberOfElements());
entry.setKey(entry.getKey() + 1);
}
}
return foundStop;
}
示例14: insert
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
private BTreeKey<A> insert(int bNo, BTreeKey<A> key, KeyValue<A,B> kv, int level,
boolean update) throws IOException {
BBuffer<BTreeKey<A>> sb = getIndexBlock(bNo);
BTreeKey<A> keyIndex = null;
if (level == leafLevel) {
try {
BPlusReturn<A,B> ret = insertKeyValue(kv, getNode(sb.search(key), sb),
update);
if (ret != null) { // this forced a split...
keyIndex = ret.promo;
keyIndex.leftNode = ret.newBlockNo;
}
} catch (Exception e) {
logger.error("cannot insert KeyValue into block {} with key {} and keyValue {}",bNo,key,kv);
throw new IOException(e);
}
} else
keyIndex = insert(getNode(sb.search(key), sb), key, kv, level + 1,
update);
// insert the key into the index and split if necessary:
if (keyIndex == null)
return null;
else
return insertKey(sb, bNo, keyIndex);
}
示例15: insertUpdate
import org.mellowtech.core.collections.KeyValue; //导入依赖的package包/类
private void insertUpdate(A key, B value, boolean update)
throws IOException {
KeyValue<A,B> kv = new KeyValue<>(key, value);
if (leafLevel == -1) {
// no index...to insert directly to value file...in first logical block:
BPlusReturn<A,B> ret = insertKeyValue(kv, rootPage, update);
if (ret != null && ret.action == BPlusReturn.SPLIT) {
// we now have to value blocks time for index
ret.promo.leftNode = ret.newBlockNo;
createRoot(ret.promo);
}
return;
}
BTreeKey<A> searchKey = new BTreeKey<>(key, -1);
BTreeKey<A> rootKey = insert(rootPage, searchKey, kv, 0, update);
if (rootKey != null)
createRoot(rootKey);
}