Finished b-tree index support

This commit is contained in:
BLM 2015-07-24 14:48:22 -05:00
parent 25d23b90d3
commit 2e40efe3b2
2 changed files with 27 additions and 0 deletions

View File

@ -1,3 +1,4 @@
#include <algorithm>
#include <exception> #include <exception>
#include <string> #include <string>
@ -16,6 +17,11 @@ using namespace i18n::phonenumbers;
static const PhoneNumberUtil* const phoneUtil = PhoneNumberUtil::GetInstance(); static const PhoneNumberUtil* const phoneUtil = PhoneNumberUtil::GetInstance();
template <typename T>
T clip(const T& n, const T& lower, const T& upper) {
return std::max(lower, std::min(n, upper));
}
/* /*
* Utility functions * Utility functions
*/ */
@ -284,4 +290,22 @@ extern "C" {
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
PGDLLEXPORT PG_FUNCTION_INFO_V1(phone_number_cmp);
PGDLLEXPORT Datum
phone_number_cmp(PG_FUNCTION_ARGS) {
try {
const ShortPhoneNumber* number1 = (ShortPhoneNumber*)PG_GETARG_POINTER(0);
const ShortPhoneNumber* number2 = (ShortPhoneNumber*)PG_GETARG_POINTER(1);
int64 compared = number1->compare_fast(*number2);
PG_RETURN_INT32(clip<int64>(compared, -1, 1));
} catch(std::exception& e) {
reportGenericError(e);
}
PG_RETURN_NULL();
}
} }

View File

@ -124,6 +124,9 @@ CREATE OPERATOR >= (
join = scalargtjoinsel join = scalargtjoinsel
); );
CREATE FUNCTION phone_number_cmp(phone_number, phone_number) RETURNS integer
LANGUAGE c IMMUTABLE STRICT
AS 'pg_libphonenumber', 'phone_number_cmp';
CREATE OPERATOR CLASS phone_number_ops CREATE OPERATOR CLASS phone_number_ops
DEFAULT FOR TYPE phone_number USING btree AS DEFAULT FOR TYPE phone_number USING btree AS