use of il.technion.tinytable.hash.FingerPrint in project narchy by automenta.
the class TinyCountingTable method shrinkChain.
/**
* If the value of an item is reduced we may need a new number of items.
* We therefore update the index and remove an arbitrary item from its chain.
*
* @param bucketId
* @param chainId
*/
private void shrinkChain(int bucketId, int chainId) {
this.removeAndShrink(bucketId);
int bucket;
int il = this.I0.length;
for (int i = bucketId + 1; i < bucketId + il; i++) {
bucket = (i) % il;
if (A[bucket] > 0) {
removeAndShrink(bucket);
A[bucket]--;
} else {
break;
}
}
removeItemFromIndex(new FingerPrint(bucketId, chainId, 1L));
}
use of il.technion.tinytable.hash.FingerPrint in project narchy by automenta.
the class TinyTable method add.
/**
* Adds a new fingerPrint to the following bucketNumber and chainNumber, the maximal size
* of supported fingerprint is 64 bits, and it is assumed that the actual data sits on the LSB bits of
* long.
* <p>
* According to our protocol, addition of a fingerprint may result in expending the bucket on account of neighboring buckets,
* or down sizing the stored fingerprints to make room for the new one.
* <p>
* In order to support deletions, deleted items are first logically deleted, and are fully
* deleted only upon addition.
* @param bucketNumber
* @param chainNumber
* @param fingerPrint
*/
int add(FingerPrint fpAux) {
int nextBucket = this.findFreeBucket(fpAux.bucketId);
upscaleBuckets(fpAux.bucketId, nextBucket);
int idxToAdd = RankIndexing.addItem(fpAux, I0, IStar, offsets, chain);
// if we need to, we steal items from other buckets.
this.putAndPush(fpAux.bucketId, idxToAdd, fpAux.fingerprint);
return idxToAdd;
}
use of il.technion.tinytable.hash.FingerPrint in project narchy by automenta.
the class RankIndexingTechnqiueUnitTest method TestRemove.
@Test
public void TestRemove() {
long[] I0 = new long[1];
long[] IStar = new long[1];
byte[] offsets = new byte[64];
byte[] chain = new byte[64];
FingerPrint fpaux = new FingerPrint(0, 4, 1);
// add an item!
RankIndexing.addItem(fpaux, I0, IStar, offsets, chain);
// check that item chain exists
assertTrue(RankIndexing.chainExist(I0[0], 4));
// get the chain
int chainSize = RankIndexing.getChainAndUpdateOffsets(fpaux, I0, IStar, offsets, chain);
// assert that it is of size 1.
assertTrue(chainSize == 1);
// remove the item - update the chain size.
RankIndexing.RemoveItem(4, I0, IStar, 0, offsets, chain, chainSize - 1);
// verify that the chain does not exist anymore.
chainSize = RankIndexing.getChainAndUpdateOffsets(fpaux, I0, IStar, offsets, chain);
assertTrue(chainSize == 0);
assertTrue(chain[0] == -1);
}
use of il.technion.tinytable.hash.FingerPrint in project narchy by automenta.
the class TinyCountingTable method adjustChainToItems.
/**
* After storing a value the number of items in the chain may change, this function adjust the number to be sufficient for all fingerprint items and counter items.
*
* @param bucketId
* @param chainId
* @param items
* @return
*/
private IntList adjustChainToItems(int bucketId, int chainId, PrimitiveIterable items) {
IntArrayList chain = RankIndexing.getChain(chainId, I0[bucketId], IStar[bucketId], this.bucketCapacity);
FingerPrint fpaux = new FingerPrint(bucketId, chainId, 1L);
// if the chain is shorter than needed we add dummy items.
int cs = chain.size();
int is = items.size();
if (cs < is) {
int diff = is - cs;
while (diff > 0) {
this.add(fpaux);
diff--;
}
} else // if the chain is longer than needed we remove items.
if (cs > is) {
int diff = cs - is;
while (diff > 0) {
shrinkChain(bucketId, chainId);
diff--;
// this.nrItems--;
}
}
chain = RankIndexing.getChain(chainId, I0[bucketId], IStar[bucketId], bucketCapacity);
return chain;
}
use of il.technion.tinytable.hash.FingerPrint in project narchy by automenta.
the class TinyTable method moveToEnd.
private int moveToEnd(FingerPrint fpaux) {
int chainoffset = RankIndexing.getChainAndUpdateOffsets(fpaux, I0, IStar, offsets, chain) - 1;
// for (Integer itemOffset : chain) {
//
// if(itemOffset<0){
// throw new RuntimeException("Item is not there!");
// }
int itemOffset = this.find(fpaux);
if (itemOffset < 0)
return -1;
// throw new RuntimeException("Not found!");
int lastOffset = chain[chainoffset];
long lastItem = this.get(fpaux.bucketId, lastOffset);
// assertTrue(chain.containsitemOffset));
this.set(fpaux.bucketId, itemOffset, lastItem);
this.set(fpaux.bucketId, lastOffset, 0L);
return lastOffset;
}
Aggregations