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

Ondrej Zizka (JIRA) jira-events at lists.jboss.org
Mon Sep 13 13:23:12 EDT 2010


     [ https://jira.jboss.org/browse/JBCOMMON-111?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ondrej Zizka updated JBCOMMON-111:
----------------------------------

    Description: 
  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 comparison 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.

  was:
  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.



> 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.17.GA
>            Reporter: Ondrej Zizka
>            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 comparison 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