public static class ComparableBinary implements Comparable<ComparableBinary> {
private byte[] value;
public ComparableBinary(byte[] buffer) {
value = buffer;
}
public int compareTo(ComparableBinary o) {
final int size = value.length;
for (int i = 0; i < size; ++i) {
if (value[i] > o.value[i])
return 1;
else if (value[i] < o.value[i])
return -1;
}
return 0;
}
public byte[] toByteArray() {
return value;
}
}
public static class OHash256Serializer implements OBinarySerializer<ComparableBinary> {
public static final OBinaryTypeSerializer INSTANCE = new OBinaryTypeSerializer();
public static final byte ID = 100;
public static final int LENGTH = 32;
public int getObjectSize(final int length) {
return length;
}
public int getObjectSize(final ComparableBinary object) {
return object.toByteArray().length;
}
public void serialize(final ComparableBinary object, final byte[] stream, final int startPosition) {
final byte[] buffer = object.toByteArray();
System.arraycopy(buffer, 0, stream, startPosition, buffer.length);
}
public ComparableBinary deserialize(final byte[] stream, final int startPosition) {
final byte[] buffer = Arrays.copyOfRange(stream, startPosition, startPosition + LENGTH);
return new ComparableBinary(buffer);
}
public int getObjectSize(byte[] stream, int startPosition) {
return LENGTH;
}
public byte getId() {
return ID;
}
}
OBinarySerializerFactory.INSTANCE.registerSerializer(new OHash256Serializer(), null);
index = database.getMetadata().getIndexManager().createIndex("custom-hash", "UNIQUE", new ORuntimeKeyIndexDefinition(OHash256Serializer.ID), null, null);
ComparableBinary key1 = new ComparableBinary(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 });
ODocument doc1 = new ODocument().field("k", "key1");
index.put(key1, doc1);
OBinarySerializerFactory.getInstance().registerSerializer(new CFISerializer(), null);Enter code here...
val index = db.getMetadata.getIndexManager.createIndex("cfi","UNIQUE",new ORuntimeKeyIndexDefinition(CFISerializer.ID),null,null,null)
Colin Leister
Orient Technologies
The Company behind OrientDB
OBinarySerializerFactory.getInstance().registerSerializer(new CFISerializer(), null);
Colin Leister
Orient Technologies
The Company behind OrientDB
g.createKeyIndex("spec",classOf[Vertex],new Parameter("class", "CFI"), new Parameter("type", "UNIQUE"))
Colin Leister
Orient Technologies
The Company behind OrientDB
Colin Leister
Orient Technologies
The Company behind OrientDB
Excellent.
The reason I ask is I have been using the default SB-Tree *without* the custom serializer and it treats my CFI like a string - sorting/comparing it like a string. What I am hoping is that f I use the custom serializer the Index will treat the key as the CFI type it really is - and use the CFI implemation of Comparable (Comparable<CFI>) rather than the String (Comparable<String>)
execute(_.addVertex("class:CFI","spec",CFIParser.parse("epubcfi(/6/100)")))
Excellent.
The reason I ask is I have been using the default SB-Tree *without* the custom serializer and it treats my CFI like a string - sorting/comparing it like a string. What I am hoping is that f I use the custom serializer the Index will treat the key as the CFI type it really is - and use the CFI implementation of Comparable (Comparable<CFI>) rather than the String (Comparable<String>)
On Thursday, February 26, 2015 at 11:45:40 AM UTC-6, Colin wrote:
Colin Leister
Orient Technologies
The Company behind OrientDB
--
---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/QwAxzvWOyy4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Colin Leister
Orient Technologies
The Company behind OrientDB