mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-21 13:55:43 +00:00
Feat(BE-36,37,38,39): finish master data management api
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package utils
|
||||
|
||||
// UniqueUintSlice returns a new slice containing distinct values in the order of first appearance.
|
||||
func UniqueUintSlice(values []uint) []uint {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
seen := make(map[uint]struct{}, len(values))
|
||||
result := make([]uint, 0, len(values))
|
||||
for _, v := range values {
|
||||
if _, ok := seen[v]; ok {
|
||||
continue
|
||||
}
|
||||
seen[v] = struct{}{}
|
||||
result = append(result, v)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// MissingUintIDs returns the values present in expected but missing from actual.
|
||||
func MissingUintIDs(expected, actual []uint) []uint {
|
||||
lookup := make(map[uint]struct{}, len(actual))
|
||||
for _, v := range actual {
|
||||
lookup[v] = struct{}{}
|
||||
}
|
||||
missing := make([]uint, 0)
|
||||
for _, v := range expected {
|
||||
if _, ok := lookup[v]; !ok {
|
||||
missing = append(missing, v)
|
||||
}
|
||||
}
|
||||
return missing
|
||||
}
|
||||
Reference in New Issue
Block a user