// Code derived from go/src/runtime/hashmap.go
175755
func (v *Variable) mapIterator() *mapIterator {
	sv := v.clone()
	sv.RealType = resolveTypedef(&(sv.RealType.(*godwarf.MapType).TypedefType))
	sv = sv.maybeDereference()
	v.Base = sv.Addr

	maptype, ok := sv.RealType.(*godwarf.StructType)
	if !ok {
		v.Unreadable = fmt.Errorf("wrong real type for map")
		return nil
	}

	it := &mapIterator{v: v, bidx: 0, b: nil, idx: 0}

	if sv.Addr == 0 {
		it.numbuckets = 0
		return it
	}

	v.mem = cacheMemory(v.mem, v.Base, int(v.RealType.Size()))

	for _, f := range maptype.Field {
		var err error
		field, _ := sv.toField(f)
		switch f.Name {
		case "count":
			v.Len, err = field.asInt()
		case "B":
			var b uint64
			b, err = field.asUint()
			it.numbuckets = 1 << b
			it.oldmask = (1 << (b - 1)) - 1
		case "buckets":
			it.buckets = field.maybeDereference()
		case "oldbuckets":
			it.oldbuckets = field.maybeDereference()
		}
		if err != nil {
			v.Unreadable = err
			return nil
		}
	}

	if it.buckets.Kind != reflect.Struct || it.oldbuckets.Kind != reflect.Struct {
		v.Unreadable = errMapBucketsNotStruct
		return nil
	}

	it.hashTophashEmptyOne = hashTophashEmptyZero
	it.hashMinTopHash = hashMinTopHashGo111
	if producer := v.bi.Producer(); producer != "" && goversion.ProducerAfterOrEqual(producer, 1, 12) {
		it.hashTophashEmptyOne = hashTophashEmptyOne
		it.hashMinTopHash = hashMinTopHashGo112
	}

	return it
}
233090
func main () {
    d := GOnetstat.Tcp()

    // Marshal in prety print way
    output, err := json.MarshalIndent(d, "", "    ")
    if err != nil {
        fmt.Println(err)
    }

    fmt.Println(string(output))
}
394912
func TypeCode(g Generator, spec compile.TypeSpec) string {
	wire := g.Import("go.uber.org/thriftrw/wire")
	spec = compile.RootTypeSpec(spec)

	switch spec.(type) {
	case *compile.BoolSpec:
		return fmt.Sprintf("%s.TBool", wire)
	case *compile.I8Spec:
		return fmt.Sprintf("%s.TI8", wire)
	case *compile.I16Spec:
		return fmt.Sprintf("%s.TI16", wire)
	case *compile.I32Spec:
		return fmt.Sprintf("%s.TI32", wire)
	case *compile.I64Spec:
		return fmt.Sprintf("%s.TI64", wire)
	case *compile.DoubleSpec:
		return fmt.Sprintf("%s.TDouble", wire)
	case *compile.StringSpec, *compile.BinarySpec:
		return fmt.Sprintf("%s.TBinary", wire)
	case *compile.MapSpec:
		return fmt.Sprintf("%s.TMap", wire)
	case *compile.ListSpec:
		return fmt.Sprintf("%s.TList", wire)
	case *compile.SetSpec:
		return fmt.Sprintf("%s.TSet", wire)
	case *compile.EnumSpec:
		return fmt.Sprintf("%s.TI32", wire)
	case *compile.StructSpec:
		return fmt.Sprintf("%s.TStruct", wire)
	default:
		panic(fmt.Sprintf("unknown type spec %v (type %T)", spec, spec))
	}
}
632793
func (m Methods) ToMarshalJSON(receiver, pkgPath string, excludes ...string) (string, []string) {
	var sb strings.Builder

	r := receiverShort(receiver)
	what := firstToUpper(trimAsterisk(receiver))
	pgkName := path.Base(pkgPath)

	fmt.Fprintf(&sb, "func Marshal%sToJSON(%s %s) ([]byte, error) {\n", what, r, receiver)

	var methods Methods
	var excludeRes = make([]*regexp.Regexp, len(excludes))

	for i, exclude := range excludes {
		excludeRes[i] = regexp.MustCompile(exclude)
	}

	for _, method := range m {
		// Exclude methods with arguments and incompatible return values
		if len(method.In) > 0 || len(method.Out) == 0 || len(method.Out) > 2 {
			continue
		}

		if len(method.Out) == 2 {
			if method.Out[1] != "error" {
				continue
			}
		}

		for _, re := range excludeRes {
			if re.MatchString(method.Name) {
				continue
			}
		}

		methods = append(methods, method)
	}

	for _, method := range methods {
		varn := varName(method.Name)
		if len(method.Out) == 1 {
			fmt.Fprintf(&sb, "\t%s := %s.%s()\n", varn, r, method.Name)
		} else {
			fmt.Fprintf(&sb, "\t%s, err := %s.%s()\n", varn, r, method.Name)
			fmt.Fprint(&sb, "\tif err != nil {\n\t\treturn nil, err\n\t}\n")
		}
	}

	fmt.Fprint(&sb, "\n\ts := struct {\n")

	for _, method := range methods {
		fmt.Fprintf(&sb, "\t\t%s %s\n", method.Name, typeName(method.Out[0], pgkName))
	}

	fmt.Fprint(&sb, "\n\t}{\n")

	for _, method := range methods {
		varn := varName(method.Name)
		fmt.Fprintf(&sb, "\t\t%s: %s,\n", method.Name, varn)
	}

	fmt.Fprint(&sb, "\n\t}\n\n")
	fmt.Fprint(&sb, "\treturn json.Marshal(&s)\n}")

	pkgImports := append(methods.Imports(), "encoding/json")

	if pkgPath != "" {
		// Exclude self
		for i, pkgImp := range pkgImports {
			if pkgImp == pkgPath {
				pkgImports = append(pkgImports[:i], pkgImports[i+1:]...)
			}
		}
	}

	return sb.String(), pkgImports

}
45621
func (sf *ScalarFunction) HashCode(sc *stmtctx.StatementContext) []byte {
	if len(sf.hashcode) > 0 {
		return sf.hashcode
	}
	sf.hashcode = append(sf.hashcode, scalarFunctionFlag)
	sf.hashcode = codec.EncodeCompactBytes(sf.hashcode, hack.Slice(sf.FuncName.L))
	for _, arg := range sf.GetArgs() {
		sf.hashcode = append(sf.hashcode, arg.HashCode(sc)...)
	}
	return sf.hashcode
}
459458
func (col *Column) HashCode() []byte {
	if len(col.hashcode) != 0 {
		return col.hashcode
	}
	col.hashcode, _ = codec.EncodeValue(col.hashcode, types.NewStringDatum(col.FromID), types.NewIntDatum(int64(col.Position)))
	return col.hashcode
}
807644
func main() {

	fmt.Println("--- Begin Example One ---")
	exampleOne()
	fmt.Println("--- End Example One ---")

	fmt.Println("--- Begin Example Two ---")
	exampleTwo()
	fmt.Println("--- End Example Two ---")

	fmt.Println("--- Begin Example Three ---")
	exampleThree()
	fmt.Println("--- End Example Three ---")

	fmt.Println("--- Begin Example Four ---")
	exampleFour()
	fmt.Println("--- End Example Four ---")

	fmt.Println("--- Begin Example Five ---")
	exampleFive()
	fmt.Println("--- End Example Five ---")

	fmt.Println("--- Begin Example Six ---")
	exampleSix()
	fmt.Println("--- End Example Six ---")

}
522639
func (h *HashMap) All() ([]string, error) {
	var (
		values []string
		value  string
	)
	rows, err := h.host.db.Query(fmt.Sprintf("SELECT %s FROM %s", ownerCol, h.table))
	if err != nil {
		return values, err
	}
	if rows == nil {
		return values, ErrNoAvailableValues
	}
	defer rows.Close()
	for rows.Next() {
		err = rows.Scan(&value)
		if !h.host.rawUTF8 {
			Decode(&value)
		}
		values = append(values, value)
		if err != nil {
			return values, err
		}
	}
	err = rows.Err()
	return values, err
}
961742
func init() {

	for i := 0; i < len(encodeBase58Map); i++ {
		decodeBase58Map[i] = 0xFF
	}

	for i := 0; i < len(encodeBase58Map); i++ {
		decodeBase58Map[encodeBase58Map[i]] = byte(i)
	}

	for i := 0; i < len(encodeBase32Map); i++ {
		decodeBase32Map[i] = 0xFF
	}

	for i := 0; i < len(encodeBase32Map); i++ {
		decodeBase32Map[encodeBase32Map[i]] = byte(i)
	}
}
74155
func Runtime(term *ast.Term) func(*Basic) {
	return func(b *Basic) {
		b.runtime = term
	}
}
781815
func main() {
    fs, _ := ioutil.ReadDir(".")
    out, _ := os.Create("textfiles.go")
    out.Write([]byte("package nameGen \n\nvar (\n"))
    for _, f := range fs {
        if strings.HasSuffix(f.Name(), ".txt") {
            lines, _ := readFile(f.Name())
            out.Write([]byte(strings.TrimSuffix(f.Name(), ".txt") + " = [" + strconv.Itoa(len(lines)) + "]string {"))
            for _, line := range lines {
              out.Write([]byte("`" + line + "`,"))
            }
            out.Write([]byte("}\n"))
        }
    }
    out.Write([]byte(")\n"))
}
302218
func StringMap(result interface{}, err error) (map[string]string, error) {
    values, err := Values(result, err)
    if err != nil {
	return nil, err
    }
    if len(values) % 2 != 0 {
	return nil, errors.New("expect even number elements for StringMap")
    }

    m := make(map[string]string, len(values) / 2)
    for i := 0; i < len(values); i += 2 {
	key, okKey := values[i].([]byte)
	value, okValue := values[i + 1].([]byte)
	if !okKey || !okValue {
	    return nil, errors.New("expect bulk string for StringMap")
	}
	m[string(key)] = string(value)
    }

    return m, nil
}
356606
func (o *Operation) GoCode() string {
	var buf bytes.Buffer

	if len(o.OutputRef.Shape.EventStreamsMemberName) != 0 {
		o.API.AddSDKImport("aws/client")
		o.API.AddSDKImport("private/protocol")
		o.API.AddSDKImport("private/protocol/rest")
		o.API.AddSDKImport("private/protocol", o.API.ProtocolPackage())
	}

	if o.API.EndpointDiscoveryOp != nil {
		o.API.AddSDKImport("aws/crr")
		o.API.AddImport("time")
		o.API.AddImport("net/url")
	}

	if o.Endpoint != nil && len(o.Endpoint.HostPrefix) != 0 {
		setupEndpointHostPrefix(o)
	}

	err := operationTmpl.Execute(&buf, o)
	if err != nil {
		panic(err)
	}

	return strings.TrimSpace(buf.String())
}
629269
func (n Node) HashIncludeMap(field string, k, v interface{}) (bool, error) {
	key, ok := k.(string)
	if !ok {
		return false, fmt.Errorf("map key %v not a string", k)
	}

	switch field {
	case "Meta", "Attributes":
		return !IsUniqueNamespace(key), nil
	default:
		return false, fmt.Errorf("unexpected map field: %v", field)
	}
}
494834
func init() {
	noTraverseTypeList = map[reflect.Type]bool{}
	converterMap = map[reflect.Type]map[reflect.Type]Converter{}

	// Default NoTraverseTypeList
	// --------------------------
	// Auto No Traverse struct list for not traversing Deep Level
	// However, field value will be evaluated/processed by go-model library
	AddNoTraverseType(
		time.Time{},
		&time.Time{},
		os.File{},
		&os.File{},
		http.Request{},
		&http.Request{},
		http.Response{},
		&http.Response{},

		// it's better to add it to the list for appropriate type(s)
	)
}
166170
func (rh *HashMap) All() ([]string, error) {
	conn := rh.pool.Get(rh.dbindex)
	result, err := redis.Values(conn.Do("KEYS", rh.id+":*"))
	strs := make([]string, len(result))
	idlen := len(rh.id)
	for i := 0; i < len(result); i++ {
		strs[i] = getString(result, i)[idlen+1:]
	}
	return strs, err
}
381601
func (self *stateObject) Code(db Database) []byte {
	if self.code != nil {
		return self.code
	}
	if bytes.Equal(self.CodeHash(), emptyCodeHash) {
		return nil
	}
	code, err := db.ContractCode(self.addrHash, common.BytesToHash(self.CodeHash()))
	if err != nil {
		self.setError(fmt.Errorf("can't load code hash %x: %v", self.CodeHash(), err))
	}
	self.code = code
	return code
}