Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
Change-Id: I742ce92cea71f556d0c7b5a52229e46006f759e7
  • Loading branch information
zhoney committed May 12, 2021
1 parent 265f1d5 commit be0eaea
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ public KneighborRecords customizedKneighbor(Id source, EdgeStep step,
boolean concurrent = maxDepth >= this.concurrentDepth() &&
step.direction() == Directions.BOTH;

KneighborRecords records = new KneighborRecords(source, RecordType.INT,
true, concurrent);
KneighborRecords records = new KneighborRecords(RecordType.INT,
concurrent,
source, true);

Consumer<Id> consumer = v -> {
if (this.stop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public KoutRecords customizedKout(Id source, EdgeStep step,
this.depth = maxDepth;
boolean concurrent = maxDepth >= this.concurrentDepth() &&
step.direction() == Directions.BOTH;
KoutRecords records = new KoutRecords(source, RecordType.INT,
nearest, concurrent);
KoutRecords records = new KoutRecords(RecordType.INT, concurrent,
source, nearest);

Consumer<Id> consumer = v -> {
if (this.stop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.baidu.hugegraph.traversal.algorithm.records.record.RecordType;
import com.baidu.hugegraph.type.define.Directions;
import com.baidu.hugegraph.util.E;
import com.google.common.collect.ImmutableList;

public class PathsTraverser extends HugeTraverser {

Expand Down Expand Up @@ -94,8 +93,9 @@ private class Traverser {

public Traverser(Id sourceV, Id targetV, Id label,
long degree, long capacity, long limit) {
this.record = new DoubleWayMultiPathsRecords(sourceV, targetV,
RecordType.ARRAY);
this.record = new DoubleWayMultiPathsRecords(RecordType.ARRAY,
false,
sourceV, targetV);
this.label = label;
this.degree = degree;
this.capacity = capacity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ public AbstractRecords(RecordType type, boolean concurrent) {
this.idMapping = MappingFactory.newObjectIntMapping(this.concurrent);
}

public AbstractRecords(RecordType type) {
this.type = type;
this.concurrent = false;
this.idMapping = MappingFactory.newObjectIntMapping();
}

@Watched
protected int code(Id id) {
return this.idMapping.object2Code(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public class DoubleWayMultiPathsRecords extends AbstractRecords {
protected boolean forward;
private int accessed;

public DoubleWayMultiPathsRecords(Id sourceV, Id targetV, RecordType type) {
super(type);

public DoubleWayMultiPathsRecords(RecordType type, boolean concurrent,
Id sourceV, Id targetV) {
super(type, concurrent);
int sourceCode = this.code(sourceV);
int targetCode = this.code(targetV);
Record firstSourceRecord = this.newRecord();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public class KneighborRecords extends SingleWayMultiPathsRecords {

private final Id source;

public KneighborRecords(Id source, RecordType type,
boolean nearest, boolean concurrent) {
super(source, type, nearest, concurrent);
public KneighborRecords(RecordType type, boolean concurrent,
Id source, boolean nearest) {
super(type, concurrent, source, nearest);
this.source = source;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@

public class KoutRecords extends SingleWayMultiPathsRecords {

public KoutRecords(Id source,
RecordType type,
boolean nearest, boolean concurrent) {
super(source, type, nearest, concurrent);
public KoutRecords(RecordType type, boolean concurrent,
Id source, boolean nearest) {
super(type, concurrent, source, nearest);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ShortestPathRecords extends DoubleWayMultiPathsRecords {
private boolean pathFound;

public ShortestPathRecords(Id sourceV, Id targetV) {
super(sourceV, targetV, RecordType.INT);
super(RecordType.INT, false, sourceV, targetV);

this.accessedVertices = new IntHashSet();
this.accessedVertices.add(this.code(sourceV));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

import org.eclipse.collections.api.set.primitive.MutableIntSet;
Expand All @@ -49,15 +46,15 @@ public class SingleWayMultiPathsRecords extends AbstractRecords {
protected final Stack<Record> records;

private final boolean nearest;
private final Set accessedVertices;
private final MutableIntSet accessedVertices;

protected Record currentRecord;
protected IntIterator lastRecordKeys;
protected int current;
protected boolean forward;

public SingleWayMultiPathsRecords(Id source, RecordType type,
boolean nearest, boolean concurrent) {
public SingleWayMultiPathsRecords(RecordType type, boolean concurrent,
Id source, boolean nearest) {
super(type, concurrent);

this.nearest = nearest;
Expand All @@ -68,8 +65,8 @@ public SingleWayMultiPathsRecords(Id source, RecordType type,
this.records = new Stack<>();
this.records.push(firstRecord);

this.accessedVertices = concurrent ? ConcurrentHashMap.newKeySet() :
new HashSet();
this.accessedVertices = concurrent ? new IntHashSet().asSynchronized() :
new IntHashSet();
this.accessedVertices.add(sourceCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public synchronized Object code2Object(int code) {
return this.singleObjectIntMapping.code2Object(code);
}

@Override
public synchronized void clear() {
this.singleObjectIntMapping.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public synchronized Object code2Object(int code) {
return this.int2IdMap.get(code);
}

@Override
public void clear() {
this.int2IdMap.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.baidu.hugegraph.unit.core.ExceptionTest;
import com.baidu.hugegraph.unit.core.Int2IntsMapTest;
import com.baidu.hugegraph.unit.core.LocksTableTest;
import com.baidu.hugegraph.unit.core.ObjectIntMappingTest;
import com.baidu.hugegraph.unit.core.QueryTest;
import com.baidu.hugegraph.unit.core.RangeTest;
import com.baidu.hugegraph.unit.core.RolePermissionTest;
Expand Down Expand Up @@ -101,6 +102,7 @@
BackendStoreSystemInfoTest.class,
TraversalUtilTest.class,
Int2IntsMapTest.class,
ObjectIntMappingTest.class,

/* serializer */
BytesBufferTest.class,
Expand Down

0 comments on commit be0eaea

Please sign in to comment.