GNOME Bugzilla – Bug 88667
TreeNodeChildren should have a reverse iterator.
Last modified: 2011-04-20 15:09:42 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.
Do we have any reverse iterators anywhere else in gtkmm?
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.
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.
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.
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?
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.
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.
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.
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
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.