From ae2da5efa54320efa56e5a564b7be29e7a6597d1 Mon Sep 17 00:00:00 2001
From: mStar aka a person <12024604-mstarongitlab@users.noreply.gitlab.com>
Date: Wed, 17 Jan 2024 09:47:33 +0100
Subject: [PATCH] Moved stuff, added Contains to sliceutils
---
.idea/.gitignore | 8 -----
.idea/goutils.iml | 9 ------
.idea/modules.xml | 8 -----
.idea/vcs.xml | 6 ----
{pkg/containers => containers}/generics.go | 0
{pkg/containers => containers}/queues.go | 0
{pkg/containers => containers}/stacks.go | 0
{pkg/maputils => maputils}/mapUtils.go | 0
{pkg/other => other}/other.go | 0
{pkg/sliceutils => sliceutils}/sliceUtils.go | 33 +++++++++++++-------
10 files changed, 21 insertions(+), 43 deletions(-)
delete mode 100644 .idea/.gitignore
delete mode 100644 .idea/goutils.iml
delete mode 100644 .idea/modules.xml
delete mode 100644 .idea/vcs.xml
rename {pkg/containers => containers}/generics.go (100%)
rename {pkg/containers => containers}/queues.go (100%)
rename {pkg/containers => containers}/stacks.go (100%)
rename {pkg/maputils => maputils}/mapUtils.go (100%)
rename {pkg/other => other}/other.go (100%)
rename {pkg/sliceutils => sliceutils}/sliceUtils.go (53%)
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 13566b8..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/.idea/goutils.iml b/.idea/goutils.iml
deleted file mode 100644
index 5e764c4..0000000
--- a/.idea/goutils.iml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index aa5694d..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pkg/containers/generics.go b/containers/generics.go
similarity index 100%
rename from pkg/containers/generics.go
rename to containers/generics.go
diff --git a/pkg/containers/queues.go b/containers/queues.go
similarity index 100%
rename from pkg/containers/queues.go
rename to containers/queues.go
diff --git a/pkg/containers/stacks.go b/containers/stacks.go
similarity index 100%
rename from pkg/containers/stacks.go
rename to containers/stacks.go
diff --git a/pkg/maputils/mapUtils.go b/maputils/mapUtils.go
similarity index 100%
rename from pkg/maputils/mapUtils.go
rename to maputils/mapUtils.go
diff --git a/pkg/other/other.go b/other/other.go
similarity index 100%
rename from pkg/other/other.go
rename to other/other.go
diff --git a/pkg/sliceutils/sliceUtils.go b/sliceutils/sliceUtils.go
similarity index 53%
rename from pkg/sliceutils/sliceUtils.go
rename to sliceutils/sliceUtils.go
index 40070a2..c9cc0fb 100644
--- a/pkg/sliceutils/sliceUtils.go
+++ b/sliceutils/sliceUtils.go
@@ -1,8 +1,8 @@
package sliceutils
-// MapSlice applies a given function to every element of a slice.
+// MapS applies a given function to every element of a slice.
// The return type may be different from the initial type of the slice.
-func MapSlice[T any, M any](arr []T, apply func(T) M) []M {
+func Map[T any, M any](arr []T, apply func(T) M) []M {
n := make([]M, len(arr))
for i, e := range arr {
n[i] = apply(e)
@@ -10,9 +10,9 @@ func MapSlice[T any, M any](arr []T, apply func(T) M) []M {
return n
}
-// FilterSlice filters a slice using a given function.
+// Filter filters a slice using a given function.
// If the filter function returns true, the element stays, otherwise it gets removed.
-func FilterSlice[T any](arr []T, filter func(T) bool) []T {
+func Filter[T any](arr []T, filter func(T) bool) []T {
n := make([]T, 0)
for _, e := range arr {
if filter(e) {
@@ -22,8 +22,8 @@ func FilterSlice[T any](arr []T, filter func(T) bool) []T {
return n
}
-// RemoveDuplicateSlice removes all duplicates inside a slice.
-func RemoveDuplicateSlice[T comparable](sliceList []T) []T {
+// RemoveDuplicate removes all duplicates inside a slice.
+func RemoveDuplicate[T comparable](sliceList []T) []T {
allKeys := make(map[T]bool)
list := []T{}
for _, item := range sliceList {
@@ -35,15 +35,15 @@ func RemoveDuplicateSlice[T comparable](sliceList []T) []T {
return list
}
-// ReverseSlice reverses a given slice.
-func ReverseSlice[S ~[]E, E any](s S) {
+// Reverse reverses a given slice.
+func Reverse[E any](s []E) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}
-// CompareOrderedSlice compares two slices for both element equality and element order.
-func CompareOrderedSlice[T comparable](a, b []T) bool {
+// CompareOrdered compares two slices for both element equality and element order.
+func CompareOrdered[T comparable](a, b []T) bool {
if len(a) != len(b) {
return false
}
@@ -55,9 +55,9 @@ func CompareOrderedSlice[T comparable](a, b []T) bool {
return true
}
-// CompareUnorderedSlice compares two slices for element equality.
+// CompareUnorderedS compares two slices for element equality.
// The order of those elements does not matter.
-func CompareUnorderedSlice[T comparable](a, b []T) bool {
+func CompareUnordered[T comparable](a, b []T) bool {
if len(a) != len(b) {
return false
}
@@ -71,3 +71,12 @@ func CompareUnorderedSlice[T comparable](a, b []T) bool {
}
return hits == len(a)
}
+
+func Contains[T comparable](a []T, b T) bool {
+ for _, v := range a {
+ if v == b {
+ return true
+ }
+ }
+ return false
+}