primegen

package
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: 4 Imported by: 0

README

primegen.go is a Go package that generates prime numbers in order using the
Sieve of Atkin instead of the traditional Sieve of Eratosthenes.

It is a relatively straightforward port of D. J. Bernstein's original
C implementation (http://cr.yp.to/primegen.html) but makes use of
Go's concurrency features which should make it faster on multi-core CPUs.

Do "go get github.com/jbarham/primegen.go" to install the package.

View the package documentation online at
http://gopkgdoc.appspot.com/pkg/github.com/jbarham/primegen.go
or on the command line by running "go doc github.com/jbarham/primegen.go".

The repository includes two additional programs that illustrate usage of the
primegen package:

  1. primes, which writes prime numbers to standard out
  2. primespeed, which prints the time taken to generate the first
     50,847,534 prime numbers

John Barham
jbarham@gmail.com

Documentation

Overview

The primegen package generates prime numbers in order. It uses the Sieve of Atkin instead of the traditional Sieve of Eratosthenes.

The primegen Go package is a port of D. J. Bernstein's original implementation in C (http://cr.yp.to/primegen.html).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(w io.Writer, low, high uint64) (err error)

Write efficiently writes the list of prime numbers between low and high, separated by newline, to w.

Types

type Primegen

type Primegen struct {
	// contains filtered or unexported fields
}

func New

func New() *Primegen

New returns a new primegen.Primegen prime number generator.

func (*Primegen) Count

func (pg *Primegen) Count(x uint64) uint64

Count returns the number of prime numbers from the generator's current position up to x.

func (*Primegen) Next

func (pg *Primegen) Next() uint64

Next returns the next prime number and advances the generator.

func (*Primegen) Peek

func (pg *Primegen) Peek() uint64

Peek returns the next prime number, without advancing the generator.

func (*Primegen) Reset

func (pg *Primegen) Reset()

Reset resets the generator at the first prime number.

func (*Primegen) SkipTo

func (pg *Primegen) SkipTo(x uint64)

SkipTo advances the generator to generate prime numbers >= x.

Jump to

Keyboard shortcuts

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