Skip to content

Commit

Permalink
Populate Database and main function as entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsanjoseph committed Jan 9, 2022
1 parent cf64a83 commit 90c71b3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
31 changes: 31 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"fmt"
"os"
"os/signal"
"syscall"

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

func handleClose(db riemann.DivisorDb) {
fmt.Println("Got Interrupt. Shutting down...")
summarizeOutput := db.Summarize()
fmt.Println("\nHighest Number Analyzed\n======")

fmt.Printf("%+v\n", summarizeOutput.LargestComputedN)
fmt.Println("\nLargest Witness Value\n======")
fmt.Printf("%+v\n", summarizeOutput.LargestWitnessValue)

}

func main() {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGINT)
var db = riemann.DivisorDb(riemann.InMemoryDivisorDb{Data: make(map[int]riemann.RiemannDivisorSum)})
go riemann.PopulateDB(db, 1000000)

<-sigCh
handleClose(db)
}
20 changes: 20 additions & 0 deletions riemann/populate_database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package riemann

import "fmt"

func PopulateDB(db DivisorDb, batchSize int) {
var startingN int
dbStartingN := db.Summarize().LargestComputedN.N
if dbStartingN < 5040 {
startingN = 5041
} else {
startingN = dbStartingN
}

for {
endingN := startingN + batchSize - 1
db.Upsert(ComputerRiemannDivisorSums(startingN, endingN))
fmt.Printf("Computed Sums from %d to %d\n", startingN, endingN)
startingN = endingN + 1
}
}

0 comments on commit 90c71b3

Please sign in to comment.