On Wednesday, 29 April 2020 01:33:55 UTC+1, Shishir Verma wrote:
>
> I think it is kind of intuitive that empty struct takes 0 bytes
>
To me it wasn't intuitive, but that's because my brain instinctively read
it as "interface {}" and not "struct {}".
It's clear that a struct{} must occupy zero
I think it is kind of intuitive that empty struct takes 0 bytes whereas a
bool variable takes 1 byte in memory and hence a map with struct{} values
would consume lesser memory than the other. I tried checking this using
code and Randall's point proves:
mapmem.go:
package main
import (
is it mentioned anywhere such that "map[string]struct{}" is efficeient?
On Tuesday, April 28, 2020 at 10:23:08 AM UTC+5:30, Randall O'Reilly wrote:
>
> 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
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 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
On Mon, Apr 27, 2020 at 10:46 AM wrote:
>
> Basically i need a slice with indexed values, so that i can check only
> existence.
> or a map with only keys?
Use a map with struct{} values:
m:=make(map[keyType]struct{})
Then you can add keys by:
m[key]=struct{}{}
and check existence using:
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,