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.
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 TrimLeft[E any](slicep *[]E, count int)
- type Ordered
- type OrderedAny
- type OrderedPointers
- type Queue
- type Slice
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.
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 }