use of org.apache.hyracks.api.dataflow.value.IBinaryHashFunction in project asterixdb by apache.
the class FieldHashPartitionComputerFactory method createPartitioner.
@Override
public ITuplePartitionComputer createPartitioner() {
final IBinaryHashFunction[] hashFunctions = new IBinaryHashFunction[hashFunctionFactories.length];
for (int i = 0; i < hashFunctionFactories.length; ++i) {
hashFunctions[i] = hashFunctionFactories[i].createBinaryHashFunction();
}
return new ITuplePartitionComputer() {
@Override
public int partition(IFrameTupleAccessor accessor, int tIndex, int nParts) throws HyracksDataException {
if (nParts == 1) {
return 0;
}
int h = 0;
int startOffset = accessor.getTupleStartOffset(tIndex);
int slotLength = accessor.getFieldSlotsLength();
for (int j = 0; j < hashFields.length; ++j) {
int fIdx = hashFields[j];
IBinaryHashFunction hashFn = hashFunctions[j];
int fStart = accessor.getFieldStartOffset(tIndex, fIdx);
int fEnd = accessor.getFieldEndOffset(tIndex, fIdx);
int fh = hashFn.hash(accessor.getBuffer().array(), startOffset + slotLength + fStart, fEnd - fStart);
h = h * 31 + fh;
}
if (h < 0) {
h = -(h + 1);
}
return h % nParts;
}
};
}
use of org.apache.hyracks.api.dataflow.value.IBinaryHashFunction in project asterixdb by apache.
the class SimilarityJaccardEvaluator method setHashMap.
protected void setHashMap(ATypeTag buildItemTypeTag, ATypeTag probeItemTypeTag) {
if (hashMap != null) {
hashMap.clear();
return;
}
IBinaryHashFunction putHashFunc = ListItemBinaryHashFunctionFactory.INSTANCE.createBinaryHashFunction(buildItemTypeTag, ignoreCase);
IBinaryHashFunction getHashFunc = ListItemBinaryHashFunctionFactory.INSTANCE.createBinaryHashFunction(probeItemTypeTag, ignoreCase);
IBinaryComparator cmp = ListItemBinaryComparatorFactory.INSTANCE.createBinaryComparator(buildItemTypeTag, probeItemTypeTag, ignoreCase);
hashMap = new BinaryHashMap(hashTableSize, TABLE_FRAME_SIZE, putHashFunc, getHashFunc, cmp);
}
Aggregations