use map[...]struct{} for sets instead of map[...]bool
See https://groups.google.com/d/msg/golang-nuts/lb4xLHq7wug/MhrSLkyS4F8J We don't really care about the performance aspect of this, but using struct{}{} values is in some way canonical since it means the representation carries no redundant information.
This commit is contained in:
1 parent
6f2f25aca5
commit
74b3f8d44e
4 files changed
+25
-21
No files matched your search
+3
-3
@@ -350,7 +350,7 @@ func handleSpecialFrame(relayConn *LocalConnection, sender *net.UDPAddr, frame [
|
||||
|
||||
// Gossiper methods - the Router is the topology Gossiper
|
||||
|
||||
type PeerNameSet map[PeerName]bool
|
||||
type PeerNameSet map[PeerName]struct{}
|
||||
|
||||
type TopologyGossipData struct {
|
||||
peers *Peers
|
||||
@@ -360,14 +360,14 @@ type TopologyGossipData struct {
|
||||
func NewTopologyGossipData(peers *Peers, update ...*Peer) *TopologyGossipData {
|
||||
names := make(PeerNameSet)
|
||||
for _, p := range update {
|
||||
names[p.Name] = true
|
||||
names[p.Name] = struct{}{}
|
||||
}
|
||||
return &TopologyGossipData{peers: peers, update: names}
|
||||
}
|
||||
|
||||
func (d *TopologyGossipData) Merge(other GossipData) {
|
||||
for name := range other.(*TopologyGossipData).update {
|
||||
d.update[name] = true
|
||||
d.update[name] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user