rename functions
This commit is contained in:
parent
a9c7f8091b
commit
26c197318e
|
|
@ -32,7 +32,7 @@ func divisors(cmd *cobra.Command, args []string) {
|
|||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := sieve.DivisorsSieve(divisorsN, divisorsE, 1000)
|
||||
ch := sieve.Divisors(divisorsN, divisorsE, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func mobius(cmd *cobra.Command, args []string) {
|
|||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := sieve.MobiusSieve(mobiusN, 1000)
|
||||
ch := sieve.Mobius(mobiusN, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ func primeOmega(cmd *cobra.Command, args []string) {
|
|||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := sieve.PrimeOmegaSieve(primeOmegaN, primeOmegaMul, 1000)
|
||||
ch := sieve.PrimeOmega(primeOmegaN, primeOmegaMul, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func radical(cmd *cobra.Command, args []string) {
|
|||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
ch := sieve.RadicalSieve(radicalN, 1000)
|
||||
ch := sieve.Radical(radicalN, 1000)
|
||||
for i := 0; ; i++ {
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func totient(cmd *cobra.Command, args []string) {
|
|||
bufStdout := bufio.NewWriter(os.Stdout)
|
||||
defer bufStdout.Flush()
|
||||
|
||||
for v := range sieve.TotientSieve(totientN, 1000) {
|
||||
for v := range sieve.Totient(totientN, 1000) {
|
||||
if v == 0 {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ 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]
|
||||
|
|
@ -50,9 +49,9 @@ func updateMultiples(sieve []uint, x uint, p uint, n uint) {
|
|||
}
|
||||
|
||||
/*
|
||||
DivisorSieve computes sigma_x(k) for k=1 to n, where sigma_x is the divisor sum function. x sets the power each divisor is raised to.
|
||||
Divisors computes sigma_x(k) for k=1 to n, where sigma_x is the divisor sum function. x sets the power each divisor is raised to.
|
||||
*/
|
||||
func DivisorsSieve(n uint, x uint, buflen uint) chan uint {
|
||||
func Divisors(n uint, x uint, buflen uint) chan uint {
|
||||
sieve := make([]uint, n)
|
||||
sieve[0] = 0
|
||||
for i := uint(1); i < n; i++ {
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
package sieve
|
||||
|
||||
/*
|
||||
MobiusSieve computes mobius(k) for k=1 to n, where mobius is the Mobius function.
|
||||
Mobius computes mobius(k) for k=1 to n, where mobius is the Mobius function.
|
||||
*/
|
||||
func MobiusSieve(n uint, buflen uint) chan int {
|
||||
func Mobius(n uint, buflen uint) chan int {
|
||||
sieve := make([]int, n)
|
||||
for i := 0; i < int(n); i++ {
|
||||
sieve[i] = i
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ func primeOmegaUpdateMultiples(sieve []uint, p uint, n uint, multiplicity bool)
|
|||
}
|
||||
|
||||
/*
|
||||
PrimeOmegaSieve computes omega(k) for k=1 to n, where omega is the prime omega function. If multiplicity is true, factors are counted with multiplicity.
|
||||
PrimeOmega computes omega(k) for k=1 to n, where omega is the prime omega function. If multiplicity is true, factors are counted with multiplicity.
|
||||
*/
|
||||
func PrimeOmegaSieve(n uint, multiplicity bool, buflen uint) chan uint {
|
||||
func PrimeOmega(n uint, multiplicity bool, buflen uint) chan uint {
|
||||
sieve := make([]uint, n)
|
||||
for i := uint(0); i < n; i++ {
|
||||
sieve[i] = 0
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ func radicalUpdateMultiples(sieve []uint, p uint, n uint) {
|
|||
}
|
||||
|
||||
/*
|
||||
RadicalSieve computes rad(k) for k=1 to n, where rad(n) is the radical of n.
|
||||
Radical computes rad(k) for k=1 to n, where rad(n) is the radical of n.
|
||||
*/
|
||||
func RadicalSieve(n uint, buflen uint) chan uint {
|
||||
func Radical(n uint, buflen uint) chan uint {
|
||||
sieve := make([]uint, n)
|
||||
sieve[0] = 0
|
||||
for i := uint(1); i < n; i++ {
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
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.
|
||||
Totient 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.
|
||||
*/
|
||||
func TotientSieve(n uint, buflen uint) chan uint {
|
||||
func Totient(n uint, buflen uint) chan uint {
|
||||
totients := make([]uint, n)
|
||||
totients[0] = 0
|
||||
totients[1] = 1
|
||||
|
|
|
|||
Loading…
Reference in New Issue