Search in sources :

Example 1 with IntIterator

use of com.baidu.hugegraph.util.collection.IntIterator in project incubator-hugegraph by apache.

the class KneighborRecords method ids.

@Override
public List<Id> ids(long limit) {
    List<Id> ids = CollectionFactory.newList(CollectionType.EC);
    Stack<Record> records = this.records();
    // Not include record(i=0) to ignore source vertex
    for (int i = 1; i < records.size(); i++) {
        IntIterator iterator = records.get(i).keys();
        while ((limit == NO_LIMIT || limit > 0L) && iterator.hasNext()) {
            ids.add(this.id(iterator.next()));
            limit--;
        }
    }
    return ids;
}
Also used : IntIterator(com.baidu.hugegraph.util.collection.IntIterator) Record(com.baidu.hugegraph.traversal.algorithm.records.record.Record) Id(com.baidu.hugegraph.backend.id.Id)

Example 2 with IntIterator

use of com.baidu.hugegraph.util.collection.IntIterator in project incubator-hugegraph by apache.

the class KoutRecords method paths.

@Override
public PathSet paths(long limit) {
    PathSet paths = new PathSet();
    Stack<Record> records = this.records();
    IntIterator iterator = records.peek().keys();
    while ((limit == NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
        paths.add(this.linkPath(records.size() - 1, iterator.next()));
    }
    return paths;
}
Also used : IntIterator(com.baidu.hugegraph.util.collection.IntIterator) PathSet(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet) Record(com.baidu.hugegraph.traversal.algorithm.records.record.Record)

Example 3 with IntIterator

use of com.baidu.hugegraph.util.collection.IntIterator in project incubator-hugegraph by apache.

the class IntMapTest method testIntFixedMapBySegmentsValues.

@Test
public void testIntFixedMapBySegmentsValues() {
    IntMap map = fixedBySegments(Integer.MAX_VALUE, 40);
    map.put(Integer.MAX_VALUE - 1, 1);
    Assert.assertEquals(1, IteratorUtils.count(map.values().asIterator()));
    for (int i = 0; i < 10; i++) {
        IntIterator iter = map.values();
        Assert.assertTrue(iter.hasNext());
        Assert.assertEquals(1, iter.next());
        Assert.assertFalse(iter.hasNext());
        Assert.assertThrows(NoSuchElementException.class, () -> {
            iter.next();
        }, e -> {
            Assert.assertNull(e.getMessage());
        });
    }
}
Also used : IntIterator(com.baidu.hugegraph.util.collection.IntIterator) IntMap(com.baidu.hugegraph.util.collection.IntMap) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 4 with IntIterator

use of com.baidu.hugegraph.util.collection.IntIterator in project incubator-hugegraph by apache.

the class DoubleWayMultiPathsRecords method parentsContain.

public boolean parentsContain(int id) {
    Record parentRecord = this.parentRecord();
    if (parentRecord == null) {
        return false;
    }
    IntIterator parents = parentRecord.get(this.currentKey);
    while (parents.hasNext()) {
        int parent = parents.next();
        if (parent == id) {
            // Find backtrace path, stop
            return true;
        }
    }
    return false;
}
Also used : IntIterator(com.baidu.hugegraph.util.collection.IntIterator) Record(com.baidu.hugegraph.traversal.algorithm.records.record.Record)

Example 5 with IntIterator

use of com.baidu.hugegraph.util.collection.IntIterator in project incubator-hugegraph by apache.

the class DoubleWayMultiPathsRecords method linkPathLayer.

private PathSet linkPathLayer(Stack<Record> all, int id, int layerIndex) {
    PathSet results = new PathSet();
    if (layerIndex == 0) {
        Id sid = this.id(id);
        results.add(new Path(Lists.newArrayList(sid)));
        return results;
    }
    Id current = this.id(id);
    Record layer = all.elementAt(layerIndex);
    IntIterator iterator = layer.get(id);
    while (iterator.hasNext()) {
        int parent = iterator.next();
        PathSet paths = this.linkPathLayer(all, parent, layerIndex - 1);
        paths.append(current);
        results.addAll(paths);
    }
    return results;
}
Also used : Path(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path) IntIterator(com.baidu.hugegraph.util.collection.IntIterator) PathSet(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet) Record(com.baidu.hugegraph.traversal.algorithm.records.record.Record) Id(com.baidu.hugegraph.backend.id.Id)

Aggregations

IntIterator (com.baidu.hugegraph.util.collection.IntIterator)10 Record (com.baidu.hugegraph.traversal.algorithm.records.record.Record)5 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)4 IntMap (com.baidu.hugegraph.util.collection.IntMap)4 Test (org.junit.Test)4 Id (com.baidu.hugegraph.backend.id.Id)3 PathSet (com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet)3 Path (com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path)1