add a hash() method to PolkitIdentity
authorDavid Zeuthen <davidz@redhat.com>
Mon, 19 Jan 2009 21:28:59 +0000 (16:28 -0500)
committerDavid Zeuthen <davidz@redhat.com>
Mon, 19 Jan 2009 21:28:59 +0000 (16:28 -0500)
src/polkit/polkitidentity.c
src/polkit/polkitidentity.h
src/polkit/polkitunixgroup.c
src/polkit/polkitunixuser.c

index 0d88f0d..36436af 100644 (file)
@@ -65,6 +65,12 @@ polkit_identity_get_type (void)
   return iface_type;
 }
 
+guint
+polkit_identity_hash (PolkitIdentity *identity)
+{
+  return POLKIT_IDENTITY_GET_IFACE (identity)->hash (identity);
+}
+
 gboolean
 polkit_identity_equal (PolkitIdentity *a,
                       PolkitIdentity *b)
index 5bebcd4..2b81008 100644 (file)
@@ -42,6 +42,8 @@ struct _PolkitIdentityIface
 {
   GTypeInterface parent_iface;
 
+  guint    (*hash)      (PolkitIdentity *identity);
+
   gboolean (*equal)     (PolkitIdentity *a,
                          PolkitIdentity *b);
 
@@ -49,6 +51,7 @@ struct _PolkitIdentityIface
 };
 
 GType          polkit_identity_get_type      (void) G_GNUC_CONST;
+guint          polkit_identity_hash          (PolkitIdentity *a);
 gboolean       polkit_identity_equal         (PolkitIdentity *a,
                                               PolkitIdentity *b);
 gchar          *polkit_identity_to_string    (PolkitIdentity *identity);
index 67f6387..fc8bf04 100644 (file)
@@ -183,6 +183,16 @@ polkit_unix_group_new_for_name (const gchar    *name,
   return identity;
 }
 
+static guint
+polkit_unix_group_hash (PolkitIdentity *identity)
+{
+  PolkitUnixGroup *group;
+
+  group = POLKIT_UNIX_GROUP (identity);
+
+  return g_direct_hash (GINT_TO_POINTER (((gint) (group->gid)) * 2 + 1));
+}
+
 static gboolean
 polkit_unix_group_equal (PolkitIdentity *a,
                         PolkitIdentity *b)
@@ -213,6 +223,7 @@ polkit_unix_group_to_string (PolkitIdentity *identity)
 static void
 identity_iface_init (PolkitIdentityIface *identity_iface)
 {
+  identity_iface->hash      = polkit_unix_group_hash;
   identity_iface->equal     = polkit_unix_group_equal;
   identity_iface->to_string = polkit_unix_group_to_string;
 }
index 830fc79..a70d64a 100644 (file)
@@ -196,6 +196,16 @@ polkit_unix_user_equal (PolkitIdentity *a,
   return user_a->uid == user_b->uid;
 }
 
+static guint
+polkit_unix_user_hash (PolkitIdentity *identity)
+{
+  PolkitUnixUser *user;
+
+  user = POLKIT_UNIX_USER (identity);
+
+  return g_direct_hash (GINT_TO_POINTER (((gint) (user->uid)) * 2));
+}
+
 static gchar *
 polkit_unix_user_to_string (PolkitIdentity *identity)
 {
@@ -213,6 +223,7 @@ polkit_unix_user_to_string (PolkitIdentity *identity)
 static void
 identity_iface_init (PolkitIdentityIface *identity_iface)
 {
+  identity_iface->hash      = polkit_unix_user_hash;
   identity_iface->equal     = polkit_unix_user_equal;
   identity_iface->to_string = polkit_unix_user_to_string;
 }