Register a collation.
MCO_RET mco_uda_register_collation( /*IN*/ const mco_metadict_header_t * metadict,
/*IN*/ unsigned short dict_no,
/*IN*/ unsigned short collation_no,
/*IN-OUT*/ mco_collation_funcs_h coll_map,
/*IN*/ mco_compare_collation_f fcomp,
/*IN*/ mco_hash_collation_f fhash );
| metadict | The address of an initialized mco_metadict_header_t structure |
|
dict_no |
The number of the dictionary (must be between 0 and |
|
collation_no |
The collation number |
|
coll_map |
The address of an |
|
fcomp |
The application-supplied collation compare function. (See mco_compare_collation_f defined in mco.h) |
|
fhash |
The application-supplied collation hash function. (See mco_hash_collation_f defined in mco.h) |
| MCO_S_OK | Collation registered successfully |
| MCO_E_UDA_COLLATION_NOTFOUND | Collation not found |
| MCO_ERR_UDA | Fatal error registering collation |
Application snippet:
/* 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);
}
int main(int argc, char *argv[])
{
MCO_RET rc;
mco_collation_funcs_h coll_map;
unsigned int coll_map_size;
mco_metadict_header_t *metadict;
…
/* allocate collmap */
mco_uda_get_collmap_size(metadict, 0, &coll_map_size);
coll_map = (mco_collation_funcs_h) malloc(coll_map_size);
/* register collation compare & hash functions */
rc = mco_uda_register_collation(metadict, 0, coll_no, coll_map, &coll_cmp, &coll_hash);
…
}