Skip to content

Commit

Permalink
Add Optional start and end points for search
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsanjoseph committed Jan 9, 2022
1 parent 56b825a commit 9f61164
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func main() {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGINT)
var db = riemann.DivisorDb(riemann.InMemoryDivisorDb{Data: make(map[int64]riemann.RiemannDivisorSum)})
go riemann.PopulateDB(db, 1000000)

go riemann.PopulateDB(db, 10081, -1, 1000000)
<-sigCh
handleClose(db)
}
24 changes: 14 additions & 10 deletions riemann/populate_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ package riemann

import "fmt"

func PopulateDB(db DivisorDb, batchSize int64) {
var startingN int64
func PopulateDB(db DivisorDb, startingN, endingN, batchSize int64) {
var currentStartingN int64

dbStartingN := db.Summarize().LargestComputedN.N
if dbStartingN < 5040 {
startingN = 5041

if dbStartingN > startingN {
currentStartingN = dbStartingN
} else {
startingN = dbStartingN
currentStartingN = startingN
}
currentEndingN := currentStartingN + batchSize

for {
endingN := startingN + batchSize - 1
db.Upsert(ComputerRiemannDivisorSums(startingN, endingN))
fmt.Printf("Computed Sums from %d to %d\n", startingN, endingN)
startingN = endingN + 1
fmt.Println(dbStartingN, startingN, endingN, currentEndingN, currentStartingN)
for endingN == -1 || currentEndingN < endingN+batchSize {
db.Upsert(ComputerRiemannDivisorSums(currentStartingN, currentEndingN))
fmt.Printf("Computed Sums from %d to %d\n", currentStartingN, currentEndingN)
currentStartingN = currentEndingN + 1
currentEndingN = currentStartingN + batchSize - 1
}
}
24 changes: 24 additions & 0 deletions riemann/populate_database_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package riemann_test

import (
"fmt"

"github.com/alexsanjoseph/riemann-divisor-sum-go/riemann"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Populates Database correctly", func() {

for i := 0; i < 10; i++ {
It("Populates and Summarizes correctly", func() {
var db = riemann.DivisorDb(riemann.InMemoryDivisorDb{Data: make(map[int64]riemann.RiemannDivisorSum)})
riemann.PopulateDB(db, 10070, 10085, 11)
var loadedData = db.Load()
fmt.Println(loadedData)
summaryData := db.Summarize()
Expect(summaryData.LargestWitnessValue.N).To(Equal(int64(10080)))
})
}
})

0 comments on commit 9f61164

Please sign in to comment.