76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'ext/hmsearch/postgres_ext.cc', line 76
static VALUE HmSearch_lookup(int argc, VALUE *argv, VALUE self)
{
VALUE _hash, _reduced_error;
rb_scan_args(argc, argv, "11", &_hash, &_reduced_error);
const char *hash = StringValueCStr(_hash);
int reduced_error = NIL_P(_reduced_error) ? -1 : FIX2INT(_reduced_error);
HmSearch::LookupResultList matches;
std::string error_msg;
if (!HmSearch_ptr(self)->lookup(HmSearch::parse_hexhash(hash), matches, reduced_error, &error_msg)) {
rb_raise(eHmSearchError, "%s", error_msg.c_str());
}
VALUE results = rb_ary_new2(matches.size());
for (HmSearch::LookupResultList::const_iterator it=matches.begin(); it != matches.end(); ++it) {
VALUE result = rb_hash_new();
rb_hash_aset(result, ID2SYM(id_hash), rb_str_new2(HmSearch::format_hexhash(it->hash).c_str()));
rb_hash_aset(result, ID2SYM(id_distance), INT2NUM(it->distance));
rb_ary_push(results, result);
}
return results;
}
|