use of com.carrotsearch.hppc.LongObjectOpenHashMap in project titan by thinkaurelius.
the class EdgeSerializer method parseRelation.
private RelationCache parseRelation(long vertexid, Entry data, boolean parseHeaderOnly, StandardTitanTx tx) {
assert vertexid > 0;
ReadBuffer column = data.getReadColumn();
ReadBuffer value = data.getReadValue();
LongObjectOpenHashMap properties = parseHeaderOnly ? null : new LongObjectOpenHashMap(4);
long[] typeAndDir = IDHandler.readEdgeType(column);
int dirID = (int) typeAndDir[1];
long typeId = typeAndDir[0];
Direction dir;
RelationType rtype;
switch(dirID) {
case PROPERTY_DIR:
dir = Direction.OUT;
rtype = RelationType.PROPERTY;
break;
case EDGE_OUT_DIR:
dir = Direction.OUT;
rtype = RelationType.EDGE;
break;
case EDGE_IN_DIR:
dir = Direction.IN;
rtype = RelationType.EDGE;
break;
default:
throw new IllegalArgumentException("Invalid dirID read from disk: " + dirID);
}
TitanType titanType = tx.getExistingType(typeId);
InternalType def = (InternalType) titanType;
long[] keysig = def.getSortKey();
if (!parseHeaderOnly && !titanType.isUnique(dir)) {
ReadBuffer sortKeyReader = def.getSortOrder() == Order.DESC ? column.invert() : column;
readInlineTypes(keysig, properties, sortKeyReader, tx);
}
long relationIdDiff, vertexIdDiff = 0;
if (titanType.isUnique(dir)) {
if (rtype == RelationType.EDGE)
vertexIdDiff = VariableLong.read(value);
relationIdDiff = VariableLong.read(value);
} else {
// Move position to end to read backwards
column.movePosition(column.length() - column.getPosition() - 1);
relationIdDiff = VariableLong.readBackward(column);
if (rtype == RelationType.EDGE)
vertexIdDiff = VariableLong.readBackward(column);
}
assert relationIdDiff + vertexid > 0;
long relationId = relationIdDiff + vertexid;
Object other;
switch(rtype) {
case EDGE:
Preconditions.checkArgument(titanType.isEdgeLabel());
other = vertexid + vertexIdDiff;
break;
case PROPERTY:
Preconditions.checkArgument(titanType.isPropertyKey());
TitanKey key = ((TitanKey) titanType);
other = hasGenericDataType(key) ? serializer.readClassAndObject(value) : serializer.readObjectNotNull(value, key.getDataType());
break;
default:
throw new AssertionError();
}
assert other != null;
if (!parseHeaderOnly) {
// value signature & sort key if unique
if (titanType.isUnique(dir)) {
readInlineTypes(keysig, properties, value, tx);
}
readInlineTypes(def.getSignature(), properties, value, tx);
// Third: read rest
while (value.hasRemaining()) {
TitanType type = tx.getExistingType(IDHandler.readInlineEdgeType(value));
Object pvalue = readInline(value, type);
assert pvalue != null;
properties.put(type.getID(), pvalue);
}
}
return new RelationCache(dir, typeId, relationId, other, properties);
}
Aggregations