Documentation
¶
Overview ¶
Package deque provides a double ended queue modeled after Python's collections.deque
Example:
import ( "fmt" "github.com/tebeka/deque" ) func Example() { // Create a new deque and put some numbers in it. dq := deque.New() for i := 0; i < 5; i++ { dq.Append(i) } // Pop from the left val, _ := dq.PopLeft() fmt.Println(val) // 0 // Get an item val, _ = dq.Get(2) fmt.Println(val) // 2 // Set an item dq.Set(2, "hello") // Rotate dq.Rotate(-2) // Print fmt.Println(dq) // Output: // Deque{"hello", 4, 1, 2} }
Index ¶
- Constants
- type Deque
- func (dq *Deque) Append(item interface{})
- func (dq *Deque) AppendLeft(item interface{})
- func (dq *Deque) Get(i int) (interface{}, error)
- func (dq *Deque) Len() int
- func (dq *Deque) Pop() (interface{}, error)
- func (dq *Deque) PopLeft() (interface{}, error)
- func (dq *Deque) Rotate(n int)
- func (dq *Deque) Set(i int, val interface{}) error
- func (dq *Deque) String() string
Constants ¶
View Source
const (
// Version is the package version
Version = "0.1.2"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deque ¶
type Deque struct {
// contains filtered or unexported fields
}
Deque is a double ended queue
func NewBounded ¶
NewBounded returns a new bounded Deque A bounded Deque will not grow over maxSize items
func (*Deque) Append ¶
func (dq *Deque) Append(item interface{})
Append appends an item to the right of the deque
func (*Deque) AppendLeft ¶
func (dq *Deque) AppendLeft(item interface{})
AppendLeft appends an item to the left of the deque
func (*Deque) Rotate ¶
Rotate rotates the queue. If n is positive then rotate right n steps, otherwise rotate left -n steps
Click to show internal directories.
Click to hide internal directories.