container

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Overview

Copyright 2023 The acquirecloud Authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyMap

func CopyMap[K comparable, V any](m map[K]V) map[K]V

CopyMap allows to return a copy of the map provided. NOTE: it is NOT a deep copy, but just simply produces the copy of the map

func GetFirst

func GetFirst[K comparable, V any](m map[K]V) (K, V, bool)

GetFirst returns the first (pretty random) element in the map m. This weird function maybe helpful if we know that the len(m) == 1 and we need just get the elements out of there

func IndexOf

func IndexOf[V comparable](slice []V, v V) int

IndexOf returns the position of v in slice and -1 if the v is not in slice.

func IndexOfAny

func IndexOfAny[V any](slice []V, v V, equalF func(v1, v2 V) bool) int

IndexOfAny returns the position of v in slice and -1 if the v is not in slice.

func Keys

func Keys[K comparable, V any](m map[K]V) []K

Keys returns keys list (slice is created) or nil

func MergeSlicesUnique

func MergeSlicesUnique[V comparable](slices ...[]V) []V

MergeSlicesUnique receives slices and form one with unique values from all of them

func NewRingBuffer

func NewRingBuffer[V any](size uint) *ringBuffer[V]

NewRingBuffer returns the new instance of the *ringBuffer (which implements the RingBuffer)

func SliceCopy

func SliceCopy[V any](v []V) []V

SliceCopy makes a copy of slice

func SliceExcludeOverlaps

func SliceExcludeOverlaps[V comparable](s1, s2 []V) ([]V, []V)

SliceExcludeOverlaps returns unique elements in each slice of two first return param(unique in s1) - present in s1, but not in s2 second return param(unique in s2) - present in s2, but not in s1,

func SliceExludeUniqueS2

func SliceExludeUniqueS2[V comparable](s1, s2 []V) ([]V, []V)

SliceExludeS2Unique substracts elements s2 from the s1 and returns the following: first param - elements that present in s1, but not in s2 second param - elements that presents in s1 and s2 both

func SliceFill

func SliceFill[V any](s []V, v V)

SliceFill sets all values of s to v

func SliceRemoveIdx

func SliceRemoveIdx[V any](slice []V, idx int) []V

SliceRemoveIdx removes the element at idx from the slice and return the updated slice. the function does it in place, so the original slice is changed

func SliceReverse

func SliceReverse[V any](slice []V) []V

SliceReverse the slice in place and returns the slice itself

func Values

func Values[K comparable, V any](m map[K]V) []V

Values returns values list (slice is created) or nil

Types

type RingBuffer

type RingBuffer[V any] interface {
	// Write allows to write the value v into the buffer. It may return errors.ErrExhausted
	// if the maximum capacity of the buffer is reached
	Write(v V) error
	// Read reads the value from the buffer. It will return io.EOF if the buffer is empty
	Read() (V, error)
	// ReadN allows to read multiple values into the slice dst. It will return number of
	// values read
	ReadN(dst []V) int
	// Skip allows to skip first n values. It returns the actual number of values skipped
	Skip(n int) int
	// At returns the element at the index idx. It doesn't change the buffer values
	At(idx int) V
	// Clear removes all elements from the buffer
	Clear()
	// Len returns the actual number of values can be read
	Len() int
	// Cap returns the maximum buffer capacity
	Cap() int
}

RingBuffer is an interface for working with the FIFO buffer with the fixed size

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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