Commit d6b292eb by lucapegolotti

Fix style of sequential_data_structures.h

parent d6a1458a
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace lt{ namespace lt{
namespace state{ namespace state{
class Set class Set
{ {
public: public:
typedef char Value; typedef char Value;
typedef bool Ret; typedef bool Ret;
...@@ -35,7 +35,7 @@ class Set ...@@ -35,7 +35,7 @@ class Set
bool ret = set.is_empty(); bool ret = set.is_empty();
return{ ret == empty_ret.ret, set }; return{ ret == empty_ret.ret, set };
} }
}; };
struct ContainsCallOp : public internal::ArgOp<Set, Value, s_contains_op_name> struct ContainsCallOp : public internal::ArgOp<Set, Value, s_contains_op_name>
{ {
...@@ -150,28 +150,27 @@ class Set ...@@ -150,28 +150,27 @@ class Set
{ {
return m_bitset != set.m_bitset; return m_bitset != set.m_bitset;
} }
}; };
constexpr char Set::s_empty_op_name[]; constexpr char Set::s_empty_op_name[];
constexpr char Set::s_contains_op_name[]; constexpr char Set::s_contains_op_name[];
constexpr char Set::s_insert_op_name[]; constexpr char Set::s_insert_op_name[];
constexpr char Set::s_erase_op_name[]; constexpr char Set::s_erase_op_name[];
template<> template<>
struct Hash<Set> struct Hash<Set>
{ {
std::size_t operator()(const Set& set) const noexcept std::size_t operator()(const Set& set) const noexcept
{ {
return set.bitset().hash_code(); return set.bitset().hash_code();
} }
}; };
/// Bounded stack
/// N - stack capacity /// Bounded stack
template<std::size_t N> /// N - stack capacity
class Stack template<std::size_t N>
{ class Stack
{
public: public:
typedef char Value; typedef char Value;
...@@ -488,14 +487,29 @@ class Set ...@@ -488,14 +487,29 @@ class Set
// \see_also http://en.cppreference.com/w/cpp/types/size_t // \see_also http://en.cppreference.com/w/cpp/types/size_t
return reinterpret_cast<uintptr_t>(m_curr); return reinterpret_cast<uintptr_t>(m_curr);
} }
}; };
/// Bounded queue template<std::size_t N>
constexpr char Stack<N>::s_try_push_op_name[];
/// N - queue capacity template<std::size_t N>
template<std::size_t N> constexpr char Stack<N>::s_try_pop_op_name[];
class Queue
{ template<std::size_t N>
struct Hash<Stack<N>>
{
std::size_t operator()(const Stack<N>& stack) const noexcept
{
return stack.hash_code();
}
};
/// Bounded queue
/// N - queue capacity
template<std::size_t N>
class Queue
{
public: public:
typedef char Value; typedef char Value;
...@@ -550,12 +564,12 @@ class Set ...@@ -550,12 +564,12 @@ class Set
return m_value; return m_value;
} }
#ifdef _LT_DEBUG_ #ifdef _LT_DEBUG_
std::ostream& print(std::ostream& os) const override std::ostream& print(std::ostream& os) const override
{ {
return os << "ret: [ok: " << ok() << ", value: " << (ok() ? std::to_string(value()) : "undefined") << "]"; return os << "ret: [ok: " << ok() << ", value: " << (ok() ? std::to_string(value()) : "undefined") << "]";
} }
#endif #endif
}; };
struct TryDequeueCallOp : public internal::ZeroArgOp<Queue<N>, s_try_dequeue_op_name> struct TryDequeueCallOp : public internal::ZeroArgOp<Queue<N>, s_try_dequeue_op_name>
...@@ -620,7 +634,6 @@ class Set ...@@ -620,7 +634,6 @@ class Set
if (m_next != nullptr) { if (m_next != nullptr) {
m_next->m_prev = nullptr; m_next->m_prev = nullptr;
} }
} }
Node(const Node&) = delete; Node(const Node&) = delete;
...@@ -640,6 +653,7 @@ class Set ...@@ -640,6 +653,7 @@ class Set
m_next{ next }, m_next{ next },
m_ref_counter{ 0U }, m_ref_counter{ 0U },
m_nexts_num{ 0U } { m_nexts_num{ 0U } {
if (prev != nullptr) { if (prev != nullptr) {
prev->m_ref_counter++; prev->m_ref_counter++;
} }
...@@ -650,11 +664,6 @@ class Set ...@@ -650,11 +664,6 @@ class Set
NodePtr update_next(Value value) NodePtr update_next(Value value)
{ {
/*
if (m_nexts_num > 0 && m_next != nullptr) {
m_next->m_ref_counter--;
}
*/
NodePtr node_ptr = new Node(value, this, nullptr); NodePtr node_ptr = new Node(value, this, nullptr);
m_next = node_ptr; m_next = node_ptr;
node_ptr->m_ref_counter++; node_ptr->m_ref_counter++;
...@@ -732,7 +741,6 @@ class Set ...@@ -732,7 +741,6 @@ class Set
// Decrement reference counter of head and tail, delete them if necessary // Decrement reference counter of head and tail, delete them if necessary
void dec_ref_counter() const void dec_ref_counter() const
{ {
NodePtr curNode = m_head; NodePtr curNode = m_head;
NodePtr aux = nullptr; NodePtr aux = nullptr;
...@@ -762,16 +770,9 @@ class Set ...@@ -762,16 +770,9 @@ class Set
curNode = curNode->prev(); curNode = curNode->prev();
if (curNode != nullptr) { if (curNode != nullptr) {
/*if (curNode->next() != aux) {
if (aux->m_ref_counter == 1) {
break;
}
}*/
--curNode->m_ref_counter; --curNode->m_ref_counter;
} }
delete aux; delete aux;
} }
} }
...@@ -806,8 +807,6 @@ class Set ...@@ -806,8 +807,6 @@ class Set
return find_next(m_head); return find_next(m_head);
} }
public: public:
~Queue() ~Queue()
...@@ -931,38 +930,23 @@ class Set ...@@ -931,38 +930,23 @@ class Set
// \see_also http://en.cppreference.com/w/cpp/types/size_t // \see_also http://en.cppreference.com/w/cpp/types/size_t
return reinterpret_cast<uintptr_t>(m_head); return reinterpret_cast<uintptr_t>(m_head);
} }
}; };
template<std::size_t N>
constexpr char Stack<N>::s_try_push_op_name[];
template<std::size_t N>
constexpr char Stack<N>::s_try_pop_op_name[];
template<std::size_t N>
struct Hash<Stack<N>>
{
std::size_t operator()(const Stack<N>& stack) const noexcept
{
return stack.hash_code();
}
};
template<std::size_t N> template<std::size_t N>
constexpr char Queue<N>::s_try_enqueue_op_name[]; constexpr char Queue<N>::s_try_enqueue_op_name[];
template<std::size_t N> template<std::size_t N>
constexpr char Queue<N>::s_try_dequeue_op_name[]; constexpr char Queue<N>::s_try_dequeue_op_name[];
template<std::size_t N> template<std::size_t N>
struct Hash<Queue<N>> struct Hash<Queue<N>>
{ {
std::size_t operator()(const Queue<N>& queue) const noexcept std::size_t operator()(const Queue<N>& queue) const noexcept
{ {
return queue.hash_code(); return queue.hash_code();
}
};
}
} }
};
} // state
} // lt
#endif #endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment