3 * Copyright (C) 2009 Maciej Piechotka
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Maciej Piechotka <uzytkownik2@gmail.com>
28 * Helper class for equal, hash and compare functions.
30 public class Functions {
32 private Functions () {
36 * Get a equality testing function for a given type.
38 * @param t the type which to get an equality testing function for.
40 * @return the equality testing function corresponding to the given type.
42 public static EqualFunc get_equal_func_for (Type t) {
43 if (t == typeof (string)) {
51 * Get a hash function for a given type.
53 * @param t the type which to get the hash function for.
55 * @return the hash function corresponding to the given type.
57 public static HashFunc get_hash_func_for (Type t) {
58 if (t == typeof (string)) {
66 * Get a comparator function for a given type.
68 * @param t the type which to get a comparator function for.
70 * @return the comparator function corresponding to the given type.
72 public static CompareFunc get_compare_func_for (Type t) {
73 if (t == typeof (string)) {
74 return (CompareFunc) strcmp;
76 return direct_compare;
82 * Compares two arbitrary elements together.
84 * The comparison is done on pointers and not on values behind.
86 * @param _val1 the first value to compare.
87 * @param _val2 the second value to compare.
89 * @return a negative value if _val1 is lesser than _val2, a positive value
90 * if _val1 is greater then _val2 and zero if both are equal.
92 public static int direct_compare (void* _val1, void* _val2) {
93 long val1 = (long)_val1, val2 = (long)_val2;
96 } else if (val1 == val2) {