[jboss-jira] [JBoss JIRA] Created: (JBCOMMON-111) Graph#addEdge() micro optimization

Ondrej Žižka (JIRA) jira-events at lists.jboss.org
Wed Aug 18 13:07:11 EDT 2010


Graph#addEdge() micro optimization
----------------------------------

                 Key: JBCOMMON-111
                 URL: https://jira.jboss.org/browse/JBCOMMON-111
             Project: JBoss Common
          Issue Type: Quality Risk
      Security Level: Public (Everyone can see)
    Affects Versions:  2.2.16.GA
            Reporter: Ondrej Žižka
            Assignee: Dimitris Andreadis
            Priority: Trivial


  class Graph: 
  public boolean addEdge(Vertex<T> from, Vertex<T> to, int cost)   {
        ...
         from.addEdge(e);
         to.addEdge(e);
         edges.add(e);
   }

  class Vertex: 
   public boolean addEdge(Edge<T> e)  {
      if (e.getFrom() == this)
         outgoingEdges.add(e);
      else if (e.getTo() == this)
         incomingEdges.add(e);
      else 
         return false;
      return true;
   }


Since the method knows the direction of the edge, why not use this knowledge and avoid unnecessary vertex comparion in Vertex#addEdge() ?

  public boolean addEdge(Vertex<T> from, Vertex<T> to, int cost)   {
        ...
         from.addOutgoingEdge(e, cost);
         to.addIncomingEdge(e, cost);
         edges.add(e);
   }

 addOutgoingEdge and addIncomingEdge do something else -- they create a new edge, which is a bit unintuitive, I'd call them createOutgoingEdge() -- but I hope it's clear what I mean.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the jboss-jira mailing list