MCPcopy Create free account
hub / github.com/adrg/strutil / UniqueSlice

Function UniqueSlice

internal/stringutil/stringutil.go:26–40  ·  view source on GitHub ↗

UniqueSlice returns a slice containing the unique items from the specified string slice. The items in the output slice are in the order in which they occur in the input slice.

(items []string)

Source from the content-addressed store, hash-verified

24// string slice. The items in the output slice are in the order in which they
25// occur in the input slice.
26func UniqueSlice(items []string) []string {
27 var uniq []string
28 registry := map[string]struct{}{}
29
30 for _, item := range items {
31 if _, ok := registry[item]; ok {
32 continue
33 }
34
35 registry[item] = struct{}{}
36 uniq = append(uniq, item)
37 }
38
39 return uniq
40}
41
42// SliceContains returns true if terms contains q, or false otherwise.
43func SliceContains(terms []string, q string) bool {

Callers 2

UniqueSliceFunction · 0.92
TestUniqueSliceFunction · 0.92

Calls

no outgoing calls

Tested by 1

TestUniqueSliceFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…