Skip to content

A generic allocator framework, including port allocator ...

License

Notifications You must be signed in to change notification settings

mars1024/allocator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Allocator

A universal allocator framework and some allocator implementations

Universal interfaces

Allocator interface is as below, it has 4 universal methods,

  • Assign is for assigning the using objects in range
  • Allocate is for allocating an valid object from range
  • Release is for releasing an object from range
  • Has is for testing whether an object is in range
type Interface interface {
	Assign(RangeID) error
	Allocate() (RangeID, interface{}, error)
	Release(RangeID) error
	Has(RangeID) bool
}

Range interface is as below, it has 2 universal methods,

  • Contains is for testing whether an object is in range
  • First is for returning an iterator which can traverse the whole range
type Range interface {
	Contains(RangeID) bool
	First() RangeIterator
}

RangeIterator interface is as below, it has 3 universal methods, the 3 methods can help us traverse the whole range.

type RangeIterator interface {
	Get() (RangeID, interface{})
	Next()
	InRange() bool
}

Universal implementation

There is an universal implementation to generate an Allocator from an Range. You can use func NewAllocator(ranger Range) Interface {} method to get this.

Some common allocators

There are also some common allocators implemented through the interfaces and methods above.

About

A generic allocator framework, including port allocator ...

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages