When
mco_register_collations()
ormco_uda_register_collation()
is called it must pass amco_collation_funcs_t
structure containing two callback functions defined as follows:typedef struct mco_collation_funcs_t_ { mco_compare_collation_f comp; mco_hash_collation_f hash; } mco_collation_funcs_t, *mco_collation_funcs_h;The collation compare functions have the following prototype defined in
mco.h
:typedef int2 (*mco_compare_collation_f) ( mco_collate_h c1, uint2 len1, mco_collate_h c2, uint2 len2);The parameters are as follows:
c1 The address of the first mco_collate_t
struct used for the comparison.len1 The length of the first operand in the comparison. c2 The address of the second mco_collate_t
struct used for the comparison.len2 The length of the second operand in the comparison. Note that the compare functions should return < 0, =, or >0 depending on whether the object value is less than, equal to or greater than the external key value.
The collation hash functions have the following prototype defined in
mco.h
:typedef mco_hash_counter_t (*mco_hash_collation_f) ( mco_collate_h c, uint2 len);The parameters are as follows:
c The address of the mco_collate_t
struct containing the character array to hash.len The length of the character array to hash.
Following are examples of collation function implementations:
/* custom compare & hash functions */ int2 coll_cmp(mco_collate_h c1, uint2 len1, mco_collate_h c2, uint2 len2) { mco_uda_value_t val1, val2; char buf1[20], buf2[20]; /* get first object's value */ val1.type = MCO_DD_STRING; val1.v.p.size = sizeof(buf1); val1.v.p.p.c = buf1; mco_uda_collate_get(c1, &val1); /* get second object's value */ val2.type = MCO_DD_STRING; val2.v.p.size = sizeof(buf2); val2.v.p.p.c = buf2; mco_uda_collate_get(c2, &val2); /* compare values */ return STR_CMP(buf1, buf2); } uint4 coll_hash(mco_collate_h c, uint2 len) { mco_uda_value_t val; char buf[20]; /* get object's value */ val.type = MCO_DD_STRING; val.v.p.size = sizeof(buf); val.v.p.p.c = buf; mco_uda_collate_get(c, &val); /* hash value */ return strlen(buf); }