Finished b-tree index support
This commit is contained in:
parent
25d23b90d3
commit
2e40efe3b2
|
@ -1,3 +1,4 @@
|
|||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
|
@ -16,6 +17,11 @@ using namespace i18n::phonenumbers;
|
|||
|
||||
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
|
||||
*/
|
||||
|
@ -284,4 +290,22 @@ extern "C" {
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -124,6 +124,9 @@ CREATE OPERATOR >= (
|
|||
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
|
||||
DEFAULT FOR TYPE phone_number USING btree AS
|
||||
|
|
Loading…
Reference in New Issue