Documentation ¶
Index ¶
- func BytesToUint16(b []byte) (v uint16)
- func BytesToUint32(b []byte) (v uint32)
- func BytesToUint64(b []byte) (v uint64)
- func PrefixEnd(prefix []byte) []byte
- func QuotEtag(etag string) string
- func SortUnique[T any](slice []T, cmp func(i, j int) int) []T
- func TrimEtag(etag string) string
- func Uint16toBytes(b []byte, v uint16)
- func Uint32toBytes(b []byte, v uint32)
- func Uint64toBytes(b []byte, v uint64)
- func Uint8toBytes(b []byte, v uint8)
- func Unique[T any](slice []T, equals func(i, j int) bool) []T
- type LimitedConcurrentExecutor
- type UnboundedQueue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToUint16 ¶
func BytesToUint32 ¶
func BytesToUint64 ¶
func PrefixEnd ¶
PrefixEnd returns the immediate next byte slice lexicographically after the given prefix. The result can be used as the exclusive end key when performing a range scan with the provided prefix.
For example:
- For prefix "abc", the result might be "abd".
- For prefix "ab\xff", the result might be "ac\x00".
- For a prefix that ends in multiple 0xff bytes like "ab\xff\xff", the result would be "ac\x00\x00".
If the given prefix consists entirely of 0xff bytes, the function returns nil, indicating there's no valid end key for such prefix.
It is not guaranteed that the returned byte slice is a valid key in the user's data domain, but it is suitable for range scan operations.
Params:
- prefix: The byte slice for which the end key is desired.
Returns:
- A byte slice representing the end key, or nil if the prefix is composed entirely of 0xff bytes.
func SortUnique ¶
SortUnique sorts and deduplicates a slice of any type. It first sorts the slice using sort.Slice, based on the order defined by the cmp function. cmp is a comparison function used to determine the order of two elements in the slice. If cmp(i, j) < 0, it indicates that element i should come before element j. Once the slice is sorted, SortUnique then iterates over the sorted slice, adding only the unique elements to the result slice. If cmp(i, j) == 0, it is considered that elements i and j are equal, This function returns a new slice containing the unique elements of the original slice, ordered according to the order defined by the cmp function.
Example:
slice := []int{3, 1, 2, 3, 4, 1} uniqueSlice := SortUnique(slice, func(i, j int) bool { return slice[i] < slice[j] }) fmt.Println("Unique slice:", uniqueSlice)
This example will output: Unique slice: [1 2 3 4] Note: This function modifies the contents of the input slice.
func Uint16toBytes ¶
func Uint32toBytes ¶
func Uint64toBytes ¶
func Uint8toBytes ¶
func Unique ¶
Unique removes duplicate elements from a slice. It iterates over the given slice and uses a custom equals function to determine if an element is a duplicate. The equals function takes two integer parameters i and j, which are indices of elements in the slice. If equals(i, j) returns true, it indicates that the elements at indices i and j are equal. For each element, Unique checks whether it already exists in the result slice. The element is added to the result slice only if it is not a duplicate. Ultimately, this function returns a new slice containing only the unique elements from the original slice.
Example:
slice := []string{"apple", "banana", "apple", "orange"} uniqueSlice := Unique(slice, func(i, j int) bool { return slice[i] == slice[j] }) fmt.Println("Unique slice:", uniqueSlice)
This example will output: Unique slice: ["apple" "banana" "orange"] Note that this function does not modify the contents of the original slice.
Types ¶
type LimitedConcurrentExecutor ¶
type LimitedConcurrentExecutor struct {
// contains filtered or unexported fields
}
func NewLimitedConcurrentExecutor ¶
func NewLimitedConcurrentExecutor(limit int) *LimitedConcurrentExecutor
func (*LimitedConcurrentExecutor) Execute ¶
func (lce *LimitedConcurrentExecutor) Execute(job func())
func (*LimitedConcurrentExecutor) Wait ¶
func (lce *LimitedConcurrentExecutor) Wait()
type UnboundedQueue ¶
type UnboundedQueue[T any] struct { // contains filtered or unexported fields }
func NewUnboundedQueue ¶
func NewUnboundedQueue[T any]() *UnboundedQueue[T]
func (*UnboundedQueue[T]) Consume ¶
func (q *UnboundedQueue[T]) Consume(fn func([]T))
func (*UnboundedQueue[T]) EnQueue ¶
func (q *UnboundedQueue[T]) EnQueue(items ...T)