blob: a532bbd8025c0a880693008c50bfb0739d6779d1 [file] [log] [blame] [edit]
{"name":"Golang-set","tagline":"A simple set type for the Go language.","body":"[![Build Status](https://travis-ci.org/deckarep/golang-set.png?branch=master)](https://travis-ci.org/deckarep/golang-set)\r\n\r\ngolang-set\r\n==========\r\n\r\nA simple set type for the Go language.\r\n\r\nComing from Python one of the things I miss is the superbly wonderful set collection. This is my attempt to mimic the primary features of the set from Python.\r\nYou can of course argue that there is no need for a set in Go, otherwise the creators would have added one to the standard library. To those I say simply ignore this repository\r\nand carry-on and to the rest that find this useful please contribute in helping me make it better by:\r\n\r\n* Helping to make more idiomatic improvements to the code.\r\n* Helping to make it better for more generic use across types.\r\n* Helping to increase the performance of it. ~~(So far, no attempt has been made, but since it uses a map internally, I expect it to be mostly performant.)~~\r\n* Helping to make the unit-tests more robust and kick-ass.\r\n* Helping to fill in the [documentation.](http://godoc.org/github.com/deckarep/golang-set)\r\n* Simply offering feedback and suggestions, since I am a Go n00b. (Positive, constructive feedback is appreciated.)\r\n\r\nI have to give some credit for helping seed the idea with this post on [stackoverflow.](http://programmers.stackexchange.com/questions/177428/sets-data-structure-in-golang)\r\n\r\nPlease see the unit test file for additional usage examples. The Python set documentation will also do a better job than I can of explaining how a set typically [works.](http://docs.python.org/2/library/sets.html) Please keep in mind \r\nhowever that the Python set is a built-in type and supports additional features and syntax that make it awesome. This set for Go is nowhere near as comprehensive as the Python set\r\nalso, this set has not been battle-tested or used in production. Also, this set is not goroutine safe...you have been warned.\r\n\r\nExamples but not exhaustive:\r\n```go\r\nrequiredClasses := NewSet()\r\nrequiredClasses.Add(\"Cooking\")\r\nrequiredClasses.Add(\"English\")\r\nrequiredClasses.Add(\"Math\")\r\nrequiredClasses.Add(\"Biology\")\r\n\r\nscienceSlice := []interface{}{\"Biology\", \"Chemistry\"}\r\nscienceClasses := NewSetFromSlice(scienceSlice)\r\n\r\nelectiveClasses := NewSet()\r\nelectiveClasses.Add(\"Welding\")\r\nelectiveClasses.Add(\"Music\")\r\nelectiveClasses.Add(\"Automotive\")\r\n\r\nbonusClasses := NewSet()\r\nbonusClasses.Add(\"Go Programming\")\r\nbonusClasses.Add(\"Python Programming\")\r\n\r\n//Show me all the available classes I can take\r\nallClasses := requiredClasses.Union(scienceClasses).Union(electiveClasses).Union(bonusClasses)\r\nfmt.Println(allClasses) //Set{Cooking, English, Math, Chemistry, Welding, Biology, Music, Automotive, Go Programming, Python Programming}\r\n\r\n\r\n//Is cooking considered a science class?\r\nfmt.Println(scienceClasses.Contains(\"Cooking\")) //false\r\n\r\n//Show me all classes that are not science classes, since I hate science.\r\nfmt.Println(allClasses.Difference(scienceClasses)) //Set{Music, Automotive, Go Programming, Python Programming, Cooking, English, Math, Welding}\r\n\r\n//Which science classes are also required classes?\r\nfmt.Println(scienceClasses.Intersect(requiredClasses)) //Set{Biology}\r\n\r\n//How many bonus classes do you offer?\r\nfmt.Println(bonusClasses.Size()) //2\r\n\r\n//Do you have the following classes? Welding, Automotive and English?\r\nfmt.Println(allClasses.ContainsAll(\"Welding\", \"Automotive\", \"English\")) //true\r\n```\r\n\r\nThanks!\r\n\r\n-Ralph\r\n\r\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/deckarep/golang-set/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\r\n\r\n\r\n\r\n","google":"UA-42584447-1","note":"Don't delete this file! It's used internally to help with page regeneration."}