Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtomicList ¶
type AtomicList[T any] struct { // contains filtered or unexported fields }
A thread-safe linked list
Example ¶
var ac AtomicList[int]
for i := range 10 {
ac.Add(i)
}
fmt.Println("Size:", ac.Size())
for v := range ac.Iter() {
fmt.Println(v)
}
fmt.Println("--------")
fmt.Println(ac.Remove(func(i int) bool { return i == 4 }))
fmt.Println(ac.Remove(func(i int) bool { return i == 9 }))
fmt.Println(ac.Remove(func(i int) bool { return i == 0 }))
fmt.Println(ac.Remove(func(i int) bool { return i == 0 }))
fmt.Println("Size:", ac.Size())
fmt.Println("--------")
for v := range ac.Iter() {
fmt.Println(v)
}
fmt.Println("--------")
fmt.Println(ac.RemoveAll(func(i int) bool { return i < 6 }))
fmt.Println("Size:", ac.Size())
fmt.Println("--------")
for v := range ac.Iter() {
fmt.Println(v)
}
fmt.Println("--------")
fmt.Println(ac.RemoveAll(func(i int) bool { return true }))
fmt.Println("Size:", ac.Size())
Output: Size: 10 9 8 7 6 5 4 3 2 1 0 -------- true true true false Size: 7 -------- 8 7 6 5 3 2 1 -------- 4 Size: 3 -------- 8 7 6 -------- 3 Size: 0
func (*AtomicList[T]) Add ¶
func (ac *AtomicList[T]) Add(v T)
Inserts a new value at the front of the chain
func (*AtomicList[T]) Remove ¶
func (ac *AtomicList[T]) Remove(fn func(T) bool) bool
Removes the first occurrence from the chain
func (*AtomicList[T]) RemoveAll ¶
func (ac *AtomicList[T]) RemoveAll(fn func(T) bool) (removed int64)
Removes all occurrences from the chain
func (*AtomicList[T]) Size ¶
func (ac *AtomicList[T]) Size() int64
Returns the number of items in the list
Click to show internal directories.
Click to hide internal directories.