-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate Database and main function as entrypoint
- Loading branch information
1 parent
cf64a83
commit 90c71b3
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |