Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Dec 23, 2023
1 parent e056414 commit db5631c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pagerank.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func (pr *pageRank) keyAsArrayIndex(key int) int {
index, ok := pr.keyToIndex[key]

if !ok {
pr.currentAvailableIndex++
index = pr.currentAvailableIndex
pr.currentAvailableIndex++
pr.keyToIndex[key] = index
pr.indexToKey[index] = key
}
Expand Down Expand Up @@ -146,7 +146,7 @@ func (pr *pageRank) Rank(followingProb, tolerance float64, resultFunc func(label
func (pr *pageRank) Clear() {
pr.inLinks = [][]int{}
pr.numberOutLinks = []int{}
pr.currentAvailableIndex = -1
pr.currentAvailableIndex = 0
pr.keyToIndex = make(map[int]int)
pr.indexToKey = make(map[int]int)
}
4 changes: 2 additions & 2 deletions pagerank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func assertRank(t *testing.T, pageRank Interface, expected map[int]float64) {
const tolerance = 0.0001
pageRank.Rank(0.85, tolerance, func(label int, rank float64) {
rankAsPercentage := toPercentage(rank)
if math.Abs(rankAsPercentage - expected[label]) > tolerance {
if math.Abs(rankAsPercentage-expected[label]) > tolerance {
t.Error("Rank for", label, "should be", expected[label], "but was", rankAsPercentage)
}
})
Expand Down Expand Up @@ -235,6 +235,6 @@ func BenchmarkOneMillion(b *testing.B) {
result[key] = val
})

fmt.Println("5 first values are", result[0], ",", result[1], ",", result[2], ",", result[3], ",", result[4])
fmt.Println("5 first values are", result[0], ",", result[1], ",", result[2], ",", result[3], ",", result[4], " Size:", len(result))
pageRank.Clear()
}

0 comments on commit db5631c

Please sign in to comment.