// AddVSchemaTable takes a list of vschema tables as input and
// creates a table with multiple route options. It returns a
// list of vindex maps, one for each input.
191013
func (st *symtab) AddVSchemaTable(alias sqlparser.TableName, vschemaTables []*vindexes.Table, rb *route) (vindexMaps []map[*column]vindexes.Vindex, err error) {
	t := &table{
		alias:  alias,
		origin: rb,
	}

	vindexMaps = make([]map[*column]vindexes.Vindex, len(vschemaTables))
	for i, vst := range vschemaTables {
		// If any input is authoritative, we make the table authoritative.
		// TODO(sougou): vschema builder should validate that authoritative columns match.
		if vst.ColumnListAuthoritative {
			t.isAuthoritative = true
		}

		for _, col := range vst.Columns {
			t.addColumn(col.Name, &column{
				origin: rb,
				st:     st,
				typ:    col.Type,
			})
		}

		var vindexMap map[*column]vindexes.Vindex
		for _, cv := range vst.ColumnVindexes {
			for i, cvcol := range cv.Columns {
				col, ok := t.columns[cvcol.Lowered()]
				if !ok {
					col = &column{
						origin: rb,
						st:     st,
					}
					t.addColumn(cvcol, col)
				}
				if i == 0 {
					// For now, only the first column is used for vindex Map functions.
					if vindexMap == nil {
						vindexMap = make(map[*column]vindexes.Vindex)
					}
					vindexMap[col] = cv.Vindex
				}
			}
		}
		vindexMaps[i] = vindexMap

		if ai := vst.AutoIncrement; ai != nil {
			if _, ok := t.columns[ai.Column.Lowered()]; !ok {
				t.addColumn(ai.Column, &column{
					origin: rb,
					st:     st,
				})
			}
		}

	}
	if err := st.AddTable(t); err != nil {
		return nil, err
	}
	return vindexMaps, nil
}
930784
func addSchemeIfMissing(defaultScheme string, url string) string {
	if url != "" && !strings.Contains(url, "://") {
		url = defaultScheme + "://" + url
	}
	return url
}
646752
func (vm *ViewLists) Add(tag string, v Views) error {
	if vm.Has(tag) {
		return ErrExists
	}

	var ind int

	vm.ro.RLock()
	ind = len(vm.lists)
	vm.ro.RUnlock()

	vm.ro.RLock()
	vm.lists = append(vm.lists, v)
	vm.ro.RUnlock()

	vm.mo.Lock()
	vm.keys[tag] = ind
	vm.mo.Unlock()

	return nil
}
1111545
func (table *RegommendTable) Add(key interface{}, data map[interface{}]float64) *RegommendItem {
	item := CreateRegommendItem(key, data)

	// Add item to engine.
	table.Lock()
	table.items[key] = &item

	// engine values so we don't keep blocking the mutex.
	addedItem := table.addedItem
	table.Unlock()

	// Trigger callback after adding an item to engine.
	if addedItem != nil {
		addedItem(&item)
	}

	return &item
}
1277780
func (g *Mutable) Add(v, w int) {
	g.AddCost(v, w, 0)
}
632396
func checksTableSchema() *memdb.TableSchema {
	return &memdb.TableSchema{
		Name: "checks",
		Indexes: map[string]*memdb.IndexSchema{
			"id": &memdb.IndexSchema{
				Name:         "id",
				AllowMissing: false,
				Unique:       true,
				Indexer: &memdb.CompoundIndex{
					Indexes: []memdb.Indexer{
						&memdb.StringFieldIndex{
							Field:     "Node",
							Lowercase: true,
						},
						&memdb.StringFieldIndex{
							Field:     "CheckID",
							Lowercase: true,
						},
					},
				},
			},
			"status": &memdb.IndexSchema{
				Name:         "status",
				AllowMissing: false,
				Unique:       false,
				Indexer: &memdb.StringFieldIndex{
					Field:     "Status",
					Lowercase: false,
				},
			},
			"service": &memdb.IndexSchema{
				Name:         "service",
				AllowMissing: true,
				Unique:       false,
				Indexer: &memdb.StringFieldIndex{
					Field:     "ServiceName",
					Lowercase: true,
				},
			},
			"node": &memdb.IndexSchema{
				Name:         "node",
				AllowMissing: true,
				Unique:       false,
				Indexer: &memdb.StringFieldIndex{
					Field:     "Node",
					Lowercase: true,
				},
			},
			"node_service_check": &memdb.IndexSchema{
				Name:         "node_service_check",
				AllowMissing: true,
				Unique:       false,
				Indexer: &memdb.CompoundIndex{
					Indexes: []memdb.Indexer{
						&memdb.StringFieldIndex{
							Field:     "Node",
							Lowercase: true,
						},
						&memdb.FieldSetIndex{
							Field: "ServiceID",
						},
					},
				},
			},
			"node_service": &memdb.IndexSchema{
				Name:         "node_service",
				AllowMissing: true,
				Unique:       false,
				Indexer: &memdb.CompoundIndex{
					Indexes: []memdb.Indexer{
						&memdb.StringFieldIndex{
							Field:     "Node",
							Lowercase: true,
						},
						&memdb.StringFieldIndex{
							Field:     "ServiceID",
							Lowercase: true,
						},
					},
				},
			},
		},
	}
}
292943
func (st *symtab) AddTable(t *table) error {
	if rb, ok := t.origin.(*route); !ok || rb.Resolve() != st.singleRoute {
		st.singleRoute = nil
	}
	if _, ok := st.tables[t.alias]; ok {
		return fmt.Errorf("duplicate symbol: %s", sqlparser.String(t.alias))
	}
	st.tables[t.alias] = t
	st.tableNames = append(st.tableNames, t.alias)

	// update the uniqueColumns list, and eliminate
	// duplicate symbols if found.
	for colname, c := range t.columns {
		c.st = st
		if _, ok := st.uniqueColumns[colname]; ok {
			// Keep the entry, but make it nil. This will
			// ensure that yet another column of the same name
			// doesn't get added back in.
			st.uniqueColumns[colname] = nil
			continue
		}
		st.uniqueColumns[colname] = c
	}
	return nil
}
1092197
func (pb *primitiveBuilder) processDMLTable(tableExprs sqlparser.TableExprs) (*routeOption, error) {
	if err := pb.processTableExprs(tableExprs); err != nil {
		return nil, err
	}
	rb, ok := pb.bldr.(*route)
	if !ok {
		return nil, errors.New("unsupported: multi-shard or vindex write statement")
	}
	ro := rb.routeOptions[0]
	for _, sub := range ro.substitutions {
		*sub.oldExpr = *sub.newExpr
	}
	return ro, nil
}
111467
func (t Type) Add(route string, h sqsconsumer.MessageHandlerFunc) {
	t[route] = h
}
847735
func addKnownTypes(scheme *runtime.Scheme) error {
	scheme.AddKnownTypes(SchemeGroupVersion,
		&Template{},
		&TemplateList{},
		&TemplateInstance{},
		&TemplateInstanceList{},
		&BrokerTemplateInstance{},
		&BrokerTemplateInstanceList{},
	)
	return nil
}
790289
func (v1 Vec2) Add(v2 Vec2) Vec2 {
	return Vec2{v1[0] + v2[0], v1[1] + v2[1]}
}
529512
func (m *InMemApplyer) AddOrUpdateOnSchema(s *Schema, v interface{}) error {

	// All Schemas must also have an info-schema
	if s.InfoSchema == nil {
		s.InfoSchema = NewInfoSchema("schema", s)
	}

	// The info-schema if new will need an actual store, the provider
	// will add it to the schema.
	if s.InfoSchema.DS == nil {
		m.schemaSource(s)
	}

	// Find the type of operation being updated.
	switch v := v.(type) {
	case *Table:
		u.Debugf("%p:%s InfoSchema P:%p  adding table %q", s, s.Name, s.InfoSchema, v.Name)
		s.InfoSchema.DS.Init() // Wipe out cache, it is invalid
		s.mu.Lock()
		s.addTable(v)
		s.mu.Unlock()
		s.InfoSchema.refreshSchemaUnlocked()
	case *Schema:

		u.Debugf("%p:%s InfoSchema P:%p  adding schema %q s==v?%v", s, s.Name, s.InfoSchema, v.Name, s == v)
		if s == v {
			// s==v means schema has been updated
			m.reg.mu.Lock()
			_, exists := m.reg.schemas[s.Name]
			if !exists {
				m.reg.schemas[s.Name] = s
				m.reg.schemaNames = append(m.reg.schemaNames, s.Name)
			}
			m.reg.mu.Unlock()

			s.mu.Lock()
			s.refreshSchemaUnlocked()
			s.mu.Unlock()
		} else {
			// since s != v then this is a child schema
			s.addChildSchema(v)
			s.mu.Lock()
			s.refreshSchemaUnlocked()
			s.mu.Unlock()
		}
		if s.Name != "schema" {
			s.InfoSchema.refreshSchemaUnlocked()
		}
	default:
		u.Errorf("invalid type %T", v)
		return fmt.Errorf("Could not find %T", v)
	}

	return nil
}
829477
func (ts *Server) UpdateSrvVSchema(ctx context.Context, cell string, srvVSchema *vschemapb.SrvVSchema) error {
	conn, err := ts.ConnForCell(ctx, cell)
	if err != nil {
		return err
	}

	nodePath := SrvVSchemaFile
	data, err := proto.Marshal(srvVSchema)
	if err != nil {
		return err
	}
	_, err = conn.Update(ctx, nodePath, data, nil)
	return err
}
353123
func (table *TableElem) AddCreatable(c Creatable) {
	table.creates = append(table.creates, c)
}
419879
func (r *Router) AddRegex(name, regex string) error {
	return r.dynamicRoutes.Set(name, regex)
}
10523
func ApplyRouteTable(r transport.RouteTable, m Router) transport.RouteTable {
	if m == nil {
		return r
	}
	return routeTableWithMiddleware{r: r, m: m}
}
1203332
func (b *builder) buildListSchema() *spec.Schema {
	name := definitionPrefix + util.ToRESTFriendlyName(fmt.Sprintf("%s/%s/%s", b.group, b.version, b.kind))
	doc := fmt.Sprintf("List of %s. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md", b.plural)
	s := new(spec.Schema).WithDescription(fmt.Sprintf("%s is a list of %s", b.listKind, b.kind)).
		WithRequired("items").
		SetProperty("items", *spec.ArrayProperty(spec.RefSchema(name)).WithDescription(doc)).
		SetProperty("metadata", getDefinition(listMetaType))
	addTypeMetaProperties(s)
	s.AddExtension(endpoints.ROUTE_META_GVK, []map[string]string{
		{
			"group":   b.group,
			"version": b.version,
			"kind":    b.listKind,
		},
	})
	return s
}