[folks] Change IndividualAggregator.individuals to be a Map<string, Individual>
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Change IndividualAggregator.individuals to be a Map<string, Individual>
- Date: Sat, 23 Apr 2011 21:03:23 +0000 (UTC)
commit 03bfb40e46b9c804700c57e0a6a6faf6aa503cda
Author: Philip Withnall <philip withnall collabora co uk>
Date: Wed Apr 20 01:14:05 2011 +0100
Change IndividualAggregator.individuals to be a Map<string, Individual>
This helps in our quest to get rid of HashTable.
Helps: bgo#640092
NEWS | 1 +
folks/individual-aggregator.vala | 32 +++++++++++++++---------------
tests/tracker/add-contact.vala | 5 +--
tests/tracker/avatar-updates.vala | 2 +-
tests/tracker/emails-updates.vala | 2 +-
tests/tracker/match-all.vala | 2 +-
tests/tracker/match-email-addresses.vala | 4 +-
tests/tracker/match-im-addresses.vala | 4 +-
tests/tracker/match-known-emails.vala | 4 +-
tests/tracker/match-name.vala | 4 +-
tests/tracker/match-phone-number.vala | 4 +-
tools/inspect/command-individuals.vala | 10 ++++----
tools/inspect/command-personas.vala | 6 +---
tools/inspect/utils.vala | 20 +++++++++---------
14 files changed, 49 insertions(+), 51 deletions(-)
---
diff --git a/NEWS b/NEWS
index 9fa9354..dccbbbf 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,7 @@ API changes:
Map<Individual, Map<Individual, MatchResult>>
* IndividualAggregator.get_potential_matches() now returns a
Map<Individual, MatchResult>
+* IndividualAggregator.individuals now has type Map<string, Individual>
Overview of changes from libfolks 0.4.0 to libfolks 0.5.0
=========================================================
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 831a7a1..f0fd7fd 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -96,7 +96,7 @@ public class Folks.IndividualAggregator : Object
}
/**
- * A table mapping { link Individual.id}s to their { link Individual}s.
+ * A map from { link Individual.id}s to their { link Individual}s.
*
* This is the canonical set of { link Individual}s provided by this
* IndividualAggregator.
@@ -104,8 +104,10 @@ public class Folks.IndividualAggregator : Object
* { link Individual}s may be added or removed using
* { link IndividualAggregator.add_persona_from_details} and
* { link IndividualAggregator.remove_individual}, respectively.
+ *
+ * @since UNRELEASED
*/
- public HashTable<string, Individual> individuals { get; private set; }
+ public Map<string, Individual> individuals { get; private set; }
/**
* The { link Individual} representing the user.
@@ -158,8 +160,7 @@ public class Folks.IndividualAggregator : Object
public IndividualAggregator ()
{
this._stores = new HashMap<string, PersonaStore> ();
- this.individuals = new HashTable<string, Individual> (str_hash,
- str_equal);
+ this.individuals = new HashMap<string, Individual> ();
this._link_map = new HashTable<string, Individual> (str_hash, str_equal);
this._backends = new HashSet<Backend> ();
@@ -239,7 +240,7 @@ public class Folks.IndividualAggregator : Object
new HashMap<Individual, MatchResult> ();
Folks.PotentialMatch matchObj = new Folks.PotentialMatch ();
- foreach (var i in this.individuals.get_values ())
+ foreach (var i in this.individuals.values)
{
if (i.id == matchee.id)
continue;
@@ -265,13 +266,12 @@ public class Folks.IndividualAggregator : Object
{
HashMap<Individual, HashMap<Individual, MatchResult>> matches =
new HashMap<Individual, HashMap<Individual, MatchResult>> ();
- GLib.List<Individual> individuals = this.individuals.get_values ();
+ var individuals = this.individuals.values.to_array ();
Folks.PotentialMatch matchObj = new Folks.PotentialMatch ();
- for (unowned GLib.List<Individual> l = individuals;
- l != null && l.next != null; l = l.next)
+ for (var i = 0; i < individuals.length; i++)
{
- var a = l.data;
+ var a = individuals[i];
var matches_a = matches.get (a);
if (matches_a == null)
{
@@ -279,9 +279,9 @@ public class Folks.IndividualAggregator : Object
matches.set (a, matches_a);
}
- for (unowned GLib.List<Individual> j=l.next; j != null; j = j.next)
+ for (var f = i + 1; f < individuals.length; f++)
{
- var b = j.data;
+ var b = individuals[f];
var matches_b = matches.get (b);
if (matches_b == null)
{
@@ -588,7 +588,7 @@ public class Folks.IndividualAggregator : Object
/* Add the new Individual to the aggregator */
i.removed.connect (this._individual_removed_cb);
added_individuals.add (i);
- this.individuals.insert (i.id, i);
+ this.individuals.set (i.id, i);
}
}
@@ -682,7 +682,7 @@ public class Folks.IndividualAggregator : Object
foreach (var individual in removed_individuals)
{
/* Ensure we don't remove the same Individual twice */
- if (this.individuals.lookup (individual.id) == null)
+ if (this.individuals.has_key (individual.id) == false)
continue;
debug (" %s", individual.id);
@@ -704,7 +704,7 @@ public class Folks.IndividualAggregator : Object
if (user == individual)
user = null;
- this.individuals.remove (individual.id);
+ this.individuals.unset (individual.id);
individual.personas = null;
}
@@ -777,7 +777,7 @@ public class Folks.IndividualAggregator : Object
/* Only signal if the individual is still in this.individuals. This allows
* us to group removals together in, e.g., _personas_changed_cb(). */
- if (this.individuals.lookup (i.id) != i)
+ if (this.individuals.get (i.id) != i)
return;
var individuals = new HashSet<Individual> ();
@@ -800,7 +800,7 @@ public class Folks.IndividualAggregator : Object
individuals, null, null, 0);
}
- this.individuals.remove (i.id);
+ this.individuals.unset (i.id);
}
/**
diff --git a/tests/tracker/add-contact.vala b/tests/tracker/add-contact.vala
index 3f6040c..39db742 100644
--- a/tests/tracker/add-contact.vala
+++ b/tests/tracker/add-contact.vala
@@ -116,9 +116,8 @@ public class AddContactTests : Folks.TestCase
private void _notify_full_name_cb ()
{
- GLib.List<Individual> individuals =
- this._aggregator.individuals.get_values ();
- foreach (unowned Individual i in individuals)
+ var individuals = this._aggregator.individuals.values;
+ foreach (var i in individuals)
{
if (i.full_name == this._persona_fullname)
{
diff --git a/tests/tracker/avatar-updates.vala b/tests/tracker/avatar-updates.vala
index f2dfce0..998a5d7 100644
--- a/tests/tracker/avatar-updates.vala
+++ b/tests/tracker/avatar-updates.vala
@@ -151,7 +151,7 @@ public class AvatarUpdatesTests : Folks.TestCase
private void _notify_avatar_cb ()
{
- var i = this._aggregator.individuals.lookup (this._individual_id);
+ var i = this._aggregator.individuals.get (this._individual_id);
if (i == null)
return;
diff --git a/tests/tracker/emails-updates.vala b/tests/tracker/emails-updates.vala
index 56188d0..678e106 100644
--- a/tests/tracker/emails-updates.vala
+++ b/tests/tracker/emails-updates.vala
@@ -88,7 +88,7 @@ public class EmailsUpdatesTests : Folks.TestCase
bool initial_email_found_again = false;
- var i = this._aggregator.individuals.lookup (this._individual_id);
+ var i = this._aggregator.individuals.get (this._individual_id);
if (i != null)
{
foreach (var fd in i.email_addresses)
diff --git a/tests/tracker/match-all.vala b/tests/tracker/match-all.vala
index bb56e75..772b2a1 100644
--- a/tests/tracker/match-all.vala
+++ b/tests/tracker/match-all.vala
@@ -166,7 +166,7 @@ public class MatchAllTests : Folks.TestCase
private void _try_match_all ()
{
- var ind1 = this._aggregator.individuals.lookup (this._individual_id_1);
+ var ind1 = this._aggregator.individuals.get (this._individual_id_1);
var matches_1 = this._aggregator.get_potential_matches (ind1,
MatchResult.MEDIUM);
this._matches_1 = matches_1.size;
diff --git a/tests/tracker/match-email-addresses.vala b/tests/tracker/match-email-addresses.vala
index 606fe10..2c0f599 100644
--- a/tests/tracker/match-email-addresses.vala
+++ b/tests/tracker/match-email-addresses.vala
@@ -131,8 +131,8 @@ public class MatchEmailAddressesTests : Folks.TestCase
private void _try_potential_match ()
{
- var ind1 = this._aggregator.individuals.lookup (this._individual_id_1);
- var ind2 = this._aggregator.individuals.lookup (this._individual_id_2);
+ var ind1 = this._aggregator.individuals.get (this._individual_id_1);
+ var ind2 = this._aggregator.individuals.get (this._individual_id_2);
Folks.PotentialMatch matchObj = new Folks.PotentialMatch ();
this._match = matchObj.potential_match (ind1, ind2);
diff --git a/tests/tracker/match-im-addresses.vala b/tests/tracker/match-im-addresses.vala
index fb38ee0..1c5e4e4 100644
--- a/tests/tracker/match-im-addresses.vala
+++ b/tests/tracker/match-im-addresses.vala
@@ -131,8 +131,8 @@ public class MatchIMAddressesTests : Folks.TestCase
private void _try_potential_match ()
{
- var ind1 = this._aggregator.individuals.lookup (this._individual_id_1);
- var ind2 = this._aggregator.individuals.lookup (this._individual_id_2);
+ var ind1 = this._aggregator.individuals.get (this._individual_id_1);
+ var ind2 = this._aggregator.individuals.get (this._individual_id_2);
Folks.PotentialMatch matchObj = new Folks.PotentialMatch ();
this._match = matchObj.potential_match (ind1, ind2);
diff --git a/tests/tracker/match-known-emails.vala b/tests/tracker/match-known-emails.vala
index 7c75937..a6470b0 100644
--- a/tests/tracker/match-known-emails.vala
+++ b/tests/tracker/match-known-emails.vala
@@ -139,8 +139,8 @@ public class MatchKnownEmailsTests : Folks.TestCase
private void _try_potential_match ()
{
- var ind1 = this._aggregator.individuals.lookup (this._individual_id_1);
- var ind2 = this._aggregator.individuals.lookup (this._individual_id_2);
+ var ind1 = this._aggregator.individuals.get (this._individual_id_1);
+ var ind2 = this._aggregator.individuals.get (this._individual_id_2);
Folks.PotentialMatch matchObj = new Folks.PotentialMatch ();
this._match = matchObj.potential_match (ind1, ind2);
diff --git a/tests/tracker/match-name.vala b/tests/tracker/match-name.vala
index 7c58a0e..af28606 100644
--- a/tests/tracker/match-name.vala
+++ b/tests/tracker/match-name.vala
@@ -194,8 +194,8 @@ public class MatchNameTests : Folks.TestCase
private void _try_potential_match ()
{
- var ind1 = this._aggregator.individuals.lookup (this._individual_id_1);
- var ind2 = this._aggregator.individuals.lookup (this._individual_id_2);
+ var ind1 = this._aggregator.individuals.get (this._individual_id_1);
+ var ind2 = this._aggregator.individuals.get (this._individual_id_2);
Folks.PotentialMatch matchObj = new Folks.PotentialMatch ();
this._match = matchObj.potential_match (ind1, ind2);
diff --git a/tests/tracker/match-phone-number.vala b/tests/tracker/match-phone-number.vala
index 907f2c5..5c124df 100644
--- a/tests/tracker/match-phone-number.vala
+++ b/tests/tracker/match-phone-number.vala
@@ -133,8 +133,8 @@ public class MatchPhoneNumberTests : Folks.TestCase
private void _try_potential_match ()
{
- var ind1 = this._aggregator.individuals.lookup (this._individual_id_1);
- var ind2 = this._aggregator.individuals.lookup (this._individual_id_2);
+ var ind1 = this._aggregator.individuals.get (this._individual_id_1);
+ var ind2 = this._aggregator.individuals.get (this._individual_id_2);
Folks.PotentialMatch matchObj = new Folks.PotentialMatch ();
this._match = matchObj.potential_match (ind1, ind2);
diff --git a/tools/inspect/command-individuals.vala b/tools/inspect/command-individuals.vala
index e3ce6fd..2c0c97b 100644
--- a/tools/inspect/command-individuals.vala
+++ b/tools/inspect/command-individuals.vala
@@ -58,17 +58,17 @@ private class Folks.Inspect.Commands.Individuals : Folks.Inspect.Command
if (command_string == null)
{
/* List all the individuals */
- this.client.aggregator.individuals.foreach ((k, v) =>
+ foreach (var individual in this.client.aggregator.individuals.values)
{
- Utils.print_individual ((Individual) v, false);
+ Utils.print_individual (individual, false);
Utils.print_line ("");
- });
+ }
}
else
{
/* Display the details of a single individual */
- Individual individual =
- this.client.aggregator.individuals.lookup (command_string);
+ var individual =
+ this.client.aggregator.individuals.get (command_string);
if (individual == null)
{
diff --git a/tools/inspect/command-personas.vala b/tools/inspect/command-personas.vala
index 87b953f..8c06a4a 100644
--- a/tools/inspect/command-personas.vala
+++ b/tools/inspect/command-personas.vala
@@ -54,10 +54,8 @@ private class Folks.Inspect.Commands.Personas : Folks.Inspect.Command
public override void run (string? command_string)
{
- this.client.aggregator.individuals.foreach ((k, v) =>
+ foreach (var individual in this.client.aggregator.individuals.values)
{
- Individual individual = (Individual) v;
-
foreach (Persona persona in individual.personas)
{
/* Either list all personas, or only list the one specified */
@@ -69,7 +67,7 @@ private class Folks.Inspect.Commands.Personas : Folks.Inspect.Command
if (command_string == null)
Utils.print_line ("");
}
- });
+ }
}
public override string[]? complete_subcommand (string subcommand)
diff --git a/tools/inspect/utils.vala b/tools/inspect/utils.vala
index 48ba246..e5928fc 100644
--- a/tools/inspect/utils.vala
+++ b/tools/inspect/utils.vala
@@ -424,7 +424,7 @@ private class Folks.Inspect.Utils
/* FIXME: This can't be in the individual_id_completion_cb() function because
* Vala doesn't allow static local variables. Erk. */
- private static HashTableIter<string, Individual>? individual_id_iter = null;
+ private static MapIterator<string, Individual>? individual_id_iter = null;
/* Complete an individual's ID, starting with @word. */
public static string? individual_id_completion_cb (string word,
@@ -433,14 +433,13 @@ private class Folks.Inspect.Utils
/* Initialise state. Whoever wrote the readline API should be shot. */
if (state == 0)
{
- Utils.individual_id_iter = HashTableIter<string, Individual> (
- main_client.aggregator.individuals);
+ Utils.individual_id_iter =
+ main_client.aggregator.individuals.map_iterator ();
}
- string id;
- Individual individual;
- while (Utils.individual_id_iter.next (out id, out individual) == true)
+ while (Utils.individual_id_iter.next () == true)
{
+ var id = Utils.individual_id_iter.get_key ();
if (id.has_prefix (word))
return id;
}
@@ -461,15 +460,16 @@ private class Folks.Inspect.Utils
/* Initialise state. Whoever wrote the readline API should be shot. */
if (state == 0)
{
- Utils.individual_id_iter = HashTableIter<string, Individual> (
- main_client.aggregator.individuals);
+ Utils.individual_id_iter =
+ main_client.aggregator.individuals.map_iterator ();
Utils.persona_uid_iter = null;
}
- Individual individual = null;
while (Utils.persona_uid_iter != null ||
- Utils.individual_id_iter.next (null, out individual) == true)
+ Utils.individual_id_iter.next () == true)
{
+ var individual = Utils.individual_id_iter.get_value ();
+
if (Utils.persona_uid_iter == null)
{
assert (individual != null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]