]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: add GLib.HashSet
authorEvan Nemerson <evan@nemerson.com>
Fri, 6 Jun 2014 04:15:10 +0000 (21:15 -0700)
committerEvan Nemerson <evan@nemerson.com>
Thu, 12 Jun 2014 04:24:52 +0000 (21:24 -0700)
This is basically just a convenience wrapper around GLib.HashTable
where the key and value are set to the same value, providing a set
data type instead of a map.

Fixes bug 686609.

vapi/glib-2.0.vapi

index be7b213591c8137e5d3c73f52d86b5796c47f4dd..29801e0f47ff167f4c14b3bda356e35adfbf89f7 100644 (file)
@@ -4143,6 +4143,7 @@ namespace GLib {
                public HashTable.full (HashFunc<K>? hash_func, EqualFunc<K>? key_equal_func, DestroyNotify? key_destroy_func, DestroyNotify? value_destroy_func);
                public void insert (owned K key, owned V value);
                public void replace (owned K key, owned V value);
+               [Deprecated (since = "vala-0.26", replacement = "HashSet.add")]
                public void add (owned K key);
                public unowned V? lookup (K key);
                public bool lookup_extended (K lookup_key, out unowned K orig_key, out unowned V value);
@@ -4173,6 +4174,39 @@ namespace GLib {
                public unowned GLib.HashTable<K,V> get_hash_table ();
        }
 
+       [Compact, CCode (cname = "GHashTable", lower_case_cprefix = "g_hash_table_", ref_function = "g_hash_table_ref", unref_function = "g_hash_table_unref", type_id = "G_TYPE_HASH_TABLE", type_signature = "a{%s}")]
+       public class HashSet<T> {
+               [CCode (cname = "g_hash_table_new_full", simple_generics = true)]
+               public HashSet (HashFunc<T>? hash_func, EqualFunc<T>? equal_func, GLib.DestroyNotify? pass_null_here = null);
+               public void add (owned T value);
+               public bool contains (T valule);
+               public bool remove (T value);
+               public void remove_all ();
+               public GLib.List<unowned T> get_values ();
+               [CCode (cname = "g_hash_table_iter_init", instance_pos = -1)]
+               public GLib.HashSetIter<T> iterator ();
+               [CCode (cname = "_vala_g_hash_set_foreach")]
+               public void @foreach (GLib.Func<T> func) {
+                       ((GLib.HashTable<unowned T,T>) this).foreach ((k, v) => func (v));
+               }
+               public uint length {
+                       [CCode (cname = "g_hash_table_get_size")]
+                       get;
+               }
+       }
+
+       [CCode (cname = "GHashTableIter", lower_case_cprefix = "g_hash_table_iter_")]
+       public struct HashSetIter<T> {
+               [CCode (cname = "_vala_hash_set_next_value")]
+               public unowned T? next_value () {
+                       void* vi = &this;
+                       GLib.HashTableIter<unowned T,T>* htp = vi;
+                       unowned T? value;
+                       return htp->next (out value, null) ? value : null;
+               }
+               public void remove ();
+       }
+
        [CCode (has_target = false)]
        public delegate uint HashFunc<K> (K key);
        [CCode (has_target = false)]