[ 
https://issues.apache.org/jira/browse/GIRAPH-221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13403102#comment-13403102
 ] 

Alessandro Presta commented on GIRAPH-221:
------------------------------------------

I see what you're saying. That means the user implements a method returning an 
Iterable instead of an Iterator.
I think this is fine for Collection-backed vertex types (it even saves a call 
to .iterator()), however in other cases (where the edges have to be somehow 
fetched one by one) it would be more cumbersome (have to declare an anonymous 
Iterable class on the fly).

If this sounds confusing, here's how I was thinking of changing it:

{code:java}
  public abstract Iterator<I> outEdgesIterator();

  public Iterable<I> outEdges() {
    return new Iterable<I>() {
      public Iterator<I> iterator() {
        return outEdgesIterator();
      }
    };
  }
{code}

Whereas what you're saying is we just declare:

{code:java}
public abstract Iterable<I> outEdges();
{code}

I'm fine with it, I just wonder what is the best practice here (have the user 
define an Iterator versus an Iterable). I'm moving my first steps with Java so 
I would leave the decision to you guys.
                
> Make iteration over edges more explicit
> ---------------------------------------
>
>                 Key: GIRAPH-221
>                 URL: https://issues.apache.org/jira/browse/GIRAPH-221
>             Project: Giraph
>          Issue Type: Improvement
>          Components: graph
>            Reporter: Alessandro Presta
>            Assignee: Alessandro Presta
>            Priority: Minor
>
> Is there any particular reason why BasicVertex implements Iterable?
> It seems to me that doing
> {code:java}
> for (I neighbor : vertex)
> {code}
> is not that explicit, and
> {code:java}
> for (I neighbor : this)
> {code}
> gets even obscure (which may be why all examples in the codebase explicitly 
> instantiate an iterator and call next()).
> What I propose is a more explicit
> {code:java}
> Iterator<I> outEdgesIterator()
> {code}
> and also a convenient
> {code:java}
> Iterable<I> outEdges()
> {code}
> so, for example, an algorithm can use
> {code:java}
> for (int neighbor : outEdges())
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to