idpool

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2016 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package idpool implements a reusable integer id pool.

Example

pool := idpool.New(5,1024)
pool.Allocate() // 5
pool.Allocate() // 6
pool.Allocate(5)
pool.Allocate() // 5

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool is the id pool.

func New

func New(low, high int) *Pool

New returns a new Pool for given range. Range [low,high) is left open and right closed. Setting high to 0 means high is MaxInt32.

func (*Pool) Allocate

func (p *Pool) Allocate() int

Allocate an id from the pool. Returns high if no id is available.

func (*Pool) Clear

func (p *Pool) Clear()

Clear the pool.

func (*Pool) High

func (p *Pool) High() int

High returns the high.

func (*Pool) Len

func (p *Pool) Len() int

Len returns the number of id reserved or allocated.

func (*Pool) Low

func (p *Pool) Low() int

Low returns the low.

func (*Pool) Release

func (p *Pool) Release(id int)

Release an id back to the pool. Do nothing if the id is outside of the range.

func (*Pool) Reserve

func (p *Pool) Reserve(id int)

Reserve an id from the pool.

Jump to

Keyboard shortcuts

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