// mapToCFDictionary converts a Go map[C.CFTypeRef]C.CFTypeRef to a
// CFDictionaryRef.
436768
func mapToCFDictionary(gomap map[C.CFTypeRef]C.CFTypeRef) C.CFDictionaryRef {
	var (
		n      = len(gomap)
		keys   = make([]unsafe.Pointer, 0, n)
		values = make([]unsafe.Pointer, 0, n)
	)

	for k, v := range gomap {
		keys = append(keys, unsafe.Pointer(k))
		values = append(values, unsafe.Pointer(v))
	}

	return C.CFDictionaryCreate(nilCFAllocatorRef, &keys[0], &values[0], C.CFIndex(n), nil, nil)
}
323703
func MapTo(v, source interface{}, others ...interface{}) error {
	return MapToWithMapper(v, nil, source, others...)
}
25422
func MapValueForKey(m yaml.MapSlice, key string) interface{} {
	for _, item := range m {
		itemKey, ok := item.Key.(string)
		if ok && key == itemKey {
			return item.Value
		}
	}
	return nil
}
66531
func Convert(ref C.CFTypeRef) (interface{}, error) {
	typeID := C.CFGetTypeID(ref)
	if typeID == C.CFStringGetTypeID() {
		return CFStringToString(C.CFStringRef(ref)), nil
	} else if typeID == C.CFDictionaryGetTypeID() {
		return ConvertCFDictionary(C.CFDictionaryRef(ref))
	} else if typeID == C.CFArrayGetTypeID() {
		arr := CFArrayToArray(C.CFArrayRef(ref))
		results := make([]interface{}, 0, len(arr))
		for _, ref := range arr {
			v, err := Convert(ref)
			if err != nil {
				return nil, err
			}
			results = append(results, v)
			return results, nil
		}
	} else if typeID == C.CFDataGetTypeID() {
		b, err := CFDataToBytes(C.CFDataRef(ref))
		if err != nil {
			return nil, err
		}
		return b, nil
	} else if typeID == C.CFNumberGetTypeID() {
		return CFNumberToInterface(C.CFNumberRef(ref)), nil
	} else if typeID == C.CFBooleanGetTypeID() {
		if C.CFBooleanGetValue(C.CFBooleanRef(ref)) != 0 {
			return true, nil
		}
		return false, nil
	}

	return nil, fmt.Errorf("Invalid type: %s", CFTypeDescription(ref))
}
334531
func StringToStringValueFunc() mapstructure.DecodeHookFunc {
	return func(
		f reflect.Type,
		t reflect.Type,
		data interface{}) (interface{}, error) {
		if f.Kind() != reflect.String {
			return data, nil
		}

		val := StringValue{}
		if t != reflect.TypeOf(val) {
			return data, nil
		}
		val.v = new(string)
		*(val.v) = data.(string)
		return val, nil
	}
}
707960
func stringKeysFromMap(m interface{}) (keys []string) {
	for _, k := range reflect.ValueOf(m).MapKeys() {
		keys = append(keys, k.String())
	}
	return
}
683944
func (p *gc_parser) parse_map_type() ast.Expr {
	p.expect_keyword("map")
	p.expect('[')
	key := p.parse_type()
	p.expect(']')
	elt := p.parse_type()
	return &ast.MapType{Key: key, Value: elt}
}
646771
func KeysOfStringInterfaceMap(m map[string]interface{}) []string {
	keys := make([]string, len(m))

	i := 0
	for k := range m {
		keys[i] = k
		i++
	}

	return keys
}
1131963
func fieldNameMapping(obj interface{}) map[string]string {
	st := reflect.TypeOf(obj)
	fl := st.NumField()

	jsonToForce := make(map[string]string, fl)

	for i := 0; i < fl; i++ {
		sf := st.Field(i)
		jName := strings.SplitN(sf.Tag.Get("json"), ",", 2)[0]
		fName := strings.SplitN(sf.Tag.Get("force"), ",", 2)[0]

		if jName == "-" {
			continue
		}

		if fName == "-" {
			continue
		}

		if jName == "" {
			jName = sf.Name
		}

		if fName == "" {
			fName = sf.Name
		}

		jsonToForce[jName] = fName
	}

	for k, v := range baseFieldNameMap {
		jsonToForce[k] = v
	}

	return jsonToForce
}
96482
func MapToCFDictionary(m map[C.CFTypeRef]C.CFTypeRef) (C.CFDictionaryRef, error) {
	var keys, values []C.uintptr_t
	for key, value := range m {
		keys = append(keys, C.uintptr_t(key))
		values = append(values, C.uintptr_t(value))
	}
	numValues := len(values)
	var keysPointer, valuesPointer *C.uintptr_t
	if numValues > 0 {
		keysPointer = &keys[0]
		valuesPointer = &values[0]
	}
	cfDict := C.CFDictionaryCreateSafe2(C.kCFAllocatorDefault, keysPointer, valuesPointer, C.CFIndex(numValues), &C.kCFTypeDictionaryKeyCallBacks, &C.kCFTypeDictionaryValueCallBacks)
	if cfDict == 0 {
		return 0, fmt.Errorf("CFDictionaryCreate failed")
	}
	return cfDict, nil
}
1356556
func convertMapsToStringKeyMaps(i interface{}) (res interface{}, err error) {
	switch reflect.TypeOf(i).Kind() {
	case reflect.Map:
		res := make(map[string]interface{})
		v := reflect.ValueOf(i)
		for _, k := range v.MapKeys() {
			res[fmt.Sprintf("%v", k)], err = convertMapsToStringKeyMaps(v.MapIndex(k).Interface())
			if err != nil {
				return nil, err
			}
		}
		return res, nil
	case reflect.Slice:
		res := make([]interface{}, len(i.([]interface{})))
		for k, v := range i.([]interface{}) {
			res[k], err = convertMapsToStringKeyMaps(v)
			if err != nil {
				return nil, err
			}
		}
		return res, nil

	default:
		return i, nil
	}
}
664694
func (c *Config) mapOperationsToDefinitions() {
	for _, d := range c.Definitions.All {
		if d.IsInlined {
			continue
		}

		for i := range c.OperationCategories {
			oc := c.OperationCategories[i]
			for j := range oc.OperationTypes {
				ot := oc.OperationTypes[j]
				operationId := c.getOperationId(ot.Match, d.GetOperationGroupName(), d.Version, d.Name)
				c.setOperation(operationId, "Namespaced", &ot, &oc, d)
				c.setOperation(operationId, "", &ot, &oc, d)
			}

			if len(oc.Operations) > 0 {
				d.OperationCategories = append(d.OperationCategories, &oc)
			}
		}
	}
}
500768
func CFDictionaryToMap(cfDict C.CFDictionaryRef) (m map[C.CFTypeRef]uintptr) {
	count := C.CFDictionaryGetCount(cfDict)
	if count > 0 {
		keys := make([]C.CFTypeRef, count)
		values := make([]C.CFTypeRef, count)
		C.CFDictionaryGetKeysAndValues(cfDict, (*unsafe.Pointer)(&keys[0]), (*unsafe.Pointer)(&values[0]))
		m = make(map[C.CFTypeRef]uintptr, count)
		for i := C.CFIndex(0); i < count; i++ {
			k := keys[i]
			v := values[i]
			m[k] = uintptr(v)
		}
	}
	return
}
1140327
func LabelFilter(key, value string) map[string][]string {
	return map[string][]string{
		"label": {fmt.Sprintf("%s=%s", key, value)},
	}
}
605044
func convertMap(in map[interface{}]interface{}) map[string]interface{} {
  rtn := make(map[string]interface{})
  for key, val := range in {
    // if the value is a map of interface interfaces
    // make sure to convert them as well    
    var newValue interface{}
    switch val.(type) {
      case []interface{}:
        newValue = convertArray(val.([]interface{}))
      case map[interface{}]interface{}:
        newValue = convertMap(val.(map[interface{}]interface{}))
      default:
        newValue = val
    }

    switch key.(type) {
    case string:
      rtn[key.(string)] = newValue
    }
  }

  return rtn  
}
1363264
func (s *SegmentBase) Dictionary(field string) (segment.TermDictionary, error) {
	dict, err := s.dictionary(field)
	if err == nil && dict == nil {
		return &segment.EmptyDictionary{}, nil
	}
	return dict, err
}
1131372
func (schema *Schema) mapOfSchemasValue(v interface{}) *[]*NamedSchema {
	switch v := v.(type) {
	default:
		fmt.Printf("mapOfSchemasValue: unexpected type %T\n", v)
	case yaml.MapSlice:
		m := make([]*NamedSchema, 0)
		for _, mapItem := range v {
			k2 := mapItem.Key.(string)
			v2 := mapItem.Value
			pair := &NamedSchema{Name: k2, Value: NewSchemaFromObject(v2)}
			m = append(m, pair)
		}
		return &m
	}
	return nil
}