synccol

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

Iterator is a wrapper around a cols.Iterator that provides thread-safe access to the underlying collection.

func (Iterator[T]) Get

func (it Iterator[T]) Get() T

Get returns the current element.

func (Iterator[T]) GetRef

func (it Iterator[T]) GetRef() *T

GetRef returns a reference to the current element.

func (Iterator[T]) Index

func (it Iterator[T]) Index() int

Index returns the current index.

func (Iterator[T]) InsertAfter

func (it Iterator[T]) InsertAfter(value T)

InsertAfter inserts the specified element after the current element.

func (Iterator[T]) InsertBefore

func (it Iterator[T]) InsertBefore(value T)

InsertBefore inserts the specified element before the current element.

func (Iterator[T]) Move

func (it Iterator[T]) Move()

Move moves the iterator to the next element.

func (Iterator[T]) Remove

func (it Iterator[T]) Remove()

Remove removes the current element.

func (Iterator[T]) Set

func (it Iterator[T]) Set(value T)

Set sets the current element.

func (Iterator[T]) Valid

func (it Iterator[T]) Valid() bool

Valid returns true if the iterator is currently pointing to a valid element.

type Wrapper

type Wrapper[T any] struct {
	// contains filtered or unexported fields
}

Wrapper is a wrapper around a cols.Collection that provides thread-safe access. Locking is done through read-write mutex. This means that multiple goroutines can read at the same time, but only one goroutine can write at the same time.

func From

func From[T any](collection cols.Collection[T]) *Wrapper[T]

From creates a new Wrapper around the given cols.Collection.

func (*Wrapper[T]) Append

func (w *Wrapper[T]) Append(value T)

Append appends the given value to the collection.

func (*Wrapper[T]) Clear

func (w *Wrapper[T]) Clear()

Clear clears the collection.

func (*Wrapper[T]) Clone

func (w *Wrapper[T]) Clone() cols.Collection[T]

Clone returns a copy of a Wrapper with the new underlying collection that is also cloned.

func (*Wrapper[T]) CollectionIterator

func (w *Wrapper[T]) CollectionIterator() cols.Iterator[T]

CollectionIterator returns a cols.Iterator over the elements.

func (*Wrapper[T]) FindIndex

func (w *Wrapper[T]) FindIndex(predicate predication.Predicate[T]) (int, bool)

FindIndex returns the index of the first element that satisfies the given predicate. If no element satisfies the predicate, 0 and false are returned.

func (*Wrapper[T]) FindRef

func (w *Wrapper[T]) FindRef(predicate predication.Predicate[T]) (*T, bool)

FindRef returns a reference to the first element that satisfies the given predicate. If no element satisfies the predicate, nil and false are returned. Lock will not be held while the reference is used, so it is possible that the value of the element changes while the reference is used.

func (*Wrapper[T]) Get

func (w *Wrapper[T]) Get(index int) T

Get returns the element at the given index.

func (*Wrapper[T]) GetRef

func (w *Wrapper[T]) GetRef(index int) *T

GetRef returns a reference to the element at the given index. Usage of this method is discouraged, as it breaks the thread-safety. Lock will not be held while the reference is used, so it is possible that the value of the element changes while the reference is used.

func (*Wrapper[T]) Insert

func (w *Wrapper[T]) Insert(index int, value T)

Insert inserts the given value at the given index.

func (*Wrapper[T]) Iterator

func (w *Wrapper[T]) Iterator() iter.Iterator[T]

Iterator returns an iter.Iterator over the elements.

func (*Wrapper[T]) Join

func (w *Wrapper[T]) Join(other cols.Collection[T])

Join joins the collection with the given collection.

func (*Wrapper[T]) Prepend

func (w *Wrapper[T]) Prepend(value T)

Prepend prepends the given value to the collection.

func (*Wrapper[T]) RefsStream

func (w *Wrapper[T]) RefsStream(yield func(*T) bool)

RefsStream streams the references to the elements of the collection.

func (*Wrapper[T]) Remove

func (w *Wrapper[T]) Remove(index int)

Remove removes the element at the given index.

func (*Wrapper[T]) Reverse

func (w *Wrapper[T]) Reverse()

Reverse reverses the collection.

func (*Wrapper[T]) Set

func (w *Wrapper[T]) Set(index int, value T)

Set sets the value of the element at the given index.

func (*Wrapper[T]) Size

func (w *Wrapper[T]) Size() int

Size returns the number of elements.

func (*Wrapper[T]) Sort

func (w *Wrapper[T]) Sort(comparator comparison.Comparator[T])

Sort sorts the elements using the given comparator.

func (*Wrapper[T]) Stream

func (w *Wrapper[T]) Stream(yield func(T) bool)

Stream streams the elements of the collection.

func (*Wrapper[T]) Transaction

func (w *Wrapper[T]) Transaction(updateFunction func(collection cols.Collection[T]))

Transaction executes the given function with the cols.Collection as an argument. Wrapped cols.Collection will be locked for writing while the function is executed.

func (*Wrapper[T]) Update

func (w *Wrapper[T]) Update(index int, updateFunction func(value T) T)

Update calculates and sets the new value of the element at the given index.

func (*Wrapper[T]) UpdateRef

func (w *Wrapper[T]) UpdateRef(index int, updateFunction func(value *T))

UpdateRef in-place updates the value of the element at the given index.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL