After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 88667 - TreeNodeChildren should have a reverse iterator.
TreeNodeChildren should have a reverse iterator.
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: TreeView
2.0
Other other
: Normal enhancement
: 3
Assigned To: gtkmm-forge
gtkmm-forge
Depends on: 128058
Blocks:
 
 
Reported: 2002-07-20 05:59 UTC by Matthew Tuck
Modified: 2011-04-20 15:09 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement



Description Matthew Tuck 2002-07-20 05:59:23 UTC
Gtk::TreeNodeChildren does not have a reverse iterator (rbegin()/rend()). 
I'd find this handy as quick way of getting the last element, among other
things.
Comment 1 Murray Cumming 2002-07-20 11:23:20 UTC
Do we have any reverse iterators anywhere else in gtkmm?
Comment 2 Matthew Tuck 2002-07-21 02:25:35 UTC
No idea, I mainly use TreeView.

Actually on second thoughts it would be nice if they were random
access iterators too.  There is already random access to elements [],
so I suspect random access iterators would be possible.
Comment 3 Murray Cumming 2002-07-22 07:57:30 UTC
Please give me examples of usage of these random access iterators with
normal STL containers.

If there are no existing reverse iterators then we should only add
them if we add them to all of our STL-style containers.
Comment 4 Murray Cumming 2002-07-27 11:50:37 UTC
There are other reverse iterators in gtkmm (grep for rbegin), so this
would be nice to have. But there is no gtk_tree_model_iter_previous(),
so it isn't trivial to implement, though it might be possible. Punted.
Comment 5 Daniel Elstner 2002-10-10 14:14:37 UTC
While I agree that reverse iterators would be handy, we can't support
them as long GTK+ doesn't support them.  And I strongly object against
introducing functionality that contradicts the way the underlying data
structures work -- this would violate STL principles.  E.g.
std::list<> doesn't support random access iterators although it would
technically be possible.

Murray, is it OK to close this bug?
Comment 6 darco 2003-04-29 03:26:50 UTC
The existence of the function gtk_tree_model_iter_nth_child() seems to
hint of the possibility of random-access iterators. If the underlying
GtkTreeModel is using a data structure that would allow for fast
random access, then having a random-access iterator might be desirable.

For the built-in GtkTreeModels (GtkTreeStore/GtkListStore), a
random-access call would be O(n) because (from what I understand) they
use linked-lists internally. However, for a custom GtkTreeModel, it is
possible to have O(1) performance with a random-access iterator.

You could implement a random-access iterator by doing the following:

1) Get the index of the current iterator in the parent from the path
using gtk_tree_model_get_path()
2) Get the parent iterator of the iterator in question using
gtk_tree_model_iter_parent()
3) Add the given requested index to the current index and get the
requested iterator using gtk_tree_model_iter_nth_child()

I could write this and submit a patch if you guys think it would be
useful.
Comment 7 Murray Cumming 2003-04-30 06:07:10 UTC
This doesn't seem to contradict Daniel's comment about it being 
possible but not natural. Please reopen this bug if you want him to 
reconsider.
Comment 8 Murray Cumming 2011-01-06 12:49:30 UTC
GTK+ now has a gtk_tree_model_iter_previous(), which we now use in TreeIter::opeator--(), so it seems like we should now have a reverse iterator too. A patch would be welcome.
Comment 9 Kjell Ahlstedt 2011-04-20 14:45:55 UTC
What has happened? I added a comment to this bug some time ago (could have been
March 24). As a result of that comment, Murray closed the bug. Now every trace
of my comment is gone.

The comment I added (good that saved a copy of it):

I might make a patch, but I don't understand what remains to do.
A reverse iterator was added to TreeNodeChildren on 2004-02-26 by commit
http://git.gnome.org/browse/gtkmm/commit/?id=40b25ec108ef1be29167399407c9652ef31c156f
Comment 10 Murray Cumming 2011-04-20 15:09:42 UTC
There was a brief bugzilla crash, after which some very recent comments were lost.

I closed it, after your comment, with
"
I guess it's fixed already then. Thanks.
"

So I'm closing it again.