move sieves to subpackage
This commit is contained in:
parent
03e463b7a6
commit
a9c7f8091b
|
|
@ -22,7 +22,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib/sieve"
|
||||
)
|
||||
|
||||
var divisorsN uint
|
||||
|
|
@ -32,7 +32,7 @@ func divisors(cmd *cobra.Command, args []string) {
|
|||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := lib.DivisorsSieve(divisorsN, divisorsE, 1000)
|
||||
ch := sieve.DivisorsSieve(divisorsN, divisorsE, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib/sieve"
|
||||
)
|
||||
|
||||
var mobiusN uint
|
||||
|
|
@ -31,7 +31,7 @@ func mobius(cmd *cobra.Command, args []string) {
|
|||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := lib.MobiusSieve(mobiusN, 1000)
|
||||
ch := sieve.MobiusSieve(mobiusN, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib/sieve"
|
||||
)
|
||||
|
||||
var primeOmegaN uint
|
||||
|
|
@ -32,7 +32,7 @@ func primeOmega(cmd *cobra.Command, args []string) {
|
|||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := lib.PrimeOmegaSieve(primeOmegaN, primeOmegaMul, 1000)
|
||||
ch := sieve.PrimeOmegaSieve(primeOmegaN, primeOmegaMul, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib/sieve"
|
||||
)
|
||||
|
||||
var radicalN uint
|
||||
|
|
@ -31,7 +31,7 @@ func radical(cmd *cobra.Command, args []string) {
|
|||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := lib.RadicalSieve(radicalN, 1000)
|
||||
ch := sieve.RadicalSieve(radicalN, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib"
|
||||
"scm.dairydemon.net/filifa/mathtools/internal/lib/sieve"
|
||||
)
|
||||
|
||||
var totientN uint
|
||||
|
|
@ -31,7 +31,7 @@ func totient(cmd *cobra.Command, args []string) {
|
|||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
for v := range lib.TotientSieve(totientN, 1000) {
|
||||
for v := range sieve.TotientSieve(totientN, 1000) {
|
||||
if v == 0 {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ GNU General Public License for more details.
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package lib
|
||||
package sieve
|
||||
|
||||
func pow(base uint, exp uint) uint {
|
||||
result := uint(1)
|
||||
|
|
@ -42,6 +42,7 @@ func updateMultiples(sieve []uint, x uint, p uint, n uint) {
|
|||
if p*q >= n {
|
||||
break
|
||||
}
|
||||
println(q)
|
||||
|
||||
// sigma_x(p^k) = p^(kx) + sigma_x(p^(k-1))
|
||||
sieve[p*q] = pow(p*q, x) + sieve[q]
|
||||
|
|
@ -14,7 +14,7 @@ GNU General Public License for more details.
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package lib
|
||||
package sieve
|
||||
|
||||
/*
|
||||
MobiusSieve computes mobius(k) for k=1 to n, where mobius is the Mobius function.
|
||||
|
|
@ -14,7 +14,7 @@ GNU General Public License for more details.
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package lib
|
||||
package sieve
|
||||
|
||||
func primeOmegaUpdateMultiples(sieve []uint, p uint, n uint, multiplicity bool) {
|
||||
for q := p; ; q *= p {
|
||||
|
|
@ -14,7 +14,7 @@ GNU General Public License for more details.
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package lib
|
||||
package sieve
|
||||
|
||||
func radicalUpdateMultiples(sieve []uint, p uint, n uint) {
|
||||
for q := p; ; q *= p {
|
||||
|
|
@ -14,7 +14,7 @@ GNU General Public License for more details.
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package lib
|
||||
package sieve
|
||||
|
||||
/*
|
||||
TotientSieve computes totient(k) for k=1 to n, where totient is Euler's totient function. buflen sets the buffer length of the returned channel. Larger buffer lengths can result in better performance at the cost of higher memory usage.
|
||||
Loading…
Reference in New Issue