Documentation ¶
Overview ¶
OrderedAny is a slice ordered by a function allowing duplicates. OrderedAny implements [parl.Ordered][E any].
OrderedPointers is an ordered list of *E pointers sorted by the referenced values. OrderedPointers implements [parl.OrderedPointers][E any].
Ordered is an ordered slice overwriting duplicates implementing [parl.Ordered][E any].
ResolveSlice removes one level of indirection from a slice of pointers.
SetLength adjusts the lenght of *slicep extending with append if necessary.
TrimLeft removes count bytes from the start of slicep, copying remaining bytes to its beginning.
Index ¶
- func IndexPartial(byts []byte, index int, key []byte) (newIndex int, notKnown bool)
- func InsertOrdered[E constraints.Ordered](slice0 []E, value E) (slice []E)
- func InsertOrderedFunc[E any](slice0 []E, value E, cmp func(a, b E) (result int)) (slice []E)
- func NewOrdered[E constraints.Ordered]() (list parli.Ordered[E])
- func NewOrderedAny[E any](cmp func(a, b E) (result int)) (list parli.Ordered[E])
- func NewOrderedPointers[E constraints.Ordered]() (list parli.OrderedPointers[E])
- func ResolveSlice[E any](slic []*E) (sList []E)
- func SetLength[E any](slicep *[]E, newLength int, noZero ...bool)
- func TrimLeft[E any](slicep *[]E, count int, noZero ...bool)
- type Ordered
- type OrderedAny
- type OrderedPointers
- type Queue
- type RangeCh
- type Slice
- func (o *Slice[E]) Append(slice []E)
- func (o *Slice[E]) Cap() (capacity int)
- func (o *Slice[E]) Clear()
- func (o *Slice[E]) Clone() (clone *Slice[E])
- func (o *Slice[E]) DeleteIndex(index0 int, index1 ...int)
- func (o *Slice[E]) Element(index int) (element E)
- func (o *Slice[E]) Length() (index int)
- func (o *Slice[E]) List(n ...int) (list []E)
- func (o *Slice[E]) SetElement(index int, element E)
- func (o *Slice[E]) SubSlice(index0, index1 int) (elements []E)
- type ThreadSafeSlice
- func (t *ThreadSafeSlice[T]) Append(element T)
- func (t *ThreadSafeSlice[T]) Clear()
- func (t *ThreadSafeSlice[T]) Get(index int) (element T, hasValue bool)
- func (t *ThreadSafeSlice[T]) Length() (length int)
- func (t *ThreadSafeSlice[T]) Put(element T, index int) (success bool)
- func (t *ThreadSafeSlice[T]) SetLength(newLength int)
- func (t *ThreadSafeSlice[T]) SliceClone() (clone []T)
- func (t *ThreadSafeSlice[T]) TrimLeft(count int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IndexPartial ¶ added in v0.4.38
IndexPartial returns scan-result in a byte-slice for a key byte-sequence, whether key was found or more bytes needs to be read to determine if key is present.
- index is the first index to search at and it is checked against the length of byts
- return value:
- — notKnown: true, newIndex >= index: byts ended during a partial key match, newIndex is first byte of match
- — notKnown: false, newIndex >= index: entire key was found at newIndex
- — newIndex -1: no key sequence was found in byts
- empty or nil key is found immediately, but only if index is less than length of byts
- if byts is nil or empty, nothing is found
- panic-free
func InsertOrdered ¶
func InsertOrdered[E constraints.Ordered](slice0 []E, value E) (slice []E)
InsertOrdered inserts value into an ordered slice
- duplicate values are allowed, new values are placed at the end
- insert is O(log n)
func InsertOrderedFunc ¶
InsertOrderedFunc inserts a value into a slice making it ordered using a comparison function.
- duplicate values are allowed, new values are placed at the end
- insert is O(log n)
- cmp function can be provided by E being a type with Cmp method.
- cmp(a, b) is expected to return an integer comparing the two parameters: 0 if a == b, a negative number if a < b and a positive number if a > b
func NewOrdered ¶ added in v0.4.29
func NewOrdered[E constraints.Ordered]() (list parli.Ordered[E])
NewOrdered returns a slice ordered by value.
func NewOrderedAny ¶
NewOrderedAny creates a list ordered by a comparison function.
- The cmp comparison function can be provided by E being pslices.Comparable, ie. a type having a Cmp method.
- cmp(a, b) is expected to return an integer comparing the two parameters: 0 if a == b, a negative number if a < b and a positive number if a > b
- duplicate values are allowed and inserted in order with later values last
- if E is an interface-type and cmp is nil, every provided value must be checked to be comparable
func NewOrderedPointers ¶
func NewOrderedPointers[E constraints.Ordered]() (list parli.OrderedPointers[E])
func ResolveSlice ¶ added in v0.4.29
func ResolveSlice[E any](slic []*E) (sList []E)
ResolveSlice removes one level of indirection from a slice of pointers.
func SetLength ¶ added in v0.4.48
SetLength adjusts the lenght of *slicep extending with append if necessary.
- slicep’s length is adjusted
- if newLength > cap, slice may be reallocated
Types ¶
type Ordered ¶ added in v0.4.29
type Ordered[E constraints.Ordered] struct { Slice[E] }
Ordered is an ordered slice overwriting duplicates implementing [parl.Ordered][E any].
- E must be a comparable and ordered type, ie. not slice func map.
- Insert overwrites duplicates and is O(log n)
- Delete removes the first occurrence O(log n)
- For custom sort order or slice func map types, use NewOrderedAny
type OrderedAny ¶
type OrderedAny[E any] struct { Slice[E] // Element() Length() List() Clear() // contains filtered or unexported fields }
OrderedAny is a slice ordered by a function allowing duplicates. OrderedAny implements [parl.Ordered][E any].
- cmp allows for custom ordering or ordering of slice map and function types
- Use E as value for small-sized data or interface values.
- Use E as a pointer for larger sized structs.
- Duplicates are allowed, Inssert places duplicates at end
- Insert and Delete O(log n)
- cmp(a, b) is expected to return an integer comparing the two parameters: 0 if a == b, a negative number if a < b and a positive number if a > b
func (*OrderedAny[E]) Clone ¶ added in v0.4.29
func (o *OrderedAny[E]) Clone() (o2 parli.Ordered[E])
Length returns the number of elements
func (*OrderedAny[E]) Delete ¶
func (o *OrderedAny[E]) Delete(element E)
Delete removes an element from the ordered slice.
- if the element did not exist, the slice is not changed
- if element exists in duplicates, a random element of those duplicates is removed
- O(log n)
func (*OrderedAny[E]) Index ¶ added in v0.4.29
func (o *OrderedAny[E]) Index(element E) (index int)
func (*OrderedAny[E]) Insert ¶
func (o *OrderedAny[E]) Insert(element E)
Insert adds a value to the ordered slice.
type OrderedPointers ¶
type OrderedPointers[E constraints.Ordered] struct { OrderedAny[*E] // Element() Length() List() Clear() Insert() Delete() Index() Clone() }
OrderedPointers is an ordered list of *E pointers sorted by the referenced values. OrderedPointers implements [parl.OrderedPointers][E any].
- The OrderedPointers ordered list does not require a comparison function
- E is used for large structs.
- Insert overwrites duplicates.
- for custom sort order, use NewOrderedAny
func (*OrderedPointers[E]) Cmp ¶
func (o *OrderedPointers[E]) Cmp(a, b *E) (result int)
type Queue ¶ added in v0.4.43
type Queue[T any] struct { // contains filtered or unexported fields }
type RangeCh ¶ added in v0.4.58
type RangeCh[T any] struct { // contains filtered or unexported fields }
RangeCh is a range-able channel based on a thread-safe slice
- RangeCh.Ch() must be either read until close or RangeCh.Close must be invoked
func NewRangeCh ¶ added in v0.4.58
func NewRangeCh[T any](tss *ThreadSafeSlice[T]) (rangeChan *RangeCh[T])
NewRangeCh returns a range-able channel based on a ThreadSafeSlice
- the channel must be either read until it closes or invoke Close
type Slice ¶ added in v0.4.29
type Slice[E any] struct { // contains filtered or unexported fields }
Slice is a base type for reusable slice implementations
- super-types could implement Insert Delete Index
- Length
- Element single-element access
- Slice multiple-element access
- DeleteIndex delete elements
- Clear Clone
- List clone of n first items
- Slice implements parl.Slice[E any].
func (*Slice[E]) Append ¶ added in v0.4.94
func (o *Slice[E]) Append(slice []E)
Append adds element at end
func (*Slice[E]) Clear ¶ added in v0.4.29
func (o *Slice[E]) Clear()
Clear empties the ordered slice
func (*Slice[E]) DeleteIndex ¶ added in v0.4.94
DeleteIndex removes elements by index
- index1 default is slice length
func (*Slice[E]) Element ¶ added in v0.4.29
Element returns element by index. if index is negative or the length of the slice or larger, the E zero-value is returned.
func (*Slice[E]) SetElement ¶ added in v0.4.94
type ThreadSafeSlice ¶ added in v0.4.58
type ThreadSafeSlice[T any] struct { // contains filtered or unexported fields }
func NewThreadSafeSlice ¶ added in v0.4.58
func NewThreadSafeSlice[T any]() (threadSafeSlice *ThreadSafeSlice[T])
func (*ThreadSafeSlice[T]) Append ¶ added in v0.4.58
func (t *ThreadSafeSlice[T]) Append(element T)
func (*ThreadSafeSlice[T]) Clear ¶ added in v0.4.58
func (t *ThreadSafeSlice[T]) Clear()
func (*ThreadSafeSlice[T]) Get ¶ added in v0.4.58
func (t *ThreadSafeSlice[T]) Get(index int) (element T, hasValue bool)
func (*ThreadSafeSlice[T]) Length ¶ added in v0.4.58
func (t *ThreadSafeSlice[T]) Length() (length int)
func (*ThreadSafeSlice[T]) Put ¶ added in v0.4.58
func (t *ThreadSafeSlice[T]) Put(element T, index int) (success bool)
func (*ThreadSafeSlice[T]) SetLength ¶ added in v0.4.58
func (t *ThreadSafeSlice[T]) SetLength(newLength int)
func (*ThreadSafeSlice[T]) SliceClone ¶ added in v0.4.58
func (t *ThreadSafeSlice[T]) SliceClone() (clone []T)
func (*ThreadSafeSlice[T]) TrimLeft ¶ added in v0.4.58
func (t *ThreadSafeSlice[T]) TrimLeft(count int)