grayphash 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/grayhash/grayphash.c +11 -6
- metadata +1 -1
data/ext/grayhash/grayphash.c
CHANGED
@@ -30,12 +30,17 @@ VALUE method_hamming(int argc, VALUE * argv, VALUE self) {
|
|
30
30
|
}
|
31
31
|
unsigned long long hash1 = rb_num2ull(argv[0]);
|
32
32
|
unsigned long long hash2 = rb_num2ull(argv[1]);
|
33
|
-
int* (*phash_func)();
|
34
|
-
phash_func = dlsym(sdl_library, "ph_hamming_distance");
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
|
35
|
+
ulong64 x = hash1^hash2;
|
36
|
+
const ulong64 m1 = 0x5555555555555555ULL;
|
37
|
+
const ulong64 m2 = 0x3333333333333333ULL;
|
38
|
+
const ulong64 h01 = 0x0101010101010101ULL;
|
39
|
+
const ulong64 m4 = 0x0f0f0f0f0f0f0f0fULL;
|
40
|
+
x -= (x >> 1) & m1;
|
41
|
+
x = (x & m2) + ((x >> 2) & m2);
|
42
|
+
x = (x + (x >> 4)) & m4;
|
43
|
+
return INT2FIX((x * h01)>>56);
|
39
44
|
}
|
40
45
|
|
41
46
|
|
@@ -60,7 +65,7 @@ VALUE method_close(VALUE self) {
|
|
60
65
|
}
|
61
66
|
|
62
67
|
VALUE method_about(VALUE self) {
|
63
|
-
return rb_str_new_cstr("pHash 0.9.4. Copyright 2008-2010 Aetilius, Inc. Included only some image functions.");
|
68
|
+
return rb_str_new_cstr("pHash 0.9.4. Copyright 2008-2010 Aetilius, Inc. Included only some image functions (grayphash v-0.0.4).");
|
64
69
|
//char* (*about)();
|
65
70
|
//about = dlsym(sdl_library, "ph_about");
|
66
71
|
|