GithubHelp home page GithubHelp logo

gomap's Introduction

gomap

This module contains a group of customized types based on map[K]V with a new function GetKeys(). Since Go 1.x doesn't support generics type, only 6 six common pairs of types are supported by the module.

Import it in your program as:

      import "github.com/pochard/gomap"

API

type StringBoolMap

func GetKeys() ([]string) 

type StringStringMap

func GetKeys() ([]string) 

type StringIntMap

func GetKeys() ([]string) 

type IntStringMap

func GetKeys() ([]int) 

type IntIntMap

func GetKeys() ([]int) 

type IntBoolMap

func GetKeys() ([]int) 

Example

func main(){
	sbmap := make(gomap.StringBoolMap)
	sbmap["China"] = true
	sbmap["USA"] = true
 	sbmap["Japan"] = true

	fmt.Printf("StringBoolMap keys:\n")
	for _,key := range sbmap.GetKeys(){
 		fmt.Printf("%s\n", key)
 	}

	ssmap := make(gomap.StringStringMap)
	ssmap["China"] = "Chinese"
	ssmap["USA"] = "English"
 	ssmap["Japan"] = "Japanese"

	fmt.Printf("StringStringMap keys:\n")
	for _,key := range ssmap.GetKeys(){
 		fmt.Printf("%s\n", key)
 	}

	simap := make(gomap.StringIntMap)
	simap["China"] = 145
	simap["USA"] = 6756
	simap["Japan"] = 987

	fmt.Printf("StringIntMap keys:\n")
	for _,key := range simap.GetKeys(){
		fmt.Printf("%s\n", key)
	}

	ismap := make(gomap.IntStringMap)
	ismap[145] = "China"
	ismap[6756] = "USA"
	ismap[987] = "Japan"

	fmt.Printf("IntStringMap keys:\n")
	for _,key := range ismap.GetKeys(){
		fmt.Printf("%d\n", key)
	}

	iimap := make(gomap.IntIntMap)
	iimap[145] = 12
	iimap[6756] = 24
	iimap[987] = 32

	fmt.Printf("IntIntMap keys:\n")
	for _,key := range iimap.GetKeys(){
		fmt.Printf("%d\n", key)
	}

	ibmap := make(gomap.IntBoolMap)
	ibmap[145] = true
	ibmap[6756] = true
	ibmap[987] = true

	fmt.Printf("IntBoolMap keys:\n")
	for _,key := range ibmap.GetKeys(){
		fmt.Printf("%d\n", key)
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.