slicejuice

package
v1.11.18 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Description: This package contains utility functions for working with slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsAny added in v1.11.12

func ContainsAny(slice interface{}, element interface{}) (bool, error)

ContainsAny checks if an element is present in the given slice.

This method uses reflection to work with slices of any type.

It has a time complexity of O(n), where n is the length of the slice.

func ContainsObjectIDMap added in v1.11.13

func ContainsObjectIDMap(slice []primitive.ObjectID, element primitive.ObjectID) bool

ContainsObjectIDMap checks if a slice contains a given element using a map for faster lookups.

This method has a time complexity of O(n) for creating the map, and O(1) for the lookup.

However, it has a space complexity of O(n), where n is the length of the slice.

It is suitable for large slices or when the slice is expected to contain the element.

func ContainsStringLinear

func ContainsStringLinear(slice []string, element string) bool

ContainsStringLinear checks if a slice contains a given element using a linear search.

This method has a time complexity of O(n), where n is the length of the slice.

It is suitable for small slices or when the slice is not expected to contain the element.

func ContainsStringMap

func ContainsStringMap(slice []string, element string) bool

ContainsStringMap checks if a slice contains a given element using a map for faster lookups.

This method has a time complexity of O(n) for creating the map, and O(1) for the lookup.

However, it has a space complexity of O(n), where n is the length of the slice.

It is suitable for large slices or when the slice is expected to contain the element.

Types

This section is empty.

Jump to

Keyboard shortcuts

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