diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2011-03-24 12:19:32 +0000 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2011-04-16 14:43:16 +0100 |
commit | 34e89c9fdeba10c52238831cd6303fa7a2e9e2c3 (patch) | |
tree | a8af44f0b491dacbc0cbf461f390faf42c0a55d0 | |
parent | f311735144325c44de2c542415fcf65913d9e286 (diff) |
Add stamping to LinkedHashSet
Since we don't have access to the stamps in the LinkedHashSet's linked list
or hash set, we have to maintain our own. This is necessary for implementing
our own Iterator. (See next commit.)
Helps: bgo#645684
-rw-r--r-- | folks/linked-hash-set.vala | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/folks/linked-hash-set.vala b/folks/linked-hash-set.vala index ffb149d..ab1c8ba 100644 --- a/folks/linked-hash-set.vala +++ b/folks/linked-hash-set.vala @@ -33,6 +33,9 @@ public class Folks.LinkedHashSet<G> : AbstractList<G>, private HashSet<G> _hash_set; /* A linked list that maintains the order of the items. */ private LinkedList<G> _linked_list; + /* A stamp which changes whenever either the hash set or the linked list are + * modified. */ + private int _stamp = 0; /** * Constructs a new empty set. @@ -93,6 +96,7 @@ public class Folks.LinkedHashSet<G> : AbstractList<G>, { if (this._hash_set.add (item)) { + this._stamp++; this._linked_list.add (item); return true; } @@ -114,6 +118,7 @@ public class Folks.LinkedHashSet<G> : AbstractList<G>, { if (this._hash_set.remove (item)) { + this._stamp++; this._linked_list.remove (item); return true; } @@ -131,6 +136,7 @@ public class Folks.LinkedHashSet<G> : AbstractList<G>, */ public override void clear () { + this._stamp++; this._hash_set.clear (); this._linked_list.clear (); } @@ -197,7 +203,10 @@ public class Folks.LinkedHashSet<G> : AbstractList<G>, { G item = this._linked_list.remove_at (index); if (item != null) - this._hash_set.remove (item); + { + this._stamp++; + this._hash_set.remove (item); + } return item; } |