Index reorganization
This commit is contained in:
parent
3e6c535f42
commit
48e0fc9639
@ -33,6 +33,7 @@
|
|||||||
#define ZRCOLA_NOVTABLE __declspec(novtable)
|
#define ZRCOLA_NOVTABLE __declspec(novtable)
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable: 4251)
|
#pragma warning(disable: 4251)
|
||||||
|
#pragma warning(disable: 4512)
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -54,16 +55,26 @@ namespace ZRCola {
|
|||||||
///
|
///
|
||||||
/// Memory index
|
/// Memory index
|
||||||
///
|
///
|
||||||
template <class T = unsigned __int32>
|
template <class T, class T_idx = unsigned __int32>
|
||||||
class index : public std::vector<T>
|
class index : public std::vector<T_idx>
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
std::vector<T> &host; ///< Reference to host data
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
///
|
||||||
|
/// Constructs the index
|
||||||
|
///
|
||||||
|
/// \param[in] h Reference to vector holding the data
|
||||||
|
///
|
||||||
|
index(_In_ std::vector<T> &h) : host(h) {}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Sorts index
|
/// Sorts index
|
||||||
///
|
///
|
||||||
inline void sort()
|
inline void sort()
|
||||||
{
|
{
|
||||||
qsort_s(data(), size(), sizeof(T), compare_s, this);
|
qsort_s(data(), size(), sizeof(T_idx), compare_s, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -77,12 +88,13 @@ namespace ZRCola {
|
|||||||
/// - =0 when a == b
|
/// - =0 when a == b
|
||||||
/// - >0 when a > b
|
/// - >0 when a > b
|
||||||
///
|
///
|
||||||
virtual int compare(_In_ const void *a, _In_ const void *b) const = 0;
|
virtual int compare(_In_ const T &a, _In_ const T &b) const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int __cdecl compare_s(void *p, const void *a, const void *b)
|
static int __cdecl compare_s(void *p, const void *a, const void *b)
|
||||||
{
|
{
|
||||||
return ((const index<T>*)p)->compare(a, 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]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,18 +81,15 @@ namespace ZRCola {
|
|||||||
///
|
///
|
||||||
/// Composition index
|
/// Composition index
|
||||||
///
|
///
|
||||||
class indexComp : public index<unsigned __int32>
|
class indexComp : public index<unsigned __int16, unsigned __int32>
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
std::vector<unsigned __int16> &source; ///< Reference to source data
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
/// Constructs the index
|
/// Constructs the index
|
||||||
///
|
///
|
||||||
/// \param[in] d Reference to vector holding the data
|
/// \param[in] h Reference to vector holding the data
|
||||||
///
|
///
|
||||||
indexComp(_In_ std::vector<unsigned __int16> &s) : source(s) {}
|
indexComp(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32>(h) {}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Compares two transformations by string
|
/// Compares two transformations by string
|
||||||
@ -105,11 +102,11 @@ namespace ZRCola {
|
|||||||
/// - =0 when a == b
|
/// - =0 when a == b
|
||||||
/// - >0 when a > b
|
/// - >0 when a > b
|
||||||
///
|
///
|
||||||
virtual int compare(_In_ const void *a, _In_ const void *b) const
|
virtual int compare(_In_ const unsigned __int16 &a, _In_ const unsigned __int16 &b) const
|
||||||
{
|
{
|
||||||
const translation
|
const translation
|
||||||
&trans_a = (const translation&)source[*(const unsigned __int32*)a],
|
&trans_a = (const translation&)a,
|
||||||
&trans_b = (const translation&)source[*(const unsigned __int32*)b];
|
&trans_b = (const translation&)b;
|
||||||
|
|
||||||
int r = translation::CompareString(trans_a.str, trans_a.str_len, trans_b.str, trans_b.str_len);
|
int r = translation::CompareString(trans_a.str, trans_a.str_len, trans_b.str, trans_b.str_len);
|
||||||
if (r != 0) return r;
|
if (r != 0) return r;
|
||||||
@ -125,18 +122,15 @@ namespace ZRCola {
|
|||||||
///
|
///
|
||||||
/// Decomposition index
|
/// Decomposition index
|
||||||
///
|
///
|
||||||
class indexDecomp : public index<unsigned __int32>
|
class indexDecomp : public index<unsigned __int16, unsigned __int32>
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
std::vector<unsigned __int16> &source; ///< Reference to source data
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
/// Constructs the index
|
/// Constructs the index
|
||||||
///
|
///
|
||||||
/// \param[in] d Reference to vector holding the data
|
/// \param[in] h Reference to vector holding the data
|
||||||
///
|
///
|
||||||
indexDecomp(_In_ std::vector<unsigned __int16> &s) : source(s) {}
|
indexDecomp(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32>(h) {}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Compares two transformations by string
|
/// Compares two transformations by string
|
||||||
@ -149,11 +143,11 @@ namespace ZRCola {
|
|||||||
/// - =0 when a == b
|
/// - =0 when a == b
|
||||||
/// - >0 when a > b
|
/// - >0 when a > b
|
||||||
///
|
///
|
||||||
virtual int compare(_In_ const void *a, _In_ const void *b) const
|
virtual int compare(_In_ const unsigned __int16 &a, _In_ const unsigned __int16 &b) const
|
||||||
{
|
{
|
||||||
const translation
|
const translation
|
||||||
&trans_a = (const translation&)source[*(const unsigned __int32*)a],
|
&trans_a = (const translation&)a,
|
||||||
&trans_b = (const translation&)source[*(const unsigned __int32*)b];
|
&trans_b = (const translation&)b;
|
||||||
|
|
||||||
if (trans_a.chr < trans_b.chr) return -1;
|
if (trans_a.chr < trans_b.chr) return -1;
|
||||||
else if (trans_a.chr > trans_b.chr) return +1;
|
else if (trans_a.chr > trans_b.chr) return +1;
|
||||||
|
@ -89,18 +89,15 @@ namespace ZRCola {
|
|||||||
///
|
///
|
||||||
/// Character index
|
/// Character index
|
||||||
///
|
///
|
||||||
class indexChr : public index<unsigned __int32>
|
class indexChr : public index<unsigned __int16, unsigned __int32>
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
std::vector<unsigned __int16> &source; ///< Reference to source data
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
/// Constructs the index
|
/// Constructs the index
|
||||||
///
|
///
|
||||||
/// \param[in] d Reference to vector holding the data
|
/// \param[in] h Reference to vector holding the data
|
||||||
///
|
///
|
||||||
indexChr(_In_ std::vector<unsigned __int16> &s) : source(s) {}
|
indexChr(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32>(h) {}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Compares two key sequences by character
|
/// Compares two key sequences by character
|
||||||
@ -113,11 +110,11 @@ namespace ZRCola {
|
|||||||
/// - =0 when a == b
|
/// - =0 when a == b
|
||||||
/// - >0 when a > b
|
/// - >0 when a > b
|
||||||
///
|
///
|
||||||
virtual int compare(_In_ const void *a, _In_ const void *b) const
|
virtual int compare(_In_ const unsigned __int16 &a, _In_ const unsigned __int16 &b) const
|
||||||
{
|
{
|
||||||
const keyseq
|
const keyseq
|
||||||
&ks_a = (const keyseq&)source[*(const unsigned __int32*)a],
|
&ks_a = (const keyseq&)a,
|
||||||
&ks_b = (const keyseq&)source[*(const unsigned __int32*)b];
|
&ks_b = (const keyseq&)b;
|
||||||
|
|
||||||
if (ks_a.chr < ks_b.chr) return -1;
|
if (ks_a.chr < ks_b.chr) return -1;
|
||||||
else if (ks_a.chr > ks_b.chr) return +1;
|
else if (ks_a.chr > ks_b.chr) return +1;
|
||||||
@ -130,18 +127,15 @@ namespace ZRCola {
|
|||||||
///
|
///
|
||||||
/// Key index
|
/// Key index
|
||||||
///
|
///
|
||||||
class indexKey : public index<unsigned __int32>
|
class indexKey : public index<unsigned __int16, unsigned __int32>
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
std::vector<unsigned __int16> &source; ///< Reference to source data
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
/// Constructs the index
|
/// Constructs the index
|
||||||
///
|
///
|
||||||
/// \param[in] d Reference to vector holding the data
|
/// \param[in] h Reference to vector holding the data
|
||||||
///
|
///
|
||||||
indexKey(_In_ std::vector<unsigned __int16> &s) : source(s) {}
|
indexKey(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32>(h) {}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Compares two key sequences by key
|
/// Compares two key sequences by key
|
||||||
@ -154,11 +148,11 @@ namespace ZRCola {
|
|||||||
/// - =0 when a == b
|
/// - =0 when a == b
|
||||||
/// - >0 when a > b
|
/// - >0 when a > b
|
||||||
///
|
///
|
||||||
virtual int compare(_In_ const void *a, _In_ const void *b) const
|
virtual int compare(_In_ const unsigned __int16 &a, _In_ const unsigned __int16 &b) const
|
||||||
{
|
{
|
||||||
const keyseq
|
const keyseq
|
||||||
&ks_a = (const keyseq&)source[*(const unsigned __int32*)a],
|
&ks_a = (const keyseq&)a,
|
||||||
&ks_b = (const keyseq&)source[*(const unsigned __int32*)b];
|
&ks_b = (const keyseq&)b;
|
||||||
|
|
||||||
int r = keyseq::CompareSequence(ks_a.seq, ks_a.seq_len, ks_b.seq, ks_b.seq_len);
|
int r = keyseq::CompareSequence(ks_a.seq, ks_a.seq_len, ks_b.seq, ks_b.seq_len);
|
||||||
if (r != 0) return r;
|
if (r != 0) return r;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user