I will be receiving strings one by one from a framework, I need to hold them in some container and delete some of them later. Now I have 2 options :-
- Create a slice of strings and then delete some items by look up
- Create a map of string with key=string and data=dummy data so that deletion is easy
So personally I would prefer second option. Is that correct choice? Do we have any better way?
map[string]struct{}is often preferred overmap[string]boolbecause it is more semantically correct. Nobody reading your code will ever be left wondering "what does true/false mean?" Although some people preferbooleven so, because it's easier to type. Either works fine.struct{}is also slightly more memory-efficient.