Search in sources :

Example 6 with IntIterator

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

the class KoutRecords method ids.

@Override
public List<Id> ids(long limit) {
    List<Id> ids = CollectionFactory.newList(CollectionType.EC);
    IntIterator iterator = this.records().peek().keys();
    while ((limit == NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
        ids.add(this.id(iterator.next()));
    }
    return ids;
}
Also used : IntIterator(com.baidu.hugegraph.util.collection.IntIterator) Id(com.baidu.hugegraph.backend.id.Id)

Example 7 with IntIterator

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

the class KneighborRecords method paths.

@Override
public PathSet paths(long limit) {
    PathSet paths = new PathSet();
    Stack<Record> records = this.records();
    for (int i = 1; i < records.size(); i++) {
        IntIterator iterator = records.get(i).keys();
        while ((limit == NO_LIMIT || limit > 0L) && iterator.hasNext()) {
            paths.add(this.linkPath(i, iterator.next()));
            limit--;
        }
    }
    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 8 with IntIterator

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

the class IntMapTest method testIntFixedMapBySegmentsValuesWithMultiSegs.

@Test
public void testIntFixedMapBySegmentsValuesWithMultiSegs() {
    int segments = 400;
    int segmentSize = Integer.MAX_VALUE / segments;
    int step = 50;
    IntMap map = fixedBySegments(Integer.MAX_VALUE, segments);
    for (int k = 0; k < segments; k += step) {
        map.put(segmentSize * k, k);
    }
    Assert.assertEquals(map.size(), IteratorUtils.count(map.values().asIterator()));
    for (int i = 0; i < 10; i++) {
        IntIterator iter = map.values();
        for (int k = 0; k < segments; k += step) {
            Assert.assertTrue(iter.hasNext());
            Assert.assertEquals(k, 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 9 with IntIterator

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

the class IntMapTest method testIntFixedMapBySegmentsKeysWithMultiSegs.

@Test
public void testIntFixedMapBySegmentsKeysWithMultiSegs() {
    int segments = 400;
    int segmentSize = Integer.MAX_VALUE / segments;
    int step = 50;
    IntMap map = fixedBySegments(Integer.MAX_VALUE, segments);
    for (int k = 0; k < segments; k += step) {
        map.put(segmentSize * k, k);
    }
    Assert.assertEquals(map.size(), IteratorUtils.count(map.keys().asIterator()));
    for (int i = 0; i < 10; i++) {
        IntIterator iter = map.keys();
        for (int k = 0; k < segments; k += step) {
            Assert.assertTrue(iter.hasNext());
            Assert.assertEquals(segmentSize * k, 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 10 with IntIterator

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

the class IntMapTest method testIntFixedMapBySegmentsKeys.

@Test
public void testIntFixedMapBySegmentsKeys() {
    IntMap map = fixedBySegments(Integer.MAX_VALUE, 40);
    map.put(Integer.MAX_VALUE - 1, 1);
    Assert.assertEquals(1, IteratorUtils.count(map.keys().asIterator()));
    for (int i = 0; i < 10000; i++) {
        IntIterator iter = map.keys();
        Assert.assertTrue(iter.hasNext());
        Assert.assertEquals(Integer.MAX_VALUE - 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)

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