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 652822 - Add a g_hash_table_iter_replace
Add a g_hash_table_iter_replace
Status: VERIFIED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Philip Van Hoof
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-06-17 12:03 UTC by Philip Van Hoof
Modified: 2011-06-21 10:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Implementation of a iter_replace API for GHashTableIter (7.02 KB, patch)
2011-06-18 17:43 UTC, Philip Van Hoof
committed Details | Review
Add iter_replace API to GHashTableIter (7.93 KB, patch)
2011-06-21 03:39 UTC, Matthias Clasen
committed Details | Review

Description Philip Van Hoof 2011-06-17 12:03:32 UTC
Qt's QHash has an interesting feature which allows you to replace a value during iteration of a hashtable:

http://doc.qt.nokia.com/latest/qhash-iterator.html#value

QHash<uint, ServiceRequest*>::iterator i = priv->requests.begin();
while (i != priv->requests.end()) {
  if (i.key() == "Hello")
     i.value() = "Bonjour";
  ++i;
}

In GLib something similar could be done by adding alongside the already existing g_hash_table_iter_remove a g_hash_table_iter_replace.
Comment 1 Matthias Clasen 2011-06-17 18:18:40 UTC
I've been thinking about that, indeed.

A patch would be welcome.
Comment 2 Philip Van Hoof 2011-06-18 17:43:41 UTC
Created attachment 190176 [details] [review]
Implementation of a iter_replace API for GHashTableIter

This is what I got. The unit test seems to work, but please verify correctness too.
Comment 3 Matthias Clasen 2011-06-21 03:39:41 UTC
The following fix has been pushed:
f6ed357 Add iter_replace API to GHashTableIter
Comment 4 Matthias Clasen 2011-06-21 03:39:47 UTC
Created attachment 190333 [details] [review]
Add iter_replace API to GHashTableIter
Comment 5 Philip Van Hoof 2011-06-21 10:32:38 UTC
Thanks!