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 569620 - Extend boxed types to have hash and equal methods
Extend boxed types to have hash and equal methods
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks: 707305
 
 
Reported: 2009-01-29 00:18 UTC by Behdad Esfahbod
Modified: 2018-05-24 11:44 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Behdad Esfahbod 2009-01-29 00:18:32 UTC
Boxed types are commonly used to wrap "value" types.  Value types are those typically copied by value instead of being refcounted.  A very common operation with value types is to hash them.  To hash them one needs hash and equal methods.  If GBoxed is extended to take hash and equal functions, language bindings get the correct hash and equal functions automatically.  Currently the binding writer needs to manually hook up the hash and equal functions.

I'm proposing:

GType 
g_boxed_type_register_static_full (const gchar *name,
                                   GBoxedCopyFunc boxed_copy,
                                   GBoxedFreeFunc boxed_free,
                                   GHashFunc      boxed_hash,
                                   GEqualFunc     boxed_equal);

guint
g_boxed_hash (GType         boxed_type,
              gconstpointer boxed);


gboolean
g_boxed_equal (GType         boxed_type,
               gconstpointer boxed_a
               gconstpointer boxed_b);


If the hash and/or equal functions are not provided, direct hash/equal are used.
Comment 1 Benjamin Otte (Company) 2010-08-09 21:48:12 UTC
I have no opinion on the usefulness of this. I suspect bindings coders have a better idea if it's useful to them. In C, it's useless I guess.

But if we add it, it'd probably better as:

g_boxed_type_add_hash_functions (GType      boxed_type,
                                 GHashFunc  boxed_hash,
                                 GEqualFunc boxed_equal);

That's clearer as it gets around the _full() moniker and allows for future extensibility.
Comment 2 Behdad Esfahbod 2013-09-10 15:55:01 UTC
Ping?
Comment 3 Colin Walters 2013-09-10 15:59:59 UTC
See also bug 678619 for improving the boxed type API.

Making it easier to add hash and equal functions makes sense to me.
Comment 4 Simon Feltman 2013-09-10 21:41:00 UTC
There are a few places in the Python bindings where we override the __eq__ operator with functions like gdk_color_equal. This would be a welcome addition to help clean that up because it could be done generically (and correctly) for all boxed types (I think the default is a pointer comparison). Likewise, Pythons __hash__ could be set to use g_boxed_hash for more effective usage of boxed types as dictionary keys or in sets.
Comment 5 GNOME Infrastructure Team 2018-05-24 11:44:02 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/193.