MCPcopy Index your code
hub / github.com/ByteStorage/FlyDB / SDiff

Method SDiff

structure/set.go:196–231  ·  view source on GitHub ↗

SDiff computes the difference between the first and subsequent sets. It returns keys unique to the first set and an error if applicable.

(keys ...string)

Source from the content-addressed store, hash-verified

194// SDiff computes the difference between the first and subsequent sets.
195// It returns keys unique to the first set and an error if applicable.
196func (s *SetStructure) SDiff(keys ...string) ([]string, error) {
197 // If there are no keys, then there's no difference
198 if len(keys) == 0 {
199 return nil, nil
200 }
201
202 first, err := s.checkAndGetSet(keys[0], false)
203 if err != nil {
204 return nil, err
205 }
206
207 // Initialize a set for members of first set
208 mem := make(map[string]struct{})
209 for k := range *first {
210 mem[k] = struct{}{}
211 }
212
213 var diffMembers []string
214 // If member is in the first set and also in another set, remove it.
215 for _, key := range keys[1:] {
216 fs, err := s.checkAndGetSet(key, false)
217 if err != nil {
218 return nil, err
219 }
220 for k := range *fs {
221 // Only delete the existing members in the first set. Do not add members from other sets
222 delete(mem, k)
223 }
224 }
225 // Remaining members in mem are unique to first set.
226 for k := range mem {
227 diffMembers = append(diffMembers, k)
228 }
229
230 return diffMembers, nil
231}
232
233// Keys returns all the keys of the set structure
234func (s *SetStructure) Keys(regx string) ([]string, error) {

Callers

nothing calls this directly

Calls 1

checkAndGetSetMethod · 0.95

Tested by

no test coverage detected