primes

package module
v0.0.0-...-6574182 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2015 License: Apache-2.0 Imports: 9 Imported by: 0

README

primes

Circle CI Coverage Status GoDoc

Calculate the primes between two integers using several sieve algorithms

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SieveAlgos is a list of available sieve algorithms
	SieveAlgos []SieveAlgo
)

Functions

func Between

func Between(a, b uint64, algo SieveAlgo, stats bool) ([]uint64, error)

Between returns a list of all primes between a and b, inclusive

func IsPrime

func IsPrime(val uint64) bool

IsPrime returns whether val isa prime

func Write

func Write(w io.Writer, a, b uint64, algo SieveAlgo, stats bool) error

Write efficiently writes the primes between a and b to w, newline separated

Types

type Eratosthenes

type Eratosthenes struct {
	bitset.Bitset
	// contains filtered or unexported fields
}

Eratosthenes is a Sieve that is calculated using the sieve of eratosthenes algorithm

func (*Eratosthenes) Next

func (s *Eratosthenes) Next() uint64

Next returns the next prime in the sieve

func (Eratosthenes) SkipTo

func (s Eratosthenes) SkipTo(pos uint64)

SkipTo advances the position to return primes >= pos

type ErrUnknownSieveAlgo

type ErrUnknownSieveAlgo SieveAlgo

ErrUnknownSieveAlgo is returned when an invalid sieve algorithm was selected

func (ErrUnknownSieveAlgo) Error

func (err ErrUnknownSieveAlgo) Error() string

type Sieve

type Sieve interface {
	Next() uint64
	SkipTo(uint64)
}

Sieve is a simple interface for different sieve algorithms

func NewEratosthenes

func NewEratosthenes(n uint64) Sieve

NewEratosthenes returns a new Eratosthenes calculated for all values from 0 to the nearest byte greater than n

func NewSundaram

func NewSundaram(n uint64) Sieve

NewSundaram returns a new Sundaram calculated for all values from 0 to the nearest byte greater than n

type SieveAlgo

type SieveAlgo int

SieveAlgo is an enum representing different kinds of sieve algorithms

const (
	// EratosthenesAlgo is the sieve of eratosthene algorithm
	EratosthenesAlgo SieveAlgo = iota

	// SundaramAlgo is the sieve of sundaram algorithm
	SundaramAlgo

	// AtkinAlgo is the sieve of atkin algorithm
	AtkinAlgo
)

func (SieveAlgo) String

func (i SieveAlgo) String() string

type Sundaram

type Sundaram struct {
	bitset.Bitset
	// contains filtered or unexported fields
}

Sundaram is a Sieve that is calculated using the sieve of sundaram algorithm

func (*Sundaram) Next

func (s *Sundaram) Next() uint64

Next returns the next prime in the sieve

func (Sundaram) SkipTo

func (s Sundaram) SkipTo(pos uint64)

SkipTo advances the position to return primes >= pos

Directories

Path Synopsis
Godeps
_workspace/src/github.com/codegangsta/cli
Package cli provides a minimal framework for creating and organizing command line Go applications.
Package cli provides a minimal framework for creating and organizing command line Go applications.
_workspace/src/github.com/dustin/go-humanize
Package humanize converts boring ugly numbers to human-friendly strings and back.
Package humanize converts boring ugly numbers to human-friendly strings and back.
_workspace/src/github.com/jbarham/primegen.go
The primegen package generates prime numbers in order.
The primegen package generates prime numbers in order.
_workspace/src/github.com/jtolds/gls
Package gls implements goroutine-local storage.
Package gls implements goroutine-local storage.
_workspace/src/github.com/smartystreets/assertions
Package assertions contains the implementations for all assertions which are referenced in goconvey's `convey` package (github.com/smartystreets/goconvey/convey) for use with the So(...) method.
Package assertions contains the implementations for all assertions which are referenced in goconvey's `convey` package (github.com/smartystreets/goconvey/convey) for use with the So(...) method.
_workspace/src/github.com/smartystreets/assertions/internal/oglematchers
Package oglematchers provides a set of matchers useful in a testing or mocking framework.
Package oglematchers provides a set of matchers useful in a testing or mocking framework.
_workspace/src/github.com/smartystreets/assertions/internal/oglemock/createmock
createmock is used to generate source code for mock versions of interfaces from installed packages.
createmock is used to generate source code for mock versions of interfaces from installed packages.
_workspace/src/github.com/smartystreets/assertions/internal/oglemock/generate
Package generate implements code generation for mock classes.
Package generate implements code generation for mock classes.
_workspace/src/github.com/smartystreets/assertions/internal/oglemock/generate/test_cases/complicated_pkg
Package complicated_pkg contains an interface with lots of interesting cases, for use in integration testing.
Package complicated_pkg contains an interface with lots of interesting cases, for use in integration testing.
_workspace/src/github.com/smartystreets/assertions/internal/oglemock/generate/test_cases/renamed_pkg
A package that calls itself something different than its package path would have you believe.
A package that calls itself something different than its package path would have you believe.
_workspace/src/github.com/smartystreets/assertions/internal/ogletest
Package ogletest provides a framework for writing expressive unit tests.
Package ogletest provides a framework for writing expressive unit tests.
Functions for working with source code.
_workspace/src/github.com/smartystreets/assertions/internal/reqtrace
Package reqtrace contains a very simple request tracing framework.
Package reqtrace contains a very simple request tracing framework.
_workspace/src/github.com/smartystreets/assertions/should
package should is simply a rewording of the assertion functions in the assertions package.
package should is simply a rewording of the assertion functions in the assertions package.
_workspace/src/github.com/smartystreets/goconvey/convey
Package convey contains all of the public-facing entry points to this project.
Package convey contains all of the public-facing entry points to this project.
_workspace/src/github.com/smartystreets/goconvey/convey/gotest
Package gotest contains internal functionality.
Package gotest contains internal functionality.
_workspace/src/github.com/smartystreets/goconvey/convey/reporting
Package reporting contains internal functionality related to console reporting and output.
Package reporting contains internal functionality related to console reporting and output.
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL