GNOME Bugzilla – Bug 131937
Adding a first_that function to GHashTable
Last modified: 2011-02-18 16:13:45 UTC
Hello, sometimes it would be usefull not to iterate over the full hash table (like g_hash_table_for_each always does), but only to find the first element with a given property. Therefore, I propose to add a g_hash_table_first_that function.
Created attachment 23529 [details] [review] Patch against 2.3.1 to add g_hash_table_first_that plus tests.
Adding the PATCH keyword and marking Priority=High.
I don't see efficiency as a reason to add this ... the algorithm stays O(n) ... if going through half the elements is fast enough on average, then going through all the elements is fsat enough. But perhaps convenience is ... sometimes you want to find exactly one element that matches a test, but not more than one. I think it would be better called foreach_while() or maybe g_hash_table_find() or something like that.
This patch would improve efficiency, under the not unreasonable assumption that the density of searched-for elements is better than constant.
applied with rename as per owen's suggestions.
This bug was marked RESOLVED without a resolution, which Bugzilla does not allow (and so I am fixing it). It is assumed that the bug was intended to be marked as FIXED. If the bug should have some other resolution, please change its resolution.