Using hash() to find out object identity is no longer required and was a hack, use id() instead.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Mon Aug 25 15:02:37 2008 +0100 (17 months ago)
changeset 35659ec60d05c563
parent 3564 353c72fc49aa
child 3594 e965ed757e92
Using hash() to find out object identity is no longer required and was a hack, use id() instead.
examples/visualizer.py
     1.1 --- a/examples/visualizer.py	Sat Aug 23 22:36:43 2008 +0100
     1.2 +++ b/examples/visualizer.py	Mon Aug 25 15:02:37 2008 +0100
     1.3 @@ -251,7 +251,7 @@
     1.4  
     1.5      def __init__(self):
     1.6          self.nodes =  {} # node index -> Node
     1.7 -        self.channels = {} # hash(channel) -> Channel
     1.8 +        self.channels = {} # id(ns3.Channel) -> Channel
     1.9          self.window = None
    1.10          self.canvas = None
    1.11          self.time_label = None # gtk.Label
    1.12 @@ -347,7 +347,7 @@
    1.13                      if REPRESENT_CHANNELS_AS_NODES:
    1.14                          # represent channels as white nodes
    1.15                          if mobility is None:
    1.16 -                            channel_name = "Channel %s" % hash(channel)
    1.17 +                            channel_name = "Channel %s" % id(channel)
    1.18                              graph.add_edge(node_name, channel_name)
    1.19                          self.get_channel(channel)
    1.20                          self.create_link(self.get_node(nodeI), self.get_channel(channel))
    1.21 @@ -357,7 +357,7 @@
    1.22                              otherDev = channel.GetDevice(otherDevI)
    1.23                              otherNode = otherDev.GetNode()
    1.24                              otherNodeView = self.get_node(otherNode.GetId())
    1.25 -                            if hash(otherNode) != hash(node):
    1.26 +                            if otherNode is not node:
    1.27                                  if mobility is None and not otherNodeView.has_mobility:
    1.28                                      other_node_name = "Node %i" % otherNode.GetId()
    1.29                                      graph.add_edge(node_name, other_node_name)
    1.30 @@ -367,7 +367,7 @@
    1.31                          otherDev = channel.GetDevice(otherDevI)
    1.32                          otherNode = otherDev.GetNode()
    1.33                          otherNodeView = self.get_node(otherNode.GetId())
    1.34 -                        if hash(otherNode) != hash(node):
    1.35 +                        if otherNode is not node:
    1.36                              if mobility is None and not otherNodeView.has_mobility:
    1.37                                  other_node_name = "Node %i" % otherNode.GetId()
    1.38                                  graph.add_edge(node_name, other_node_name)
    1.39 @@ -397,10 +397,10 @@
    1.40  
    1.41      def get_channel(self, ns3_channel):
    1.42          try:
    1.43 -            return self.channels[hash(ns3_channel)]
    1.44 +            return self.channels[id(ns3_channel)]
    1.45          except KeyError:
    1.46              channel = Channel(ns3_channel)
    1.47 -            self.channels[hash(ns3_channel)] = channel
    1.48 +            self.channels[id(ns3_channel)] = channel
    1.49              channel.canvas_item.set_property("parent", self.canvas.get_root_item())
    1.50              return channel
    1.51