// concurrent modification protection
private int _stamp = 0;
- public ArrayList (EqualFunc equal_func = GLib.direct_equal) {
+ public ArrayList (EqualFunc? equal_func = null) {
+ if (equal_func == null) {
+ equal_func = Functions.get_equal_func_for (typeof (G));
+ }
this.equal_func = equal_func;
}
using GLib;
namespace Gee {
+
+ public class Functions {
+
+ public static EqualFunc get_equal_func_for (Type t) {
+ if (t == typeof (string)) {
+ return str_equal;
+ } else {
+ return direct_equal;
+ }
+ }
+
+ public static HashFunc get_hash_func_for (Type t) {
+ if (t == typeof (string)) {
+ return str_hash;
+ } else {
+ return direct_hash;
+ }
+ }
+
+ public static CompareFunc get_compare_func_for (Type t) {
+ if (t == typeof (string)) {
+ return (CompareFunc) strcmp;
+ } else {
+ return direct_compare;
+ }
+ }
+ }
+
public static int direct_compare (void* _val1, void* _val2) {
long val1 = (long)_val1, val2 = (long)_val2;
if (val1 > val2) {
private const int MIN_SIZE = 11;
private const int MAX_SIZE = 13845163;
- public HashMap (HashFunc key_hash_func = GLib.direct_hash, EqualFunc key_equal_func = GLib.direct_equal, EqualFunc value_equal_func = GLib.direct_equal) {
+ public HashMap (HashFunc? key_hash_func = null, EqualFunc? key_equal_func = null, EqualFunc? value_equal_func = null) {
+ if (key_hash_func == null) {
+ key_hash_func = Functions.get_hash_func_for (typeof (K));
+ }
+ if (key_equal_func == null) {
+ key_equal_func = Functions.get_equal_func_for (typeof (K));
+ }
+ if (value_equal_func == null) {
+ value_equal_func = Functions.get_equal_func_for (typeof (V));
+ }
this.key_hash_func = key_hash_func;
this.key_equal_func = key_equal_func;
this.value_equal_func = value_equal_func;
private const int MIN_SIZE = 11;
private const int MAX_SIZE = 13845163;
- public HashSet (HashFunc hash_func = GLib.direct_hash, EqualFunc equal_func = GLib.direct_equal) {
+ public HashSet (HashFunc? hash_func = null, EqualFunc? equal_func = null) {
+ if (hash_func == null) {
+ hash_func = Functions.get_hash_func_for (typeof (G));
+ }
+ if (equal_func == null) {
+ equal_func = Functions.get_equal_func_for (typeof (G));
+ }
this.hash_func = hash_func;
this.equal_func = equal_func;
}
public EqualFunc equal_func { private set; get; }
- public LinkedList (EqualFunc equal_func = direct_equal) {
+ public LinkedList (EqualFunc? equal_func = null) {
+ if (equal_func == null) {
+ equal_func = Functions.get_equal_func_for (typeof (G));
+ }
this.equal_func = equal_func;
}
private int _size = 0;
- public TreeMap (CompareFunc key_compare_func = Gee.direct_compare, EqualFunc value_equal_func = GLib.direct_equal) {
+ public TreeMap (CompareFunc? key_compare_func = null, EqualFunc? value_equal_func = null) {
+ if (key_compare_func == null) {
+ key_compare_func = Functions.get_compare_func_for (typeof (K));
+ }
+ if (value_equal_func == null) {
+ value_equal_func = Functions.get_equal_func_for (typeof (V));
+ }
this.key_compare_func = key_compare_func;
this.value_equal_func = value_equal_func;
}
private int _size = 0;
- public TreeSet (CompareFunc compare_func = Gee.direct_compare) {
+ public TreeSet (CompareFunc? compare_func = null) {
+ if (compare_func == null) {
+ compare_func = Functions.get_compare_func_for (typeof (G));
+ }
this.compare_func = compare_func;
}