commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@eurobell.co.uk>
Subject Re: [Collections][Submit] TreeNode and friends
Date Sun, 26 May 2002 18:48:01 GMT
From: bob mcwhirter <bob@werken.com>
> > > 3.  What's the rationale for having equals and hashCode
> > > be reference based?
> >
> > The alternative is to compare both the value and children of that node.
But
> > in comparing the children, each child node will compare its value and
> > children and so on. This would be potentially very expensive. Its also
how
> > JDOM does its equals method.
>
> Just to clarify:  JDOM uses identity-based equality, not semantic.  Right?

Yes, identity based equality.

> > > 4.  Must tree iterators be depth-first?  The ordered
> > > traversal for a heap tree isn't depth-first.
> >
> > No, but depth first is the one I needed ;-)  There are two possibilities
> > here,
> > a) Add extra methods for different iteration types
> > b) Remove the comment that specifies how the iteration is done.
>
> I think, personally, for things like trees, either having
>
> depthFirstIterator()
> bredthFirstIterator()
>
> or removing all iteration from the tree directly, and require
> folks to do:
>
> Iterator iter = new DepthFirstIterator( tree );
>
> or
>
> Iterator iter = new BredthFirstIterator( tree );
>
> Just because there's no -default- way to iterate a tree, I don't
> think having just a plain iterator() method is sufficient.

I would rather keep the iterator on TreeNode. If there are only two standard
ways to iterate then two methods would seem appropriate. But are there more
than two ways??

Stephen




--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message