Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
Change-Id: I80bd3d4ae961794cc82139262d605fe400f8c28b
  • Loading branch information
zhoney committed May 27, 2021
1 parent bd8e9b3 commit f400213
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class DoubleWayMultiPathsRecords extends AbstractRecords {
private final Stack<Record> targetRecords;

private IntIterator lastRecordKeys;
private int current;
private int currentKey;
private boolean forward;
private int accessed;

Expand Down Expand Up @@ -91,8 +91,8 @@ public boolean hasNextKey() {
@Watched
@Override
public Id nextKey() {
this.current = this.lastRecordKeys.next();
return this.id(this.current);
this.currentKey = this.lastRecordKeys.next();
return this.id(this.currentKey);
}

@Watched
Expand All @@ -102,12 +102,13 @@ public PathSet findPath(Id target, Function<Id, Boolean> filter,
PathSet results = new PathSet();
int targetCode = this.code(target);
// If cross point exists, path found, concat them
if (this.contains(targetCode)) {
results = this.forward ?
this.linkPath(this.current, targetCode, ring) :
this.linkPath(targetCode, this.current, ring);
if (this.forward && this.targetContains(targetCode)) {
results = this.linkPath(this.currentKey, targetCode, ring);
}
this.addPath(targetCode, this.current);
if (!this.forward && this.sourceContains(targetCode)) {
results = this.linkPath(targetCode, this.currentKey, ring);
}
this.addPath(targetCode, this.currentKey);
return results;
}

Expand All @@ -116,16 +117,11 @@ public long accessed() {
return this.accessed;
}

protected boolean contains(int node) {
return this.forward ? this.targetContains(node) :
this.sourceContains(node);
}

private boolean sourceContains(int node) {
protected boolean sourceContains(int node) {
return this.sourceRecords.peek().containsKey(node);
}

private boolean targetContains(int node) {
protected boolean targetContains(int node) {
return this.targetRecords.peek().containsKey(node);
}

Expand Down Expand Up @@ -209,6 +205,6 @@ protected boolean forward() {
}

protected int current() {
return this.current;
return this.currentKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public int size() {
public Set<Id> ids(long limit) {
Set<Id> ids = CollectionFactory.newIdSet(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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public PathSet findPath(Id target, Function<Id, Boolean> filter,
PathSet paths = new PathSet();
int targetCode = this.code(target);
// If cross point exists, shortest path found, concat them
if (this.contains(targetCode)) {
if (this.forward() && this.targetContains(targetCode) ||
!this.forward() && this.sourceContains(targetCode)) {
if (!filter.apply(target)) {
return paths;
}
Expand Down

0 comments on commit f400213

Please sign in to comment.