Support for separate search-sort comparison added
This commit is contained in:
@@ -80,7 +80,7 @@ namespace ZRCola {
|
||||
|
||||
|
||||
///
|
||||
/// Compares two elements
|
||||
/// Compares two elements (for searching)
|
||||
///
|
||||
/// \param[in] a Pointer to first element
|
||||
/// \param[in] b Pointer to second element
|
||||
@@ -93,6 +93,20 @@ namespace ZRCola {
|
||||
virtual int compare(_In_ const T &a, _In_ const T &b) const = 0;
|
||||
|
||||
|
||||
///
|
||||
/// Compares two elements (for sorting)
|
||||
///
|
||||
/// \param[in] a Pointer to first element
|
||||
/// \param[in] b Pointer to second element
|
||||
///
|
||||
/// \returns
|
||||
/// - <0 when a < b
|
||||
/// - =0 when a == b
|
||||
/// - >0 when a > b
|
||||
///
|
||||
virtual int compare_sort(_In_ const T &a, _In_ const T &b) const = 0;
|
||||
|
||||
|
||||
///
|
||||
/// Search for the element in the index
|
||||
/// The elements matching \p el are located on the interval [\p start, \p end) in the index.
|
||||
@@ -139,7 +153,7 @@ namespace ZRCola {
|
||||
static int __cdecl compare_s(void *p, const void *a, const void *b)
|
||||
{
|
||||
const index<T, T_idx> *t = (const index<T, T_idx>*)p;
|
||||
return t->compare(t->host[*(const T_idx*)a], t->host[*(const T_idx*)b]);
|
||||
return t->compare_sort(t->host[*(const T_idx*)a], t->host[*(const T_idx*)b]);
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -92,7 +92,7 @@ namespace ZRCola {
|
||||
indexComp(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32>(h) {}
|
||||
|
||||
///
|
||||
/// Compares two transformations by string
|
||||
/// Compares two transformations by string (for searching)
|
||||
///
|
||||
/// \param[in] a Pointer to key sequence
|
||||
/// \param[in] b Pointer to second key sequence
|
||||
@@ -113,6 +113,32 @@ namespace ZRCola {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
///
|
||||
/// Compares two transformations by string (for sorting)
|
||||
///
|
||||
/// \param[in] a Pointer to first element
|
||||
/// \param[in] b Pointer to second element
|
||||
///
|
||||
/// \returns
|
||||
/// - <0 when a < b
|
||||
/// - =0 when a == b
|
||||
/// - >0 when a > b
|
||||
///
|
||||
virtual int compare_sort(_In_ const unsigned __int16 &a, _In_ const unsigned __int16 &b) const
|
||||
{
|
||||
const translation
|
||||
&trans_a = (const translation&)a,
|
||||
&trans_b = (const translation&)b;
|
||||
|
||||
int r = translation::CompareString(trans_a.str, trans_a.str_len, trans_b.str, trans_b.str_len);
|
||||
if (r != 0) return r;
|
||||
|
||||
if (trans_a.chr < trans_b.chr) return -1;
|
||||
else if (trans_a.chr > trans_b.chr) return +1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
} idxComp; ///< Composition index
|
||||
|
||||
|
||||
@@ -130,7 +156,7 @@ namespace ZRCola {
|
||||
indexDecomp(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32>(h) {}
|
||||
|
||||
///
|
||||
/// Compares two transformations by string
|
||||
/// Compares two transformations by character (for searching)
|
||||
///
|
||||
/// \param[in] a Pointer to key sequence
|
||||
/// \param[in] b Pointer to second key sequence
|
||||
@@ -151,6 +177,32 @@ namespace ZRCola {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
///
|
||||
/// Compares two transformations by character (for sorting)
|
||||
///
|
||||
/// \param[in] a Pointer to first element
|
||||
/// \param[in] b Pointer to second element
|
||||
///
|
||||
/// \returns
|
||||
/// - <0 when a < b
|
||||
/// - =0 when a == b
|
||||
/// - >0 when a > b
|
||||
///
|
||||
virtual int compare_sort(_In_ const unsigned __int16 &a, _In_ const unsigned __int16 &b) const
|
||||
{
|
||||
const translation
|
||||
&trans_a = (const translation&)a,
|
||||
&trans_b = (const translation&)b;
|
||||
|
||||
if (trans_a.chr < trans_b.chr) return -1;
|
||||
else if (trans_a.chr > trans_b.chr) return +1;
|
||||
|
||||
int r = translation::CompareString(trans_a.str, trans_a.str_len, trans_b.str, trans_b.str_len);
|
||||
if (r != 0) return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
} idxDecomp; ///< Decomposition index
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user