Documentation ¶
Overview ¶
Copyright 2017 Mailgun Technologies Inc
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- type PQItem
- type PriorityQueue
- type TTLMap
- func (m *TTLMap) Get(key string) (interface{}, bool)
- func (m *TTLMap) GetInt(key string) (int, bool, error)
- func (m *TTLMap) Increment(key string, value int, ttlSeconds int) (int, error)
- func (m *TTLMap) Len() int
- func (m *TTLMap) RemoveExpired(iterations int) int
- func (m *TTLMap) RemoveLastUsed(iterations int)
- func (m *TTLMap) Set(key string, value interface{}, ttlSeconds int) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PQItem ¶
type PQItem struct { Value interface{} Priority int // The priority of the item in the queue. // contains filtered or unexported fields }
An PQItem is something we manage in a priority queue.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
Implements a PriorityQueue
func NewPriorityQueue ¶
func NewPriorityQueue() *PriorityQueue
Example ¶
package main import ( "fmt" "github.com/vulcand/oxy/v2/internal/holsterv4/collections" ) func main() { queue := collections.NewPriorityQueue() queue.Push(&collections.PQItem{ Value: "thing3", Priority: 3, }) queue.Push(&collections.PQItem{ Value: "thing1", Priority: 1, }) queue.Push(&collections.PQItem{ Value: "thing2", Priority: 2, }) // Pops item off the queue according to the priority instead of the Push() order item := queue.Pop() fmt.Printf("Item: %s", item.Value.(string)) }
Output: Item: thing1
func (PriorityQueue) Len ¶
func (p PriorityQueue) Len() int
func (*PriorityQueue) Peek ¶
func (p *PriorityQueue) Peek() *PQItem
func (*PriorityQueue) Pop ¶
func (p *PriorityQueue) Pop() *PQItem
func (*PriorityQueue) Push ¶
func (p *PriorityQueue) Push(el *PQItem)
func (*PriorityQueue) Remove ¶
func (p *PriorityQueue) Remove(el *PQItem)
func (*PriorityQueue) Update ¶
func (p *PriorityQueue) Update(el *PQItem, priority int)
Modifies the priority and value of an Item in the queue.
type TTLMap ¶
type TTLMap struct { // Optionally specifies a callback function to be // executed when an entry has expired OnExpire func(key string, i interface{}) // contains filtered or unexported fields }