mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Initial updates and fixes
This commit is contained in:
parent
cfa39d9b4e
commit
c3c12da861
@ -91,6 +91,22 @@ namespace etl
|
||||
ID = ID_,
|
||||
};
|
||||
|
||||
forward_link()
|
||||
: etl_next(ETL_NULLPTR)
|
||||
{
|
||||
}
|
||||
|
||||
forward_link(const forward_link& other)
|
||||
: etl_next(other.etl_next)
|
||||
{
|
||||
}
|
||||
|
||||
forward_link& operator =(const forward_link& rhs)
|
||||
{
|
||||
etl_next = rhs.etl_next;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
etl_next = ETL_NULLPTR;
|
||||
@ -132,6 +148,38 @@ namespace etl
|
||||
}
|
||||
}
|
||||
|
||||
// Reference
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::forward_link<TLink::ID> >::value, void>::type
|
||||
link_clear(TLink& node)
|
||||
{
|
||||
node.clear();
|
||||
}
|
||||
|
||||
// Pointer
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::forward_link<TLink::ID> >::value, void>::type
|
||||
link_clear(TLink* node)
|
||||
{
|
||||
node->clear();
|
||||
}
|
||||
|
||||
// Reference
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::forward_link<TLink::ID> >::value, bool>::type
|
||||
link_is_linked(TLink& node)
|
||||
{
|
||||
return node.is_linked();
|
||||
}
|
||||
|
||||
// Pointer
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::forward_link<TLink::ID> >::value, bool>::type
|
||||
link_is_linked(TLink* node)
|
||||
{
|
||||
return node.is_linked();
|
||||
}
|
||||
|
||||
// Pointer, Pointer
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::forward_link<TLink::ID> >::value, void>::type
|
||||
@ -248,6 +296,25 @@ namespace etl
|
||||
ID = ID_,
|
||||
};
|
||||
|
||||
bidirectional_link()
|
||||
: etl_previous(ETL_NULLPTR)
|
||||
, etl_next(ETL_NULLPTR)
|
||||
{
|
||||
}
|
||||
|
||||
bidirectional_link(const bidirectional_link& other)
|
||||
: etl_previous(other.etl_previous)
|
||||
, etl_next(other.etl_next)
|
||||
{
|
||||
}
|
||||
|
||||
bidirectional_link& operator =(const bidirectional_link& rhs)
|
||||
{
|
||||
etl_previous = rhs.etl_previous;
|
||||
etl_next = rhs.etl_next;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
etl_previous = ETL_NULLPTR;
|
||||
@ -465,6 +532,38 @@ namespace etl
|
||||
}
|
||||
}
|
||||
|
||||
// Reference
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::bidirectional_link<TLink::ID> >::value, void>::type
|
||||
link_clear(TLink& node)
|
||||
{
|
||||
node.clear();
|
||||
}
|
||||
|
||||
// Pointer
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::bidirectional_link<TLink::ID> >::value, void>::type
|
||||
link_clear(TLink* node)
|
||||
{
|
||||
node->clear();
|
||||
}
|
||||
|
||||
// Reference
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::bidirectional_link<TLink::ID> >::value, bool>::type
|
||||
link_is_linked(TLink& node)
|
||||
{
|
||||
return node.is_linked();
|
||||
}
|
||||
|
||||
// Pointer
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::bidirectional_link<TLink::ID> >::value, bool>::type
|
||||
link_is_linked(TLink* node)
|
||||
{
|
||||
return node.is_linked();
|
||||
}
|
||||
|
||||
// Reference
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::bidirectional_link<TLink::ID> >::value, void>::type
|
||||
@ -507,6 +606,28 @@ namespace etl
|
||||
ID = ID_,
|
||||
};
|
||||
|
||||
tree_link()
|
||||
: etl_parent(ETL_NULLPTR)
|
||||
, etl_left(ETL_NULLPTR)
|
||||
, etl_right(ETL_NULLPTR)
|
||||
{
|
||||
}
|
||||
|
||||
tree_link(const tree_link& other)
|
||||
: etl_parent(other.etl_parent)
|
||||
, etl_left(other.etl_left)
|
||||
, etl_right(other.etl_right)
|
||||
{
|
||||
}
|
||||
|
||||
tree_link& operator =(const tree_link& rhs)
|
||||
{
|
||||
etl_parent = other.etl_parent;
|
||||
etl_left = other.etl_left;
|
||||
etl_right = other.etl_right;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
etl_parent = ETL_NULLPTR;
|
||||
@ -790,6 +911,38 @@ namespace etl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reference
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
|
||||
link_clear(TLink& node)
|
||||
{
|
||||
node.clear();
|
||||
}
|
||||
|
||||
// Pointer
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
|
||||
link_clear(TLink* node)
|
||||
{
|
||||
node->clear();
|
||||
}
|
||||
|
||||
// Reference
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, bool>::type
|
||||
link_is_linked(TLink& node)
|
||||
{
|
||||
return node.is_linked();
|
||||
}
|
||||
|
||||
// Pointer
|
||||
template <typename TLink>
|
||||
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, bool>::type
|
||||
link_is_linked(TLink* node)
|
||||
{
|
||||
return node.is_linked();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -87,7 +87,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push(link_type& value)
|
||||
{
|
||||
value.clear();
|
||||
//if (value.is_linked())
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (p_back != ETL_NULLPTR)
|
||||
{
|
||||
@ -113,7 +116,7 @@ namespace etl
|
||||
ETL_ASSERT(!empty(), ETL_ERROR(intrusive_queue_empty));
|
||||
#endif
|
||||
link_type* p_next = p_front->etl_next;
|
||||
|
||||
p_front->clear();
|
||||
p_front = p_next;
|
||||
|
||||
// Now empty?
|
||||
|
||||
@ -87,6 +87,11 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push(link_type& value)
|
||||
{
|
||||
//if (value.is_linked())
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
value.clear();
|
||||
|
||||
if (p_top != ETL_NULLPTR)
|
||||
|
||||
@ -35,10 +35,10 @@ SOFTWARE.
|
||||
|
||||
namespace
|
||||
{
|
||||
typedef etl::forward_link<0> link0;
|
||||
typedef etl::bidirectional_link<1> link1;
|
||||
typedef etl::forward_link<0> link_fwd;
|
||||
typedef etl::bidirectional_link<1> link_bdir;
|
||||
|
||||
struct Data : public link0, public link1
|
||||
struct Data : public link_fwd, public link_bdir
|
||||
{
|
||||
Data(int i_)
|
||||
: i(i_)
|
||||
@ -70,8 +70,8 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_constructor)
|
||||
{
|
||||
etl::intrusive_queue<Data, link0> queueD;
|
||||
etl::intrusive_queue<Data, link1> queueC;
|
||||
etl::intrusive_queue<Data, link_fwd> queueD;
|
||||
etl::intrusive_queue<Data, link_bdir> queueC;
|
||||
|
||||
CHECK(queueD.empty());
|
||||
CHECK(queueC.empty());
|
||||
@ -83,8 +83,8 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_empty)
|
||||
{
|
||||
etl::intrusive_queue<Data, link0> queueD;
|
||||
etl::intrusive_queue<Data, link1> queueC;
|
||||
etl::intrusive_queue<Data, link_fwd> queueD;
|
||||
etl::intrusive_queue<Data, link_bdir> queueC;
|
||||
|
||||
Data data1(1);
|
||||
Data data2(2);
|
||||
@ -106,8 +106,8 @@ namespace
|
||||
Data data2(2);
|
||||
Data data3(3);
|
||||
|
||||
etl::intrusive_queue<Data, link0> queueD;
|
||||
etl::intrusive_queue<Data, link1> queueC;
|
||||
etl::intrusive_queue<Data, link_fwd> queueD;
|
||||
etl::intrusive_queue<Data, link_bdir> queueC;
|
||||
|
||||
queueD.push(data1);
|
||||
queueD.push(data2);
|
||||
@ -127,8 +127,8 @@ namespace
|
||||
Data data2(2);
|
||||
Data data3(3);
|
||||
|
||||
etl::intrusive_queue<Data, link0> queueD;
|
||||
etl::intrusive_queue<Data, link1> queueC;
|
||||
etl::intrusive_queue<Data, link_fwd> queueD;
|
||||
etl::intrusive_queue<Data, link_bdir> queueC;
|
||||
|
||||
queueD.push(data1);
|
||||
queueD.push(data2);
|
||||
@ -151,8 +151,8 @@ namespace
|
||||
Data data2(2);
|
||||
Data data3(3);
|
||||
|
||||
etl::intrusive_queue<Data, link0> queueD;
|
||||
etl::intrusive_queue<Data, link1> queueC;
|
||||
etl::intrusive_queue<Data, link_fwd> queueD;
|
||||
etl::intrusive_queue<Data, link_bdir> queueC;
|
||||
|
||||
queueD.push(data1);
|
||||
CHECK_EQUAL(queueD.front(), data1);
|
||||
@ -175,6 +175,48 @@ namespace
|
||||
CHECK_EQUAL(queueC.back(), data2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_double_push)
|
||||
{
|
||||
Data data1(1);
|
||||
Data data2(2);
|
||||
Data data3(3);
|
||||
Data data4(4);
|
||||
|
||||
etl::intrusive_queue<Data, link_fwd> queue;
|
||||
|
||||
queue.push(data1);
|
||||
CHECK(data1.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK(data2.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK(data3.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK(data4.link_fwd::etl_next == ETL_NULLPTR);
|
||||
|
||||
queue.push(data2);
|
||||
CHECK(data1.link_fwd::etl_next == &data2);
|
||||
CHECK(data2.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK(data3.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK(data4.link_fwd::etl_next == ETL_NULLPTR);
|
||||
|
||||
queue.push(data3);
|
||||
CHECK(data1.link_fwd::etl_next == &data2);
|
||||
CHECK(data2.link_fwd::etl_next == &data3);
|
||||
CHECK(data3.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK(data4.link_fwd::etl_next == ETL_NULLPTR);
|
||||
|
||||
queue.push(data2);
|
||||
CHECK(data1.link_fwd::etl_next == &data2);
|
||||
CHECK(data2.link_fwd::etl_next == &data3);
|
||||
CHECK(data3.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK(data4.link_fwd::etl_next == ETL_NULLPTR);
|
||||
|
||||
queue.push(data4);
|
||||
CHECK(data1.link_fwd::etl_next == &data2);
|
||||
CHECK(data2.link_fwd::etl_next == &data3);
|
||||
CHECK(data3.link_fwd::etl_next == &data4);
|
||||
CHECK(data4.link_fwd::etl_next == ETL_NULLPTR);
|
||||
|
||||
CHECK_EQUAL(4, queue.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pop)
|
||||
@ -183,8 +225,8 @@ namespace
|
||||
Data data2(2);
|
||||
Data data3(3);
|
||||
|
||||
etl::intrusive_queue<Data, link0> queueD;
|
||||
etl::intrusive_queue<Data, link1> queueC;
|
||||
etl::intrusive_queue<Data, link_fwd> queueD;
|
||||
etl::intrusive_queue<Data, link_bdir> queueC;
|
||||
|
||||
queueD.push(data1);
|
||||
queueD.push(data2);
|
||||
@ -220,8 +262,8 @@ namespace
|
||||
Data data2(2);
|
||||
Data data3(3);
|
||||
|
||||
etl::intrusive_queue<Data, link0> queue1;
|
||||
etl::intrusive_queue<Data, link0> queue2;
|
||||
etl::intrusive_queue<Data, link_fwd> queue1;
|
||||
etl::intrusive_queue<Data, link_fwd> queue2;
|
||||
|
||||
queue1.push(data1);
|
||||
queue1.push(data2);
|
||||
@ -251,6 +293,70 @@ namespace
|
||||
CHECK_EQUAL(data3, queue2.back());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pop_forward_link_clear)
|
||||
{
|
||||
Data data1(1);
|
||||
Data data2(2);
|
||||
Data data3(3);
|
||||
|
||||
etl::intrusive_queue<Data, link_fwd> queue;
|
||||
|
||||
queue.push(data1);
|
||||
queue.push(data2);
|
||||
queue.push(data3);
|
||||
CHECK_TRUE(data1.link_fwd::etl_next != ETL_NULLPTR);
|
||||
CHECK_TRUE(data2.link_fwd::etl_next != ETL_NULLPTR);
|
||||
CHECK_TRUE(data3.link_fwd::etl_next == ETL_NULLPTR);
|
||||
|
||||
queue.pop();
|
||||
CHECK_TRUE(data1.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK_TRUE(data2.link_fwd::etl_next != ETL_NULLPTR);
|
||||
CHECK_TRUE(data3.link_fwd::etl_next == ETL_NULLPTR);
|
||||
|
||||
queue.pop();
|
||||
CHECK_TRUE(data1.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK_TRUE(data2.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK_TRUE(data3.link_fwd::etl_next == ETL_NULLPTR);
|
||||
|
||||
queue.pop();
|
||||
CHECK_TRUE(data1.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK_TRUE(data2.link_fwd::etl_next == ETL_NULLPTR);
|
||||
CHECK_TRUE(data3.link_fwd::etl_next == ETL_NULLPTR);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pop_bidirectional_link_clear)
|
||||
{
|
||||
Data data1(1);
|
||||
Data data2(2);
|
||||
Data data3(3);
|
||||
|
||||
etl::intrusive_queue<Data, link_bdir> queue;
|
||||
|
||||
queue.push(data1);
|
||||
queue.push(data2);
|
||||
queue.push(data3);
|
||||
CHECK_TRUE(data1.link_bdir::etl_next != ETL_NULLPTR);
|
||||
CHECK_TRUE(data2.link_bdir::etl_next != ETL_NULLPTR);
|
||||
CHECK_TRUE(data3.link_bdir::etl_next == ETL_NULLPTR);
|
||||
|
||||
queue.pop();
|
||||
CHECK_TRUE(data1.link_bdir::etl_next == ETL_NULLPTR);
|
||||
CHECK_TRUE(data2.link_bdir::etl_next != ETL_NULLPTR);
|
||||
CHECK_TRUE(data3.link_bdir::etl_next == ETL_NULLPTR);
|
||||
|
||||
queue.pop();
|
||||
CHECK_TRUE(data1.link_bdir::etl_next == ETL_NULLPTR);
|
||||
CHECK_TRUE(data2.link_bdir::etl_next == ETL_NULLPTR);
|
||||
CHECK_TRUE(data3.link_bdir::etl_next == ETL_NULLPTR);
|
||||
|
||||
queue.pop();
|
||||
CHECK_TRUE(data1.link_bdir::etl_next == ETL_NULLPTR);
|
||||
CHECK_TRUE(data2.link_bdir::etl_next == ETL_NULLPTR);
|
||||
CHECK_TRUE(data3.link_bdir::etl_next == ETL_NULLPTR);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_front_const)
|
||||
{
|
||||
@ -258,8 +364,8 @@ namespace
|
||||
Data data2(2);
|
||||
Data data3(3);
|
||||
|
||||
etl::intrusive_queue<Data, link0> queueD;
|
||||
const etl::intrusive_queue<Data, link0>& queueDR = queueD;
|
||||
etl::intrusive_queue<Data, link_fwd> queueD;
|
||||
const etl::intrusive_queue<Data, link_fwd>& queueDR = queueD;
|
||||
|
||||
queueD.push(data1);
|
||||
queueD.push(data2);
|
||||
@ -280,8 +386,8 @@ namespace
|
||||
Data data2(2);
|
||||
Data data3(3);
|
||||
|
||||
etl::intrusive_queue<Data, link0> queueD;
|
||||
const etl::intrusive_queue<Data, link0>& queueDR = queueD;
|
||||
etl::intrusive_queue<Data, link_fwd> queueD;
|
||||
const etl::intrusive_queue<Data, link_fwd>& queueDR = queueD;
|
||||
|
||||
queueD.push(data1);
|
||||
queueD.push(data2);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user