// Restore restores the pool to the previously captured state. ErrMismatchedNetwork // is returned if the provided port range doesn't exactly match the previous range. func (r *Allocator) Restore(into *uid.Range, data []byte) error { if into.String() != r.r.String() { return ErrMismatchedRange } snapshottable, ok := r.alloc.(allocator.Snapshottable) if !ok { return fmt.Errorf("not a snapshottable allocator") } return snapshottable.Restore(into.String(), data) }
// DefaultMCSAllocation returns a label from the MCS range that matches the offset // within the overall range. blockSize must be a positive integer representing the // number of labels to jump past in the category space (if 1, range == label, if 2 // each range will have two labels). func DefaultMCSAllocation(from *uid.Range, to *mcs.Range, blockSize int) MCSAllocationFunc { return func(block uid.Block) *mcs.Label { ok, offset := from.Offset(block) if !ok { return nil } if blockSize > 0 { offset = offset * uint32(blockSize) } label, _ := to.LabelAt(uint64(offset)) return label } }
// New creates a Allocator over a UID range, calling factory to construct the backing store. func New(r *uid.Range, factory allocator.AllocatorFactory) *Allocator { return &Allocator{ r: r, alloc: factory(int(r.Size()), r.String()), } }