MCPcopy Create free account
hub / github.com/aptly-dev/aptly / StrSlicesSubstract

Function StrSlicesSubstract

utils/list.go:106–140  ·  view source on GitHub ↗

StrSlicesSubstract finds all the strings which are in l but not in r, both slices shoult be sorted

(l, r []string)

Source from the content-addressed store, hash-verified

104
105// StrSlicesSubstract finds all the strings which are in l but not in r, both slices shoult be sorted
106func StrSlicesSubstract(l, r []string) []string {
107 var result []string
108
109 // pointer to left and right reflists
110 il, ir := 0, 0
111 // length of reflists
112 ll, lr := len(l), len(r)
113
114 for il < ll || ir < lr {
115 if il == ll {
116 // left list exhausted, we got the result
117 break
118 }
119 if ir == lr {
120 // right list exhausted, append what is left to result
121 result = append(result, l[il:]...)
122 break
123 }
124
125 if l[il] == r[ir] {
126 // r contains entry from l, so we skip it
127 il++
128 ir++
129 } else if l[il] < r[ir] {
130 // item il is not in r, append
131 result = append(result, l[il])
132 il++
133 } else {
134 // skip over to next item in r
135 ir++
136 }
137 }
138
139 return result
140}

Callers 7

FetchMethod · 0.92
PublishMethod · 0.92
RemoveMethod · 0.92
aptlyDBCleanupFunction · 0.92
apiDBCleanupFunction · 0.92

Calls

no outgoing calls

Tested by 1