func (stringSetSuite) TestUninitialized(c *gc.C) { var uninitialized set.Strings c.Assert(uninitialized.Size(), gc.Equals, 0) c.Assert(uninitialized.IsEmpty(), gc.Equals, true) // You can get values and sorted values from an unitialized set. AssertValues(c, uninitialized) // All contains checks are false c.Assert(uninitialized.Contains("foo"), gc.Equals, false) // Remove works on an uninitialized Strings uninitialized.Remove("foo") var other set.Strings // Union returns a new set that is empty but initialized. c.Assert(uninitialized.Union(other), gc.DeepEquals, set.NewStrings()) c.Assert(uninitialized.Intersection(other), gc.DeepEquals, set.NewStrings()) c.Assert(uninitialized.Difference(other), gc.DeepEquals, set.NewStrings()) other = set.NewStrings("foo", "bar") c.Assert(uninitialized.Union(other), gc.DeepEquals, other) c.Assert(uninitialized.Intersection(other), gc.DeepEquals, set.NewStrings()) c.Assert(uninitialized.Difference(other), gc.DeepEquals, set.NewStrings()) c.Assert(other.Union(uninitialized), gc.DeepEquals, other) c.Assert(other.Intersection(uninitialized), gc.DeepEquals, set.NewStrings()) c.Assert(other.Difference(uninitialized), gc.DeepEquals, other) // Once something is added, the set becomes initialized. uninitialized.Add("foo") AssertValues(c, uninitialized, "foo") }
func (w *actionWatcher) merge(changes *set.Strings, updates map[interface{}]bool) error { for id, exists := range updates { if id, ok := id.(string); ok { if exists { changes.Add(id) } else { changes.Remove(id) } } else { return fmt.Errorf("id is not of type string") } } return nil }
// merge cleans up the pending changes to account for actionId's being // removed before this watcher consumes them, and to account for the slight // potential overlap between the inital actionIds pending before the watcher // starts, and actionId's the watcher detects func (w *actionWatcher) merge(changes, initial set.Strings, updates map[interface{}]bool) error { for id, exists := range updates { switch id := id.(type) { case string: if exists { if !initial.Contains(id) { changes.Add(id) } } else { changes.Remove(id) } default: return errors.Errorf("id is not of type string, got %T", id) } } return nil }
func (w *minUnitsWatcher) merge(serviceNames *set.Strings, change watcher.Change) error { serviceName := change.Id.(string) if change.Revno == -1 { delete(w.known, serviceName) serviceNames.Remove(serviceName) return nil } doc := minUnitsDoc{} if err := w.st.minUnits.FindId(serviceName).One(&doc); err != nil { return err } revno, known := w.known[serviceName] w.known[serviceName] = doc.Revno if !known || doc.Revno > revno { serviceNames.Add(serviceName) } return nil }