-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare for release 6.3.0-v16 (#1143)
ProductLine: Stash Release: v2022.03.29 Release-tracker: stashed/CHANGELOG#46 Signed-off-by: 1gtm <[email protected]>
- Loading branch information
Showing
51 changed files
with
2,312 additions
and
1,144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package arrays | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
) | ||
|
||
func InterfaceToSlice(slice interface{}) ([]interface{}, error) { | ||
s := reflect.ValueOf(slice) | ||
if s.Kind() != reflect.Slice { | ||
return nil, errors.New("slice of interface not found") | ||
} | ||
|
||
ret := make([]interface{}, s.Len()) | ||
|
||
for i := 0; i < s.Len(); i++ { | ||
ret[i] = s.Index(i).Interface() | ||
} | ||
|
||
return ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package arrays | ||
|
||
import ( | ||
"reflect" | ||
) | ||
|
||
func Reverse(slice interface{}) ([]interface{}, error) { | ||
sliceA, err := InterfaceToSlice(slice) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for i := len(sliceA)/2 - 1; i >= 0; i-- { | ||
opp := len(sliceA) - 1 - i | ||
sliceA[i], sliceA[opp] = sliceA[opp], sliceA[i] | ||
} | ||
return sliceA, nil | ||
} | ||
|
||
func Filter(slice interface{}, f func(interface{}) bool) ([]interface{}, error) { | ||
sliceA, err := InterfaceToSlice(slice) | ||
if err != nil { | ||
return nil, err | ||
} | ||
b := sliceA[:0] | ||
for _, x := range sliceA { | ||
if f(x) { | ||
b = append(b, x) | ||
} | ||
} | ||
return b, nil | ||
} | ||
|
||
func Contains(slice interface{}, value interface{}) (bool, int) { | ||
s, err := InterfaceToSlice(slice) | ||
if err != nil { | ||
return false, -1 | ||
} | ||
|
||
for i, v := range s { | ||
if reflect.DeepEqual(v, value) { | ||
return true, i | ||
} | ||
} | ||
return false, -1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.