[gnome-games] game: Add hash and equal functions
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] game: Add hash and equal functions
- Date: Thu, 19 Jul 2018 19:18:51 +0000 (UTC)
commit eb863a774fd88e21af6a7c8a7f31520eb196b6fd
Author: theawless <theawless gmail com>
Date: Thu Jul 19 18:43:52 2018 +0530
game: Add hash and equal functions
These will allow hashing and comparing objects that implement Game
interface.
src/core/game.vala | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
---
diff --git a/src/core/game.vala b/src/core/game.vala
index f2608a1..e00274e 100644
--- a/src/core/game.vala
+++ b/src/core/game.vala
@@ -11,4 +11,39 @@ public interface Games.Game : Object {
public abstract Genre get_genre ();
public abstract Players get_players ();
public abstract Runner get_runner () throws Error;
+
+ public static uint hash (Game key) {
+ var uid = "";
+ try {
+ uid = key.get_uid ().get_uid ();
+ }
+ catch (Error e) {
+ critical (e.message);
+ }
+
+ return str_hash (uid);
+ }
+
+ public static bool equal (Game a, Game b) {
+ if (direct_equal (a, b))
+ return true;
+
+ var a_uid = "";
+ try {
+ a_uid = a.get_uid ().get_uid ();
+ }
+ catch (Error e) {
+ critical (e.message);
+ }
+
+ var b_uid = "";
+ try {
+ b_uid = b.get_uid ().get_uid ();
+ }
+ catch (Error e) {
+ critical (e.message);
+ }
+
+ return str_equal (a_uid, b_uid);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]