code: func (t *SwitchesTable) computeChanges(c context.Context, datacenters []*config.Datacenter) error {
  	cfgs := make(map[string]*Switch, len(datacenters))
  	for _, dc := range datacenters {
  		for _, rack := range dc.Rack {
  			for _, cfg := range rack.Switch {
  				id, ok := t.racks[rack.Name]
  				if !ok {
  					return errors.Reason("failed to determine rack ID for switch %q: rack %q does not exist", cfg.Name, rack.Name).Err()
  				}
  				cfgs[cfg.Name] = &Switch{
  					Switch: config.Switch{
  						Name:        cfg.Name,
  						Description: cfg.Description,
  						Ports:       cfg.Ports,
  						State:       cfg.State,
  					},
  					RackId: id,
  				}
  			}
  		}
  	}
  
  	for _, s := range t.current {
  		if cfg, ok := cfgs[s.Name]; ok {
  			// Switch found in the config.
  			if t.needsUpdate(s, cfg) {
  				// Switch doesn't match the config.
  				cfg.Id = s.Id
  				t.updates = append(t.updates, cfg)
  			}
  			// Record that the switch config has been seen.
  			delete(cfgs, cfg.Name)
  		} else {
  			// Switch not found in the config.
  			t.removals = append(t.removals, s)
  		}
  	}
  
  	// Switches remaining in the map are present in the config but not the database.
  	// Iterate deterministically over the slices to determine which switches need to be added.
  	for _, dc := range datacenters {
  		for _, rack := range dc.Rack {
  			for _, cfg := range rack.Switch {
  				if s, ok := cfgs[cfg.Name]; ok {
  					t.additions = append(t.additions, s)
  				}
  			}
  		}
  	}
  	return nil
  }
docs: // computeChanges computes the changes that need to be made to the switches in the database.