Search in sources :

Example 1 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class ComputeManagerTest method addMessages.

private static void addMessages(Consumer<ManagedBuffer> consumer) throws IOException {
    for (long i = 0L; i < 200L; i++) {
        int count = RANDOM.nextInt(5);
        for (int j = 0; j < count; j++) {
            Id id = BytesId.of(i);
            IdList message = new IdList();
            message.add(id);
            ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
        }
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Example 2 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class MapValue method write.

protected void write(RandomAccessOutput out, boolean writeElemType) throws IOException {
    out.writeInt(this.map.size());
    if (writeElemType) {
        out.writeByte(this.elemType.code());
    }
    for (Map.Entry<Id, T> entry : this.map.entrySet()) {
        Id id = entry.getKey();
        T value = entry.getValue();
        id.write(out);
        value.write(out);
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class StoreTestUtil method idFromPointer.

public static Id idFromPointer(Pointer pointer) throws IOException {
    BytesInput input = IOFactory.createBytesInput(pointer.bytes());
    Id id = new BytesId();
    id.read(input);
    return id;
}
Also used : BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId)

Example 4 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class EdgeMessageRecvPartitionTest method checkTenEdgesWithCombinedProperties.

private static void checkTenEdgesWithCombinedProperties(Iterator<KvEntry> it) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        Assert.assertTrue(it.hasNext());
        KvEntry entry = it.next();
        Id id = ReceiverUtil.readId(entry.key());
        Assert.assertEquals(BytesId.of(i), id);
        EntryIterator subKvIt = EntriesUtil.subKvIterFromEntry(entry);
        for (long j = i + 1; j < i + 3; j++) {
            Assert.assertTrue(subKvIt.hasNext());
            KvEntry subKv = subKvIt.next();
            Id targetId = ReceiverUtil.readId(subKv.key());
            Assert.assertEquals(BytesId.of(j), targetId);
            Properties properties = graphFactory().createProperties();
            ReceiverUtil.readValue(subKv.value(), properties);
            Assert.assertEquals(2, properties.size());
            LongValue v1 = properties.get("p1");
            Assert.assertEquals(new LongValue(i), v1);
            LongValue v2 = properties.get("p2");
            Assert.assertEquals(new LongValue(2L * i), v2);
        }
    }
    Assert.assertFalse(it.hasNext());
}
Also used : KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) EntryIterator(com.baidu.hugegraph.computer.core.store.EntryIterator) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties)

Example 5 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class EdgeMessageRecvPartitionTest method checkTenEdges.

public static void checkTenEdges(PeekableIterator<KvEntry> it) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        Assert.assertTrue(it.hasNext());
        KvEntry entry = it.next();
        Id id = ReceiverUtil.readId(entry.key());
        Assert.assertEquals(BytesId.of(i), id);
        EntryIterator subKvIt = EntriesUtil.subKvIterFromEntry(entry);
        for (long j = i + 1; j < i + 3; j++) {
            Assert.assertTrue(subKvIt.hasNext());
            KvEntry subKv = subKvIt.next();
            Id targetId = ReceiverUtil.readId(subKv.key());
            Assert.assertEquals(BytesId.of(j), targetId);
            Properties properties = graphFactory().createProperties();
            ReceiverUtil.readValue(subKv.value(), properties);
            Assert.assertEquals(1, properties.size());
            LongValue v1 = properties.get("p1");
            Assert.assertEquals(new LongValue(i), v1);
        }
    }
    Assert.assertFalse(it.hasNext());
}
Also used : KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) EntryIterator(com.baidu.hugegraph.computer.core.store.EntryIterator) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties)

Aggregations

Id (com.baidu.hugegraph.computer.core.graph.id.Id)74 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)51 Test (org.junit.Test)29 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)18 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)12 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)12 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)12 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)12 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)11 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)10 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)9 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)8 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)7 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)6 File (java.io.File)6 Value (com.baidu.hugegraph.computer.core.graph.value.Value)5 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)5 Config (com.baidu.hugegraph.computer.core.config.Config)4 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)4