[geary/mjog/misc-fixes: 3/6] Fix indentation of util-collection.vala



commit 1deae845c30753c317da45426f0d5bcc4b3668d3
Author: Michael Gratton <mike vee net>
Date:   Tue Nov 19 13:23:04 2019 +1100

    Fix indentation of util-collection.vala

 src/engine/util/util-collection.vala | 344 ++++++++++++++++++-----------------
 1 file changed, 177 insertions(+), 167 deletions(-)
---
diff --git a/src/engine/util/util-collection.vala b/src/engine/util/util-collection.vala
index 0ba4e09e..46ba01d1 100644
--- a/src/engine/util/util-collection.vala
+++ b/src/engine/util/util-collection.vala
@@ -6,203 +6,213 @@
 
 namespace Geary.Collection {
 
-public delegate uint8 ByteTransformer(uint8 b);
+    public delegate uint8 ByteTransformer(uint8 b);
 
-public inline bool is_empty(Gee.Collection? c) {
-    return c == null || c.size == 0;
-}
-
-/** Returns a modifiable collection containing a single element. */
-public Gee.Collection<T> single<T>(T element) {
-    Gee.Collection<T> single = new Gee.LinkedList<T>();
-    single.add(element);
-    return single;
-}
-
-/** Returns a modifiable map containing a single entry. */
-public Gee.Map<K,V> single_map<K,V>(K key, V value) {
-    Gee.Map<K,V> single = new Gee.HashMap<K,V>();
-    single.set(key, value);
-    return single;
-}
-
-// A substitute for ArrayList<G>.wrap() for compatibility with older versions of Gee.
-public Gee.ArrayList<G> array_list_wrap<G>(G[] a, owned Gee.EqualDataFunc<G>? equal_func = null) {
-    Gee.ArrayList<G> list = new Gee.ArrayList<G>((owned) equal_func);
-    add_all_array<G>(list, a);
-    return list;
-}
-
-public Gee.ArrayList<G> to_array_list<G>(Gee.Collection<G> c) {
-    Gee.ArrayList<G> list = new Gee.ArrayList<G>();
-    list.add_all(c);
-
-    return list;
-}
-
-public Gee.HashMap<Key, Value> to_hash_map<Key, Value>(
-    Gee.Collection<Value> c, Gee.MapFunc<Key, Value> key_selector) {
-    Gee.HashMap<Key, Value> map = new Gee.HashMap<Key, Value>();
-    foreach (Value v in c)
-        map.set(key_selector(v), v);
-    return map;
-}
-
-public void add_all_array<G>(Gee.Collection<G> c, G[] ar) {
-    foreach (G g in ar)
-        c.add(g);
-}
-
-public G? get_first<G>(Gee.Collection<G> c) {
-    Gee.Iterator<G> iter = c.iterator();
-
-    return iter.next() ? iter.get() : null;
-}
+    public inline bool is_empty(Gee.Collection? c) {
+        return c == null || c.size == 0;
+    }
 
-/**
- * Returns the first element in the Collection that passes the Predicte function.
- *
- * The Collection is walked in Iterator order.
- */
-public G? find_first<G>(Gee.Collection<G> c, owned Gee.Predicate<G> pred) {
-    Gee.Iterator<G> iter = c.iterator();
-    while (iter.next()) {
-        if (pred(iter.get()))
-            return iter.get();
+    /** Returns a modifiable collection containing a single element. */
+    public Gee.Collection<T> single<T>(T element) {
+        Gee.Collection<T> single = new Gee.LinkedList<T>();
+        single.add(element);
+        return single;
     }
 
-    return null;
-}
+    /** Returns a modifiable map containing a single entry. */
+    public Gee.Map<K,V> single_map<K,V>(K key, V value) {
+        Gee.Map<K,V> single = new Gee.HashMap<K,V>();
+        single.set(key, value);
+        return single;
+    }
 
-public bool are_sets_equal<G>(Gee.Set<G> a, Gee.Set<G> b) {
-    if (a.size != b.size)
-        return false;
+    // A substitute for ArrayList<G>.wrap() for compatibility with older versions of Gee.
+    public Gee.ArrayList<G> array_list_wrap<G>(G[] a, owned Gee.EqualDataFunc<G>? equal_func = null) {
+        Gee.ArrayList<G> list = new Gee.ArrayList<G>((owned) equal_func);
+        add_all_array<G>(list, a);
+        return list;
+    }
 
-    foreach (G element in a) {
-        if (!b.contains(element))
-            return false;
+    public Gee.ArrayList<G> to_array_list<G>(Gee.Collection<G> c) {
+        Gee.ArrayList<G> list = new Gee.ArrayList<G>();
+        list.add_all(c);
+        return list;
     }
 
-    return true;
-}
+    public Gee.HashMap<Key, Value> to_hash_map<Key, Value>(
+        Gee.Collection<Value> c, Gee.MapFunc<Key, Value> key_selector) {
+        Gee.HashMap<Key, Value> map = new Gee.HashMap<Key, Value>();
+        foreach (Value v in c) {
+            map.set(key_selector(v), v);
+        }
+        return map;
+    }
 
-/**
- * Removes all elements from the Collection that do pass the Predicate function.
- *
- * Note that this modifies the supplied Collection.
- */
-public Gee.Collection<G> remove_if<G>(Gee.Collection<G> c, owned Gee.Predicate<G> pred) {
-    Gee.Iterator<G> iter = c.iterator();
-    while (iter.next()) {
-        if (pred(iter.get()))
-            iter.remove();
+    public void add_all_array<G>(Gee.Collection<G> c, G[] ar) {
+        foreach (G g in ar) {
+            c.add(g);
+        }
     }
 
-    return c;
-}
+    public G? get_first<G>(Gee.Collection<G> c) {
+        Gee.Iterator<G> iter = c.iterator();
+        return iter.next() ? iter.get() : null;
+    }
 
-/**
- * Sets the dest Map with all keys and values in src.
- */
-public void map_set_all<K, V>(Gee.Map<K, V> dest, Gee.Map<K, V> src) {
-    foreach (K key in src.keys)
-        dest.set(key, src.get(key));
-}
+    /**
+     * Returns the first element in the Collection that passes the Predicte function.
+     *
+     * The Collection is walked in Iterator order.
+     */
+    public G? find_first<G>(Gee.Collection<G> c, owned Gee.Predicate<G> pred) {
+        Gee.Iterator<G> iter = c.iterator();
+        while (iter.next()) {
+            if (pred(iter.get()))
+                return iter.get();
+        }
+
+        return null;
+    }
 
-/**
- * Sets multiple elements with the same key in a MultiMap.
- */
-public void multi_map_set_all<K, V>(Gee.MultiMap<K, V> dest, K key, Gee.Collection<V> values) {
-    foreach (V value in values)
-        dest.set(key, value);
-}
+    public bool are_sets_equal<G>(Gee.Set<G> a, Gee.Set<G> b) {
+        if (a.size != b.size) {
+            return false;
+        }
 
-/**
- * Removes all keys from the Map.
- */
-public void map_unset_all_keys<K, V>(Gee.Map<K, V> map, Gee.Collection<K> keys) {
-    foreach (K key in keys)
-        map.unset(key);
-}
+        foreach (G element in a) {
+            if (!b.contains(element)) {
+                return false;
+            }
+        }
 
-/**
- * Return a MultiMap of value => key of the input map's key => values.
- */
-public Gee.MultiMap<V, K> reverse_multi_map<K, V>(Gee.MultiMap<K, V> map) {
-    Gee.HashMultiMap<V, K> reverse = new Gee.HashMultiMap<V, K>();
-    foreach (K key in map.get_keys()) {
-        foreach (V value in map.get(key))
-            reverse.set(value, key);
+        return true;
     }
 
-    return reverse;
-}
+    /**
+     * Removes all elements from the Collection that do pass the Predicate function.
+     *
+     * Note that this modifies the supplied Collection.
+     */
+    public Gee.Collection<G> remove_if<G>(Gee.Collection<G> c, owned Gee.Predicate<G> pred) {
+        Gee.Iterator<G> iter = c.iterator();
+        while (iter.next()) {
+            if (pred(iter.get()))
+                iter.remove();
+        }
+
+        return c;
+    }
 
-/**
- * To be used by a Hashable's to_hash() method.
- */
-public inline uint int64_hash(int64 value) {
-    return hash_memory(&value, sizeof(int64));
-}
+    /**
+     * Sets the dest Map with all keys and values in src.
+     */
+    public void map_set_all<K, V>(Gee.Map<K, V> dest, Gee.Map<K, V> src) {
+        foreach (K key in src.keys) {
+            dest.set(key, src.get(key));
+        }
+    }
 
-/**
- * To be used as hash_func for Gee collections.
- */
-public inline uint int64_hash_func(int64? n) {
-    return hash_memory((uint8 *) n, sizeof(int64));
-}
+    /**
+     * Sets multiple elements with the same key in a MultiMap.
+     */
+    public void multi_map_set_all<K, V>(Gee.MultiMap<K, V> dest, K key, Gee.Collection<V> values) {
+        foreach (V value in values) {
+            dest.set(key, value);
+        }
+    }
 
-/**
- * To be used as equal_func for Gee collections.
- */
-public bool int64_equal_func(int64? a, int64? b) {
-    int64 *bia = (int64 *) a;
-    int64 *bib = (int64 *) b;
+    /**
+     * Removes all keys from the Map.
+     */
+    public void map_unset_all_keys<K, V>(Gee.Map<K, V> map, Gee.Collection<K> keys) {
+        foreach (K key in keys) {
+            map.unset(key);
+        }
+    }
 
-    return (*bia) == (*bib);
-}
+    /**
+     * Return a MultiMap of value => key of the input map's key => values.
+     */
+    public Gee.MultiMap<V, K> reverse_multi_map<K, V>(Gee.MultiMap<K, V> map) {
+        Gee.HashMultiMap<V, K> reverse = new Gee.HashMultiMap<V, K>();
+        foreach (K key in map.get_keys()) {
+            foreach (V value in map.get(key)) {
+                reverse.set(value, key);
+            }
+        }
+
+        return reverse;
+    }
 
-/**
- * A rotating-XOR hash that can be used to hash memory buffers of any size.
- */
-public uint hash_memory(void *ptr, size_t bytes) {
-    if (ptr == null || bytes == 0)
-        return 0;
+    /**
+     * To be used by a Hashable's to_hash() method.
+     */
+    public inline uint int64_hash(int64 value) {
+        return hash_memory(&value, sizeof(int64));
+    }
 
-    uint8 *u8 = (uint8 *) ptr;
+    /**
+     * To be used as hash_func for Gee collections.
+     */
+    public inline uint int64_hash_func(int64? n) {
+        return hash_memory((uint8 *) n, sizeof(int64));
+    }
 
-    // initialize hash to first byte value and then rotate-XOR from there
-    uint hash = *u8;
-    for (int ctr = 1; ctr < bytes; ctr++)
-        hash = (hash << 4) ^ (hash >> 28) ^ (*u8++);
+    /**
+     * To be used as equal_func for Gee collections.
+     */
+    public bool int64_equal_func(int64? a, int64? b) {
+        int64 *bia = (int64 *) a;
+        int64 *bib = (int64 *) b;
 
-    return hash;
-}
+        return (*bia) == (*bib);
+    }
 
-/**
- * A rotating-XOR hash that can be used to hash memory buffers of any size until a terminator byte
- * is found.
- *
- * A {@link ByteTransformer} may be supplied to convert bytes before they are hashed.
- *
- * Returns zero if the initial byte is the terminator.
- */
-public uint hash_memory_stream(void *ptr, uint8 terminator, ByteTransformer? cb) {
-    uint8 *u8 = (uint8 *) ptr;
+    /**
+     * A rotating-XOR hash that can be used to hash memory buffers of any size.
+     */
+    public uint hash_memory(void *ptr, size_t bytes) {
+        if (ptr == null || bytes == 0) {
+            return 0;
+        }
 
-    uint hash = 0;
-    for (;;) {
-        uint8 b = *u8++;
-        if (b == terminator)
-            break;
+        uint8 *u8 = (uint8 *) ptr;
 
-        if (cb != null)
-            b = cb(b);
+        // initialize hash to first byte value and then rotate-XOR from there
+        uint hash = *u8;
+        for (int ctr = 1; ctr < bytes; ctr++) {
+            hash = (hash << 4) ^ (hash >> 28) ^ (*u8++);
+        }
 
-        hash = (hash << 4) ^ (hash >> 28) ^ b;
+        return hash;
     }
 
-    return hash;
-}
+    /**
+     * A rotating-XOR hash that can be used to hash memory buffers of any size until a terminator byte
+     * is found.
+     *
+     * A {@link ByteTransformer} may be supplied to convert bytes before they are hashed.
+     *
+     * Returns zero if the initial byte is the terminator.
+     */
+    public uint hash_memory_stream(void *ptr, uint8 terminator, ByteTransformer? cb) {
+        uint8 *u8 = (uint8 *) ptr;
+
+        uint hash = 0;
+        for (;;) {
+            uint8 b = *u8++;
+            if (b == terminator) {
+                break;
+            }
+
+            if (cb != null) {
+                b = cb(b);
+            }
+
+            hash = (hash << 4) ^ (hash >> 28) ^ b;
+        }
+
+        return hash;
+    }
 
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]