Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
Fix: Correct walker behaviour for alpha == 0 (#1645)
Browse files Browse the repository at this point in the history
* Correct walker behaviour for alpha == 0

* Remove duplicate approver filter code

* update comment
  • Loading branch information
DyrellC authored and Gal Rogozinski committed Dec 3, 2019
1 parent 80b7834 commit 3ff5ec0
Showing 1 changed file with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ private Optional<Hash> select(Map<Hash, Integer> ratings, Set<Hash> approversSet
List<Hash> approvers;
int approverIndex;

//Check if ratings map is empty. If so, alpha was set to 0 and a random approver will be selected.
if(!Collections.EMPTY_MAP.equals(ratings)) {
//filter based on tangle state when starting the walk
approvers = approversSet.stream().filter(ratings::containsKey).collect(Collectors.toList());
//After filtering, if no approvers are available, it's a tip.
if (approvers.size() == 0) {
return Optional.empty();
}
//filter based on tangle state when starting the walk
approvers = approversSet.stream().filter(ratings::containsKey).collect(Collectors.toList());
//After filtering, if no approvers are available, it's a tip.
if (approvers.size() == 0) {
return Optional.empty();
}

//Check if alpha was set to 0. If so, weight calculations are skipped and a random approver will be selected.
if(alpha != 0) {
//calculate the probabilities
List<Integer> walkRatings = approvers.stream().map(ratings::get).collect(Collectors.toList());

Expand All @@ -157,11 +157,7 @@ private Optional<Hash> select(Map<Hash, Integer> ratings, Set<Hash> approversSet
}
}
} else {
approvers = approversSet.stream().filter(ratings::containsKey).collect(Collectors.toList());
if (approvers.size() == 0) {
return Optional.empty();
}
approverIndex = random.nextInt(approversSet.size());
approverIndex = random.nextInt(approvers.size());
}
return Optional.of(approvers.get(approverIndex));
}
Expand Down

0 comments on commit 3ff5ec0

Please sign in to comment.