Documentation
¶
Overview ¶
Package addrset implements a set of IP addresses.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotAvailable is returned when no more addresses are available to set ErrNotAvailable = errors.New("address not available") // ErrAllocated is returned when the specific address requested is already allocated ErrAllocated = errors.New("address already allocated") )
Functions ¶
This section is empty.
Types ¶
type AddrSet ¶
type AddrSet struct {
// contains filtered or unexported fields
}
AddrSet is a set of IP addresses.
func (*AddrSet) Add ¶
Add adds address addr to the set. If addr is already in the set, it returns a wrapped ErrAllocated. If addr is not in the set's address range, it returns an error.
func (*AddrSet) AddAny ¶
AddAny adds an arbitrary address to the set, and returns that address. Or, if no addresses are available, it returns a wrapped ErrNotAvailable.
If the address set's pool contains fewer than 1<<maxBitsPerBitmap addresses, AddAny will add any address from the entire set. If the pool is bigger than that, AddAny will only consider the first 1<<maxBitsPerBitmap addresses. If those are all allocated, it returns ErrNotAvailable.
When serial=true, the set is scanned starting from the address following the address most recently set by AddrSet.AddAny (or AddrSet.AddAnyInRange if the range is in the same 1<<maxBitsPerBitmap .
func (*AddrSet) AddAnyInRange ¶
AddAnyInRange adds an arbitrary address from ipr to the set, and returns that address. Or, if no addresses are available, it returns a wrapped ErrNotAvailable. If ipr is not fully contained within the set's range, it returns an error.
When serial=true, the set is scanned starting from the address following the address most recently set by AddrSet.AddAny or AddrSet.AddAnyInRange.