Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fifo ¶
type Fifo struct {
// contains filtered or unexported fields
}
Fifo represents a dynamic, memory-efficient queue with a minimum fixed size.
func (*Fifo) IsEmpty ¶
IsEmpty returns true if the queue is empty.
Example ¶
ExampleFifo_IsEmpty demonstrates the usage of the IsEmpty method.
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/queue" ) func main() { q := queue.NewFifo(2) fmt.Println(q.IsEmpty()) q.Push(1) fmt.Println(q.IsEmpty()) }
Output: true false
func (*Fifo) Length ¶
Length returns the current number of items in the queue.
Example ¶
ExampleFifo_Length demonstrates the usage of the Length method.
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/queue" ) func main() { q := queue.NewFifo(2) fmt.Println(q.Length()) q.Push(1, 2) fmt.Println(q.Length()) }
Output: 0 2
func (*Fifo) Pop ¶
Pop removes and returns data from the start of the queue. Returns nil if the queue is empty. Shrinks the queue to minimum size if data length is less than minimum size.
Example ¶
ExampleFifo_Pop demonstrates the usage of the Pop method.
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/queue" ) func main() { q := queue.NewFifo(2) q.Push(1, 2, 3) fmt.Println(q.Pop()) fmt.Println(q.Pop()) }
Output: 1 2
func (*Fifo) PopN ¶
PopN removes and returns data with length n from the start of the queue. May return data less than n when n > count. Shrinks the queue to minimum size if remaining data size is less than the minimum size.
Example ¶
ExampleFifo_PopN demonstrates the usage of the PopN method.
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/queue" ) func main() { q := queue.NewFifo(2) q.Push(1, 2, 3, 4) fmt.Println(q.PopN(3)) }
Output: [1 2 3]
func (*Fifo) Push ¶
Push adds data to the end of the queue, nil data items are ignored. Automatically resizes to a larger size if the queue is full.
Example ¶
ExampleFifo_Push demonstrates the usage of the Push method.
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/queue" ) func main() { q := queue.NewFifo(2) q.Push(1, 2, 3) fmt.Println(q.Length()) }
Output: 3