2015-03-20 13:53:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2016-09-24 02:49:24 +00:00
|
|
|
#include <stdlib.h>
|
2015-03-20 13:53:54 +00:00
|
|
|
#include <qse/cmn/BinaryHeap.hpp>
|
|
|
|
#include <qse/cmn/String.hpp>
|
|
|
|
#include <qse/cmn/alg.h>
|
|
|
|
#include <qse/cmn/time.h>
|
|
|
|
|
2016-09-24 02:49:24 +00:00
|
|
|
|
|
|
|
//#define MAX_HEAP
|
|
|
|
|
2015-03-20 13:53:54 +00:00
|
|
|
class Julia
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Julia (int q = 0): x(QSE_NULL)
|
|
|
|
{
|
|
|
|
this->x = new int (q);
|
|
|
|
}
|
|
|
|
|
|
|
|
Julia (const Julia& q): x(QSE_NULL)
|
|
|
|
{
|
|
|
|
this->x = new int (*q.x);
|
|
|
|
}
|
|
|
|
|
2015-04-04 15:27:50 +00:00
|
|
|
#if defined(QSE_CPP_ENABLE_CPP11_MOVE)
|
2015-03-20 13:53:54 +00:00
|
|
|
Julia (Julia&& q)
|
|
|
|
{
|
|
|
|
this->x = q.x;
|
|
|
|
q.x = QSE_NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
~Julia()
|
|
|
|
{
|
|
|
|
if (this->x)
|
|
|
|
{
|
|
|
|
delete this->x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Julia& operator= (const Julia& q)
|
|
|
|
{
|
|
|
|
if (this != &q)
|
|
|
|
{
|
|
|
|
if (this->x) { delete this->x; this->x = QSE_NULL; }
|
|
|
|
this->x = new int (*q.x);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-04-04 15:27:50 +00:00
|
|
|
#if defined(QSE_CPP_ENABLE_CPP11_MOVE)
|
2015-03-20 13:53:54 +00:00
|
|
|
Julia& operator= (Julia&& q)
|
|
|
|
{
|
|
|
|
if (this != &q)
|
|
|
|
{
|
|
|
|
if (this->x) { delete this->x; this->x = QSE_NULL; }
|
|
|
|
this->x = q.x;
|
|
|
|
q.x = QSE_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-09-24 02:49:24 +00:00
|
|
|
#if defined(MAX_HEAP)
|
2015-03-20 13:53:54 +00:00
|
|
|
bool operator> (const Julia& q) const { return *this->x > *q.x; }
|
2016-09-24 02:49:24 +00:00
|
|
|
#else
|
|
|
|
bool operator> (const Julia& q) const { return *this->x < *q.x; }
|
|
|
|
#endif
|
2015-03-20 13:53:54 +00:00
|
|
|
int* x;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef QSE::BinaryHeap<Julia> JuliaHeap;
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
JuliaHeap jh;
|
|
|
|
qse_uint32_t x;
|
|
|
|
qse_ntime_t nt;
|
2016-09-24 02:49:24 +00:00
|
|
|
int oldval, newval;
|
2015-03-20 13:53:54 +00:00
|
|
|
|
|
|
|
qse_gettime (&nt);
|
|
|
|
|
|
|
|
x = nt.sec + nt.nsec;
|
|
|
|
|
2016-09-24 02:49:24 +00:00
|
|
|
for (int i = 0; i < 2500; i++)
|
2015-03-20 13:53:54 +00:00
|
|
|
{
|
2016-09-24 02:49:24 +00:00
|
|
|
//x = qse_rand31(x);
|
|
|
|
x = rand();
|
|
|
|
jh.insert (Julia((int)x % 1000));
|
2015-03-20 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2016-09-24 02:49:24 +00:00
|
|
|
#if defined(MAX_HEAP)
|
|
|
|
oldval = 9999999;
|
|
|
|
#else
|
|
|
|
oldval = 0;
|
|
|
|
#endif
|
2015-03-20 13:53:54 +00:00
|
|
|
while (!jh.isEmpty())
|
|
|
|
{
|
2016-09-24 02:49:24 +00:00
|
|
|
newval = *jh.getValueAt(0).x;
|
|
|
|
printf ("%d oldval => %d\n", newval, oldval);
|
|
|
|
#if defined(MAX_HEAP)
|
|
|
|
QSE_ASSERT (newval <= oldval);
|
|
|
|
#else
|
|
|
|
QSE_ASSERT (newval >= oldval);
|
|
|
|
#endif
|
2015-03-20 13:53:54 +00:00
|
|
|
jh.remove (0);
|
2016-09-24 02:49:24 +00:00
|
|
|
oldval = newval;
|
2015-03-20 13:53:54 +00:00
|
|
|
}
|
2016-09-24 02:49:24 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-03-20 13:53:54 +00:00
|
|
|
}
|