mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
35 lines
817 B
Go
35 lines
817 B
Go
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
|
|
}
|