Documentation ¶
Overview ¶
Package xtypes prodives useful data structures.
Index ¶
- Variables
- func Copy(dst, src interface{}) error
- type ExtMap
- type PQItem
- type PQItems
- type PriorityQueue
- func (pq *PriorityQueue) Empty() bool
- func (pq *PriorityQueue) Get(n int) ([]PQItem, error)
- func (pq *PriorityQueue) Len() int
- func (pq *PriorityQueue) Peek() PQItem
- func (pq *PriorityQueue) Pop() (PQItem, error)
- func (pq *PriorityQueue) Push(item PQItem) error
- func (pq *PriorityQueue) Put(items ...PQItem) error
- type QItems
- type Queue
- type SafeMap
- type Semaphore
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyQueue is returned when an non-applicable operation was called on queue due to its empty state. ErrEmptyQueue = errors.New("empty queue") // ErrInvalidQueue is returned when an non-applicable operation was called on a nil queue. ErrInvalidQueue = errors.New("invalid queue") )
Functions ¶
Types ¶
type ExtMap ¶
type ExtMap map[string]interface{}
ExtMap represents an extended map with come useful methods for convenience.
It almost the same as url.Values/http.Header. The main purpose of this type is to put values and then marshal them to JSON. This is NOT thread safe.
type PQItems ¶
type PQItems []PQItem
PQItems represents the queue items.
func (*PQItems) Pop ¶
func (pqi *PQItems) Pop() interface{}
Pop implements heap.Interface. Returns the first item.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue is a priority queue implemented using heap.
This is clean and simple thread safe implementation with no magic. PriorityQueue MUST be created using constructor.
func NewPriorityQueue ¶
func NewPriorityQueue(hint int) *PriorityQueue
NewPriorityQueue creates and inits a new PriorityQueue.
func (*PriorityQueue) Empty ¶
func (pq *PriorityQueue) Empty() bool
Empty returns true if the queue is empty.
func (*PriorityQueue) Get ¶
func (pq *PriorityQueue) Get(n int) ([]PQItem, error)
Get returns up to requested n of items.
func (*PriorityQueue) Peek ¶
func (pq *PriorityQueue) Peek() PQItem
Peek returns the first element without modifying the queue.
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() (PQItem, error)
Pop returns the first element from the queue. If the queue is empty - an error will be returned.
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(item PQItem) error
Push adds an item to the queue. If the underlying storage is nil - an error will be returned.
func (*PriorityQueue) Put ¶
func (pq *PriorityQueue) Put(items ...PQItem) error
Put adds items to queue.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is a simple queue based on slice.
This is clean and simple thread safe implementation with no magic. Queue MUST be created using constructor.
func (*Queue) Peek ¶
func (q *Queue) Peek() interface{}
Peek returns the first element without modifying the queue.
func (*Queue) Pop ¶
Pop returns the first element from the queue. If the queue is empty - an error will be returned.
type SafeMap ¶
type SafeMap struct {
// contains filtered or unexported fields
}
SafeMap provides a storage based on a map.
It is safe to use in concurrent mode. The storage is protected by the mutex.