mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-12-22 22:48:53 +00:00
epee: allow copying a rolling_median_t object
This commit is contained in:
parent
f49fc9b487
commit
9f786f0550
@ -126,7 +126,6 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
rolling_median_t &operator=(const rolling_median_t&) = delete;
|
rolling_median_t &operator=(const rolling_median_t&) = delete;
|
||||||
rolling_median_t(const rolling_median_t&) = delete;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//creates new rolling_median_t: to calculate `nItems` running median.
|
//creates new rolling_median_t: to calculate `nItems` running median.
|
||||||
@ -139,6 +138,20 @@ public:
|
|||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rolling_median_t(const rolling_median_t &other)
|
||||||
|
{
|
||||||
|
N = other.N;
|
||||||
|
int size = N * (sizeof(Item) + sizeof(int) * 2);
|
||||||
|
data = (Item*)malloc(size);
|
||||||
|
memcpy(data, other.data, size);
|
||||||
|
pos = (int*) (data + N);
|
||||||
|
heap = pos + N + (N / 2); //points to middle of storage.
|
||||||
|
idx = other.idx;
|
||||||
|
minCt = other.minCt;
|
||||||
|
maxCt = other.maxCt;
|
||||||
|
sz = other.sz;
|
||||||
|
}
|
||||||
|
|
||||||
rolling_median_t(rolling_median_t &&m)
|
rolling_median_t(rolling_median_t &&m)
|
||||||
{
|
{
|
||||||
memcpy(this, &m, sizeof(rolling_median_t));
|
memcpy(this, &m, sizeof(rolling_median_t));
|
||||||
|
@ -211,3 +211,21 @@ TEST(rolling_median, size)
|
|||||||
ASSERT_EQ(m.size(), std::min<int>(10, i + 2));
|
ASSERT_EQ(m.size(), std::min<int>(10, i + 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(rolling_median, copy)
|
||||||
|
{
|
||||||
|
epee::misc_utils::rolling_median_t<uint64_t> m(100);
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; ++i)
|
||||||
|
m.insert(rand());
|
||||||
|
|
||||||
|
epee::misc_utils::rolling_median_t<uint64_t> copy(m);
|
||||||
|
|
||||||
|
for (int i = 0; i < 5000; ++i)
|
||||||
|
{
|
||||||
|
uint64_t v = rand();
|
||||||
|
m.insert(v);
|
||||||
|
copy.insert(v);
|
||||||
|
ASSERT_EQ(m.median(), copy.median());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user