I think map[string]struct{} takes no storage for the value and is the most
efficient way to do this.
- Randy
> On Apr 27, 2020, at 7:20 PM, Shishir Verma <[email protected]> wrote:
>
> I think the idiomatic way to implement a set in golang is to use a map with
> bool values. Here is an example from effective go documentation:
>
>
> attended := map[string]bool{
> "Ann": true,
> "Joe": true,
> ...
> }
>
> if attended[person] { // will be false if person is not in the map
> fmt.Println(person, "was at the meeting")
> }
>
>
>
> On Monday, 27 April 2020 22:16:20 UTC+5:30, [email protected] wrote:
> Basically i need a slice with indexed values, so that i can check only
> existence.
> or a map with only keys?
> How it can be done?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/1201e6f3-621e-4875-9374-d7713fa7d8aa%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/6B2E6C64-4B49-48B2-95C3-FFA2852916EE%40gmail.com.