// Flatten flattens the entire tree down to a single merged Config
// structure.
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)
}
626766
func Simplify(inp tree.Expression) tree.Expression {
	return reduceTransformers(inp,
		// X in [P]  ==>  P == Q
		// X in [P, Q, R]  where X and R can be determined to not be equal  ==>  X in [P, Q]
		// X in [P, Q, R]  where X and one of the values can be determined to be equal  ==>  true
		// X notIn [P]  ==>  X != P
		// X notIn [P, Q, R]  where X and R can be determined to not be equal  ==>  X notIn [P, Q]
		// X notIn [P, Q, R]  where X and one of the values can be determined to be equal  ==>  false
		createInclusionSimplifier(),

		// X in [P, Q, R]     ==>  X == P || X == Q || X == R
		// X notIn [P, Q, R]  ==>  X != P && X != Q && X != R
		createInclusionRemoverSimplifier(),

		// X < Y    ==>  Y >= X
		// X <= Y   ==>  Y > X
		createLtExpressionsSimplifier(),

		// Where X and Y can be determined statically:
		// X + Y   ==>  [X+Y]
		// X - Y   ==>  [X-Y]
		// X * Y   ==>  [X*Y]
		// X / Y   ==>  [X/Y]
		// X % Y   ==>  [X%Y]
		// X & Y   ==>  [X&Y]
		// X | Y   ==>  [X|Y]
		// X ^ Y   ==>  [X^Y]
		// X << Y  ==>  [X<<Y]
		// X >> Y  ==>  [X<<Y]
		// ~X      ==>  [~X]
		// Note that these calculations will all be done on 64bit unsigned values
		// - this could lead to different result than if they were evaluated by the BPF engine.
		createArithmeticSimplifier(),

		// Where X and Y can be determined statically:
		// X == Y  where X == Y  ==>  true
		// X == Y  where X != Y  ==>  false
		// X != Y  where X == Y  ==>  false
		// X != Y  where X != Y  ==>  true
		// X > Y   where X > Y   ==>  true
		// X > Y   where X <= Y  ==>  false
		// X >= Y  where X >= Y  ==>  true
		// X >= Y  where X < Y   ==>  false
		// X < Y   where X < Y   ==>  true
		// X < Y   where X >= Y  ==>  false
		// X <= Y  where X <= Y  ==>  true
		// X <= Y  where X > Y   ==>  false
		createComparisonSimplifier(),

		// !true           ==>  false
		// !false          ==>  true
		// false || Y      ==>  Y
		// false || true   ==>  true
		// false || false  ==>  false
		// true  || Y      ==>  true
		// true  && true   ==>  true
		// true  && false  ==>  false
		// true  && Y      ==>  Y
		// false && [any]  ==>  false
		createBooleanSimplifier(),

		// ~X  ==> X ^ 0xFFFFFFFFFFFFFFFF
		createBinaryNegationSimplifier(),

		// Where X can be determined statically (the opposite order is also valid)
		// arg0 == X     ==>  argL0 == X.low && argH0 == X.high
		// arg0 != X     ==>  argL0 != X.low || argH0 != X.high
		// arg0 > X      ==>  argH0 > X.high || (argH0 == X.high && argL0 > X.low)
		// arg0 >= X     ==>  argH0 > X.high || (argH0 == X.high && argL0 >= X.low)
		// arg0 == arg1  ==>  argL0 == argL1 && argH0 == argH1
		// arg0 != arg1  ==>  argL0 != argL1 || argH0 != argH1
		// arg0 > arg1   ==>  argH0 > argH1  || (argH0 == argH1 && argL0 > argL1)
		// arg0 >= arg1  ==>  argH0 > argH1  || (argH0 == argH1 && argL0 >= argL1)
		createFullArgumentSplitterSimplifier(),

		// We repeat some of the simplifiers in the hope that the above operations have opened up new avenues of simplification
		createArithmeticSimplifier(),
		createComparisonSimplifier(),
		createBooleanSimplifier(),
		createBinaryNegationSimplifier(),
	)
}
1061704
func flattenDeploymentStyle(style *codedeploy.DeploymentStyle) []map[string]interface{} {
	if style == nil {
		return nil
	}

	item := make(map[string]interface{})
	if style.DeploymentOption != nil {
		item["deployment_option"] = *style.DeploymentOption
	}
	if style.DeploymentType != nil {
		item["deployment_type"] = *style.DeploymentType
	}

	result := make([]map[string]interface{}, 0, 1)
	result = append(result, item)
	return result
}
253282
func flattenStringList(list []*string) []interface{} {
	vs := make([]interface{}, 0, len(list))
	for _, v := range list {
		vs = append(vs, *v)
	}
	return vs
}
1002659
func flattenMultiMaps(m map[string]interface{}) error {
	for k, v := range m {
		switch v := v.(type) {
		case []map[string]interface{}:
			switch {
			case len(v) > 1:
				return fmt.Errorf("multiple map declarations not supported for variables")
			case len(v) == 1:
				m[k] = v[0]
			}
		}
	}
	return nil
}
1266169
func (c ConfigDataNode) Merge(n ctree.Node) ctree.Node {
	// Because Add only allows the ConfigDataNode type we
	// are safe to convert ctree.Node interface to ConfigDataNode
	cd := n.(*ConfigDataNode)
	t := cd.Table()
	// For the table in the passed ConfigDataNode(converted) add each item to
	// this ConfigDataNode overwriting where needed.
	for k, v := range t {
		c.AddItem(k, v)
	}
	// Return modified version of ConfigDataNode(as ctree.Node)
	return c
}
586500
func (rm ReachMap) FlattenAll(stdlib bool) []string {
	return rm.flatten(func(pkg string) bool { return true }, stdlib)
}
1278998
func flattenPublish(config jsonconfig.Obj) error {
	gallery := []string{}
	blog := []string{}
	config["gallery"] = gallery
	config["blog"] = blog
	published, ok := config["publish"]
	if !ok {
		delete(config, "publish")
		return nil
	}
	pubObj, ok := published.(map[string]interface{})
	if !ok {
		return fmt.Errorf("Was expecting a map[string]interface{} for \"publish\", got %T", published)
	}
	for k, v := range pubObj {
		pub, ok := v.(map[string]interface{})
		if !ok {
			return fmt.Errorf("Was expecting a map[string]interface{} for %s, got %T", k, pub)
		}
		template, rootPermanode, style := "", "", ""
		for pk, pv := range pub {
			val, ok := pv.(string)
			if !ok {
				return fmt.Errorf("Was expecting a string for %s, got %T", pk, pv)
			}
			switch pk {
			case "template":
				template = val
			case "rootPermanode":
				rootPermanode = val
			case "style":
				style = val
			default:
				return fmt.Errorf("Unknown key %q in %s", pk, k)
			}
		}
		if template == "" || rootPermanode == "" {
			return fmt.Errorf("missing \"template\" key or \"rootPermanode\" key in %s", k)
		}
		obj := []string{k, rootPermanode, style}
		config[template] = obj
	}

	delete(config, "publish")
	return nil
}
681485
func (n *normalizer) Normalize(un *unstructured.Unstructured) error {
	matched := make([]normalizerPatch, 0)
	for _, patch := range n.patches {
		groupKind := un.GroupVersionKind().GroupKind()
		if groupKind == patch.groupKind &&
			(patch.name == "" || patch.name == un.GetName()) &&
			(patch.namespace == "" || patch.namespace == un.GetNamespace()) {

			matched = append(matched, patch)
		}
	}
	if len(matched) == 0 {
		return nil
	}

	docData, err := json.Marshal(un)
	if err != nil {
		return err
	}

	for _, patch := range matched {
		patchedData, err := patch.patch.Apply(docData)
		if err != nil {
			// bug?
			if strings.HasPrefix(err.Error(), "Unable to remove nonexistent key") {
				continue
			}
			return err
		}
		docData = patchedData
	}

	err = json.Unmarshal(docData, un)
	if err != nil {
		return err
	}
	return nil
}
282115
func FlattenFn(fieldName string, field reflect.Value, values *url.Values) {
	l := field.Len()
	if l > 0 {
		for i := 0; i < l; i++ {
			str := field.Index(i).String()
			values.Set(fieldName+"."+strconv.Itoa(i+1), str)
		}
	}
}
534416
func (p *trie) merge(m matcher) (matcher, error) {
	other, ok := m.(*trie)
	if !ok {
		return nil, fmt.Errorf("Can't merge %T and %T", p, m)
	}
	mapper := p.mapper.equivalent(other.mapper)
	if mapper == nil {
		return nil, fmt.Errorf("Can't merge %T and %T", p, m)
	}

	root, err := p.root.merge(other.root)
	if err != nil {
		return nil, err
	}
	return &trie{root: root, mapper: mapper}, nil
}
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)
}
656615
func Flatten(g Grouping) *Table {
	groups := g.Tables()
	switch len(groups) {
	case 0:
		return new(Table)

	case 1:
		return g.Table(groups[0])
	}

	tabs := make([]*Table, len(groups))
	for i, gid := range groups {
		tabs[i] = g.Table(gid)
	}

	return concatRows(tabs...)
}
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
}
986578
func (image *Image) Flatten() error {
	if image.image == nil {
		return errors.New(fmt.Sprintf("RBD image %s is not open", image.name))
	}

	return GetError(C.rbd_flatten(image.image))
}
1205657
func FlattenJsonMap(m map[string]interface{}) (map[string][]string, error) {
	outMap := make(map[string][]string, len(m))
	if err := flattenJson("", outMap, m); err != nil {
		return nil, err
	}
	return outMap, nil
}
683620
func (c ConfigPolicyNode) Merge(n ctree.Node) ctree.Node {
	// Because Add only allows the ConfigPolicyNode type we
	// are safe to convert ctree.Node interface to ConfigPolicyNode
	cd := n.(*ConfigPolicyNode)
	// For the rules in the passed ConfigPolicyNode(converted) add each rule to
	// this ConfigPolicyNode overwriting where needed.
	no := NewPolicyNode()
	for _, r := range c.rules {
		no.Add(r)
	}

	for _, r := range cd.rules {

		no.Add(r)
	}
	// Return modified version of ConfigPolicyNode(as ctree.Node)
	return no
}