incremental

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2019 License: BSD-2-Clause Imports: 1 Imported by: 107

README

go.incremental

Build Status Go package incremental provides typed incremental counters that are type-safe.

Install

go get github.com/GeertJohan/go.incremental

Usage example

This example is also located in the example subdirectory

package main

import (
	"fmt"
	"github.com/GeertJohan/go.incremental"
	"runtime"
)

func main() {
	// use max cpu's
	runtime.GOMAXPROCS(runtime.NumCPU())

	// create new incremental.Int
	i := &incremental.Int{}

	// print some numbers
	fmt.Println(i.Next()) // print 1
	fmt.Println(i.Next()) // print 2
	fmt.Println(i.Next()) // print 3

	// create chan to check if goroutines are done
	done := make(chan int)

	// spawn 4 goroutines
	for a := 0; a < 4; a++ {
		// call goroutine with it's number (0-3)
		go func(aa int) {
			// print 10 incremental numbers
			for b := 0; b < 10; b++ {
				fmt.Printf("routine %d: %d\n", aa, i.Next())
			}
			// signal done
			done <- aa
		}(a)
	}

	// wait until all goroutines are done
	for a := 0; a < 4; a++ {
		fmt.Printf("goroutine %d done\n", <-done)
	}
	fmt.Println("all done")
}

Documentation

Overview

package incremental provides concurency-safe incremental numbers.

This package was created by a simple piece of code located in the gen subdirectory. Please modify that command if you want to modify this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Int

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

func (*Int) Last

func (i *Int) Last() int

Last returns the number (int) that was returned by the most recent call to this instance's Next()

func (*Int) Next

func (i *Int) Next() int

Next returns with an integer that is exactly one higher as the previous call to Next() for this Int

func (*Int) Set

func (i *Int) Set(value int)

Set changes the increment to given value, the succeeding call to Next() will return the given value+1

type Int16

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

func (*Int16) Last

func (i *Int16) Last() int16

Last returns the number (int16) that was returned by the most recent call to this instance's Next()

func (*Int16) Next

func (i *Int16) Next() int16

Next returns with an integer that is exactly one higher as the previous call to Next() for this Int16

func (*Int16) Set

func (i *Int16) Set(value int16)

Set changes the increment to given value, the succeeding call to Next() will return the given value+1

type Int32

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

func (*Int32) Last

func (i *Int32) Last() int32

Last returns the number (int32) that was returned by the most recent call to this instance's Next()

func (*Int32) Next

func (i *Int32) Next() int32

Next returns with an integer that is exactly one higher as the previous call to Next() for this Int32

func (*Int32) Set

func (i *Int32) Set(value int32)

Set changes the increment to given value, the succeeding call to Next() will return the given value+1

type Int64

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

func (*Int64) Last

func (i *Int64) Last() int64

Last returns the number (int64) that was returned by the most recent call to this instance's Next()

func (*Int64) Next

func (i *Int64) Next() int64

Next returns with an integer that is exactly one higher as the previous call to Next() for this Int64

func (*Int64) Set

func (i *Int64) Set(value int64)

Set changes the increment to given value, the succeeding call to Next() will return the given value+1

type Int8

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

func (*Int8) Last

func (i *Int8) Last() int8

Last returns the number (int8) that was returned by the most recent call to this instance's Next()

func (*Int8) Next

func (i *Int8) Next() int8

Next returns with an integer that is exactly one higher as the previous call to Next() for this Int8

func (*Int8) Set

func (i *Int8) Set(value int8)

Set changes the increment to given value, the succeeding call to Next() will return the given value+1

type Uint

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

func (*Uint) Last

func (i *Uint) Last() uint

Last returns the number (uint) that was returned by the most recent call to this instance's Next()

func (*Uint) Next

func (i *Uint) Next() uint

Next returns with an integer that is exactly one higher as the previous call to Next() for this Uint

func (*Uint) Set

func (i *Uint) Set(value uint)

Set changes the increment to given value, the succeeding call to Next() will return the given value+1

type Uint16

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

func (*Uint16) Last

func (i *Uint16) Last() uint16

Last returns the number (uint16) that was returned by the most recent call to this instance's Next()

func (*Uint16) Next

func (i *Uint16) Next() uint16

Next returns with an integer that is exactly one higher as the previous call to Next() for this Uint16

func (*Uint16) Set

func (i *Uint16) Set(value uint16)

Set changes the increment to given value, the succeeding call to Next() will return the given value+1

type Uint32

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

func (*Uint32) Last

func (i *Uint32) Last() uint32

Last returns the number (uint32) that was returned by the most recent call to this instance's Next()

func (*Uint32) Next

func (i *Uint32) Next() uint32

Next returns with an integer that is exactly one higher as the previous call to Next() for this Uint32

func (*Uint32) Set

func (i *Uint32) Set(value uint32)

Set changes the increment to given value, the succeeding call to Next() will return the given value+1

type Uint64

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

func (*Uint64) Last

func (i *Uint64) Last() uint64

Last returns the number (uint64) that was returned by the most recent call to this instance's Next()

func (*Uint64) Next

func (i *Uint64) Next() uint64

Next returns with an integer that is exactly one higher as the previous call to Next() for this Uint64

func (*Uint64) Set

func (i *Uint64) Set(value uint64)

Set changes the increment to given value, the succeeding call to Next() will return the given value+1

type Uint8

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

func (*Uint8) Last

func (i *Uint8) Last() uint8

Last returns the number (uint8) that was returned by the most recent call to this instance's Next()

func (*Uint8) Next

func (i *Uint8) Next() uint8

Next returns with an integer that is exactly one higher as the previous call to Next() for this Uint8

func (*Uint8) Set

func (i *Uint8) Set(value uint8)

Set changes the increment to given value, the succeeding call to Next() will return the given value+1

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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