Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
Change-Id: I7509a653ad429d329165e968358cf4d01bf86742
  • Loading branch information
zhoney committed Apr 13, 2021
1 parent dcd3b0f commit 2fd2f80
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.perf.PerfUtil.Watched;
import com.baidu.hugegraph.structure.HugeEdge;
import com.baidu.hugegraph.traversal.algorithm.records.MultiPathsByArrayRecords;
import com.baidu.hugegraph.traversal.algorithm.records.MultiPathsRecords;
import com.baidu.hugegraph.type.define.Directions;
import com.baidu.hugegraph.util.E;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -82,7 +82,7 @@ public PathSet paths(Id sourceV, Directions sourceDir,

private class Traverser {

private final MultiPathsByArrayRecords record;
private final MultiPathsRecords record;

private final Id label;
private final long degree;
Expand All @@ -93,7 +93,7 @@ private class Traverser {

public Traverser(Id sourceV, Id targetV, Id label,
long degree, long capacity, long limit) {
this.record = new MultiPathsByArrayRecords(sourceV, targetV);
this.record = new MultiPathsRecords(sourceV, targetV);

this.label = label;
this.degree = degree;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2017 HugeGraph Authors
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.baidu.hugegraph.traversal.algorithm.records;

import org.eclipse.collections.api.iterator.IntIterator;

import com.baidu.hugegraph.util.collection.Int2IntsMap;

public class ArrayRecord implements Record {

private Int2IntsMap layer;

public ArrayRecord() {
this.layer = new Int2IntsMap();
}

@Override
public IntIterator keys() {
return this.layer.keyIterator();
}

@Override
public boolean containsKey(int key) {
return this.layer.containsKey(key);
}

@Override
public IntIterator get(int key) {
return new IntArrayIterator(this.layer.get(key));
}

@Override
public void addPath(int node, int parent) {
this.layer.add(node, parent);
}

@Override
public int size() {
return this.layer.size();
}

public class IntArrayIterator implements IntIterator {

private int[] array;
private int index;

public IntArrayIterator(int[] array) {
this.array = array;
this.index = 0;
}

@Override
public int next() {
return this.array[index++];
}

@Override
public boolean hasNext() {
return this.index < this.array.length;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2017 HugeGraph Authors
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.baidu.hugegraph.traversal.algorithm.records;

import org.eclipse.collections.api.iterator.IntIterator;
import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;

public class IntSetRecord implements Record {

private IntObjectHashMap<IntHashSet> layer;

public IntSetRecord() {
this.layer = new IntObjectHashMap<>();
}

@Override
public IntIterator keys() {
return this.layer.keySet().intIterator();
}


@Override
public boolean containsKey(int key) {
return this.layer.containsKey(key);
}

@Override public IntIterator get(int key) {
return this.layer.get(key).intIterator();
}

@Override
public void addPath(int node, int parent) {
if (this.layer.containsKey(node)) {
this.layer.get(node).add(parent);
} else {
this.layer.put(node, IntHashSet.newSetWith(parent));
}
}

@Override
public int size() {
return this.layer.size();
}
}

This file was deleted.

Loading

0 comments on commit 2fd2f80

Please sign in to comment.