No Subject
- From: "Juergen A. Erhard" <jae laden ilk de>
- To: GTK <gtk-list redhat com>
- Date: Thu, 23 Apr 1998 15:57:01 +0200
Hi all...
This is annoying. I just wanted to use those wonderful g_hash_*
functions. But I need to know when the hash is empty. So... I need
to know how many entries are in the hash.
And there's no (simple) way. I mean, I really love ADTs (long-time
Modula-2 programmer in a former life). But please, when you do an
ADT, export the attributes (if they are not totally private). And one
attribute that's usually needed is the size of some structure.
The patches below (relative to 0.99.9) add a g_hash_table_entries
function to hashes. Yes, there is this `feature freeze'... but this
is not a new feature, it's just fixing a bug. I only hope `nnodes' is
what I think it is...
BTW: yes, you can do that with a g_hash_table_foreach
construction... but why so complicated when the data is all
there... you just can't get to it?
Bye, J
===================================================================
RCS file: /var/cvsroot/GNU/gtk/glib/glib.h,v
retrieving revision 1.1.1.7
diff -b -p -u -r1.1.1.7 glib.h
--- glib.h 1998/04/16 03:56:33 1.1.1.7
+++ glib.h 1998/04/23 08:36:39
@@ -511,6 +511,7 @@ void g_hash_table_remove (GHashTabl
gpointer key);
gpointer g_hash_table_lookup (GHashTable *hash_table,
const gpointer key);
+gint g_hash_table_entries (GHashTable *hash_table);
void g_hash_table_freeze (GHashTable *hash_table);
void g_hash_table_thaw (GHashTable *hash_table);
void g_hash_table_foreach (GHashTable *hash_table,
Index: ghash.c
===================================================================
RCS file: /var/cvsroot/GNU/gtk/glib/ghash.c,v
retrieving revision 1.1.1.2
diff -b -p -u -r1.1.1.2 ghash.c
--- ghash.c 1997/09/20 23:47:52 1.1.1.2
+++ ghash.c 1998/04/23 08:35:53
@@ -220,6 +220,20 @@ g_hash_table_lookup (GHashTable *has
return NULL;
}
+gint
+g_hash_table_entries (GHashTable *hash_table)
+{
+ GRealHashTable *rhash_table;
+
+ if (hash_table)
+ {
+ rhash_table = (GRealHashTable*) hash_table;
+ return rhash_table->nnodes;
+ }
+
+ return 0;
+}
+
void
g_hash_table_freeze (GHashTable *hash_table)
{
--
Jürgen A. Erhard eMail: jae@laden.ilk.de phone: (GERMANY) 0721 27326
MARS: http://members.tripod.com/~Juergen_Erhard/mars_index.html
Linux - Free PC Unix (http://www.linux.org)
"Windows NT" is an acronym for "Windows? No thanks." -- Russ McManus
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]