mirror of
https://github.com/emirpasic/gods.git
synced 2026-06-15 16:16:35 +03:00
14f714261f
* Generics migration This attempts to migrate this library in the least invasive way by preserving as much of the original API as possible. It does not change the tests in a meaningful way nor does it attempt to upgrade any logic that can be simplified or improved with generics. This is purely an API migration, and still requires a lot of additional work to be fully ready. * Fix a few broken tests around serialization * Add v2 suffix * Temporarily change mod name for testing * Rename module to /v2
27 lines
874 B
Go
27 lines
874 B
Go
// Copyright (c) 2015, Emir Pasic. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import cb "github.com/emirpasic/gods/v2/queues/circularbuffer"
|
|
|
|
// CircularBufferExample to demonstrate basic usage of CircularBuffer
|
|
func main() {
|
|
queue := cb.New[int](3) // empty (max size is 3)
|
|
queue.Enqueue(1) // 1
|
|
queue.Enqueue(2) // 1, 2
|
|
queue.Enqueue(3) // 1, 2, 3
|
|
_ = queue.Values() // 1, 2, 3
|
|
queue.Enqueue(3) // 4, 2, 3
|
|
_, _ = queue.Peek() // 4,true
|
|
_, _ = queue.Dequeue() // 4, true
|
|
_, _ = queue.Dequeue() // 2, true
|
|
_, _ = queue.Dequeue() // 3, true
|
|
_, _ = queue.Dequeue() // nil, false (nothing to deque)
|
|
queue.Enqueue(1) // 1
|
|
queue.Clear() // empty
|
|
queue.Empty() // true
|
|
_ = queue.Size() // 0
|
|
}
|