// Flatten JSON hierarchy to produce field name and field value
// Parameters:
//    item: Item map to flatten
//    fields: Map to store generated fields.
//    id: Prefix for top level metric (empty string "")
// Returns:
//    void
427812
func (h *GrayLog) flatten(item map[string]interface{}, fields map[string]interface{}, id string) {
	if id != "" {
		id = id + "_"
	}
	for k, i := range item {
		switch i.(type) {
		case int:
			fields[id+k] = i.(float64)
		case float64:
			fields[id+k] = i.(float64)
		case map[string]interface{}:
			h.flatten(i.(map[string]interface{}), fields, id+k)
		default:
		}
	}
}
713030
func (cc *ConsolidatorCache) Items() []ConsolidatorCacheItem {
	items := cc.LRUCache.Items()
	ret := make([]ConsolidatorCacheItem, len(items))
	for i, v := range items {
		ret[i] = ConsolidatorCacheItem{Query: v.Key, Count: v.Value.(*ccount).get()}
	}
	return ret
}
1364595
func (hm *SyncedHashMap) Items() (ci chan Item) {
	go func() {
		hm.RLock()
		defer hm.RUnlock()
		defer close(ci)
		for k := range hm.keys {
			i := Item{(*hm).keys[k], (*hm).values[k]}
			ci <- i
		}
	}()
	return
}
159432
func Flatten(list cty.Value) (cty.Value, error) {
	return FlattenFunc.Call([]cty.Value{list})
}
951960
func flatten(key string, value interface{}, vars map[string]string) {
	switch value.(type) {
	case string:
		log.Debug("setting key %s to: %s", key, value)
		vars[key] = value.(string)
	case map[string]interface{}:
		inner := value.(map[string]interface{})
		for innerKey, innerValue := range inner {
			innerKey = path.Join(key, "/", innerKey)
			flatten(innerKey, innerValue, vars)
		}
	default: // we don't know how to handle non string or maps of strings
		log.Warning("type of '%s' is not supported (%T)", key, value)
	}
}
1325812
func (i *Item) UnmarshalJSON(value []byte) error {
	return json.Unmarshal(value, &i.Value)
}
885385
func (bk *Backend) flatten(bucket []string) string {
	// Convert ["foo", "bar"] to "foo/bar"
	raw := filepath.Join(bucket...)

	// URL encode bucket from "foo/bar" to "foo%2Fbar".
	flat := url.QueryEscape(raw)

	return filepath.Join(bk.rootDir, flat)
}
1341952
func Flatten(resources []mesos.Resource, opts ...FlattenOpt) []mesos.Resource {
	var flattened mesos.Resources
	fc := &flattenConfig{}
	for _, f := range opts {
		f(fc)
	}
	if fc.role == "" {
		fc.role = mesos.DefaultRole
	}
	// we intentionally manipulate a copy 'r' of the item in resources
	for _, r := range resources {
		r.Role = &fc.role
		r.Reservation = fc.reservation
		flattened.Add1(r)
	}
	return flattened
}
184030
func (t itemType) String() string {
	for k, v := range builtinIdents {
		if v == t {
			return k
		}
	}
	for k, v := range arithmeticItemsBySymbol {
		if v == t {
			return k
		}
	}
	var r, ok = map[itemType]string{
		itemEOF:              "<eof>",
		itemEquals:           "=",
		itemError:            "<error>",
		itemText:             "<text>",
		itemLeftDelim:        "{",
		itemRightDelim:       "}",
		itemRightDelimEnd:    "/}",
		itemIdent:            "<ident>",
		itemDollarIdent:      "<$ident>",
		itemDotIdent:         "<.ident>",
		itemQuestionDotIdent: "<?.ident>",
		itemDotIndex:         "<.N>",
		itemQuestionDotIndex: "<?.N>",
		itemLeftBracket:      "[",
		itemRightBracket:     "]",
		itemQuestionKey:      "?[",
	}[t]
	if ok {
		return r
	}
	return fmt.Sprintf("item(%d)", t)
}
1127050
func (b *Uniform) Serialize() interface{} {
	data := make(map[string]interface{})
	data["strategy"] = "uniform selection"
	data["counts"] = b.counts
	data["values"] = b.values
	return data
}
1351918
func (t *LLRB) AscendGreaterOrEqual(pivot Item, iterator ItemIterator) {
	t.ascendGreaterOrEqual(t.root, pivot, iterator)
}
196316
func flattenElastiCacheParameters(list []*elasticache.Parameter) []map[string]interface{} {
	result := make([]map[string]interface{}, 0, len(list))
	for _, i := range list {
		if i.ParameterValue != nil {
			result = append(result, map[string]interface{}{
				"name":  strings.ToLower(*i.ParameterName),
				"value": *i.ParameterValue,
			})
		}
	}
	return result
}
272070
func (as *accountSet) flatten() []common.Address {
	if as.cache == nil {
		accounts := make([]common.Address, 0, len(as.accounts))
		for account := range as.accounts {
			accounts = append(accounts, account)
		}
		as.cache = &accounts
	}
	return *as.cache
}
716926
func (def *Synthdef) flattenInput(params Params, ugen *Ugen, input Input) {
	switch v := input.(type) {
	case *Ugen:
		_, idx, _ := def.addUgen(v)

		// In has different behavior than other ugens when it is multichannel expanded.
		// Each channel of its output gets mapped to a single channel of the expression
		// tree above it. [briansorahan]
		if v.Name == "In" {
			ugen.Inputs = append(ugen.Inputs, UgenInput{
				UgenIndex:   int32(idx),
				OutputIndex: int32(def.inidx),
			})
			def.inidx++
			break
		}
		for outputIndex := range v.Outputs {
			ugen.Inputs = append(ugen.Inputs, UgenInput{
				UgenIndex:   int32(idx),
				OutputIndex: int32(outputIndex),
			})
		}
	case C:
		idx := def.addConstant(v)
		ugen.Inputs = append(ugen.Inputs, UgenInput{
			UgenIndex:   -1,
			OutputIndex: int32(idx),
		})
	case *param:
		idx := v.Index()
		ugen.Inputs = append(ugen.Inputs, UgenInput{
			UgenIndex:   0,
			OutputIndex: idx,
		})
	case MultiInput:
		for _, min := range v.InputArray() {
			switch x := min.(type) {
			case *Ugen:
				_, idx, _ := def.addUgen(x)
				// will we ever need to use a different output index? [bps]
				for outputIndex := range x.Outputs {
					ugen.Inputs = append(ugen.Inputs, UgenInput{
						UgenIndex:   int32(idx),
						OutputIndex: int32(outputIndex),
					})
				}
			case C:
				ugen.Inputs = append(ugen.Inputs, UgenInput{
					UgenIndex:   -1,
					OutputIndex: int32(def.addConstant(x)),
				})
			case *param:
				ugen.Inputs = append(ugen.Inputs, UgenInput{
					UgenIndex:   0,
					OutputIndex: x.Index(),
				})
			}
		}
	}
}
334057
func (t *configTree) Flatten() (*Config, error) {
	// No children is easy: we're already merged!
	if len(t.Children) == 0 {
		return t.Config, nil
	}

	// Depth-first, merge all the children first.
	childConfigs := make([]*Config, len(t.Children))
	for i, ct := range t.Children {
		c, err := ct.Flatten()
		if err != nil {
			return nil, err
		}

		childConfigs[i] = c
	}

	// Merge all the children in order
	config := childConfigs[0]
	childConfigs = childConfigs[1:]
	for _, config2 := range childConfigs {
		var err error
		config, err = Merge(config, config2)
		if err != nil {
			return nil, err
		}
	}

	// Merge the final merged child config with our own
	return Merge(config, t.Config)
}
425742
func (items *Items) MergeIn(subSchema *JsonSubSchema, skipFields StringSet) {
	if items == nil || len(items.Items) == 0 {
		// nothing to do
		return
	}
	p := reflect.ValueOf(subSchema).Elem()
	// loop through all struct fields of Jsonsubschema
	for i := 0; i < p.NumField(); i++ {
		// don't copy fields that are blacklisted, or that aren't pointers
		if skipFields[p.Type().Field(i).Name] || p.Field(i).Kind() != reflect.Ptr {
			continue
		}
		// loop through all items (e.g. the list of oneOf schemas)
		for _, item := range items.Items {
			c := reflect.ValueOf(item).Elem()
			// only replace destination value if it is currently nil
			if destination, source := c.Field(i), p.Field(i); destination.IsNil() {

				// To copy the pointer, we would just:
				//   destination.Set(source)
				// However, we want to make copies of the entries, rather than
				// copy the pointers, so that future modifications of a copied
				// subschema won't update the source schema. Note: this is only
				// a top-level copy, not a deep copy, but is better than nothing.

				// dereference the pointer to get the value
				targetValue := reflect.Indirect(source)
				if targetValue.IsValid() {
					// create a new value to store it
					newValue := reflect.New(targetValue.Type()).Elem()
					// copy the value into the new value
					newValue.Set(targetValue)
					// create a new pointer to point to the new value
					newPointer := reflect.New(targetValue.Addr().Type()).Elem()
					// set that pointer to the address of the new value
					newPointer.Set(newValue.Addr())
					// copy the new pointer to the destination
					destination.Set(newPointer)
				}
			}
			// If we wanted to "move" instead of "copy", we could reset source
			// to nil with:
			//   source.Set(reflect.Zero(source.Type()))
		}
	}
}
974625
func (s *Bucket) upsert(item *Item) error {
	if s == nil {
		return fmt.Errorf("nil storage bucket")
	}

	if item == nil {
		return fmt.Errorf("nil item")
	}

	if item.ID == "" {
		return fmt.Errorf("missing item ID")
	}

	// Look for an item with matching key and don't modify the collection
	// while iterating
	foundIdx := -1
	for itemIdx, bucketItems := range s.Items {
		if bucketItems.ID == item.ID {
			foundIdx = itemIdx
			break
		}
	}

	// If there is no match, append the item, otherwise update it
	if foundIdx == -1 {
		s.Items = append(s.Items, item)
	} else {
		s.Items[foundIdx] = item
	}

	return nil
}