123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- #ifndef BOOST_INTRUSIVE_LINEAR_SLIST_ALGORITHMS_HPP
- #define BOOST_INTRUSIVE_LINEAR_SLIST_ALGORITHMS_HPP
- #include <boost/intrusive/detail/config_begin.hpp>
- #include <boost/intrusive/intrusive_fwd.hpp>
- #include <boost/intrusive/detail/common_slist_algorithms.hpp>
- #include <boost/intrusive/detail/algo_type.hpp>
- #include <cstddef>
- #include <boost/intrusive/detail/twin.hpp>
- #if defined(BOOST_HAS_PRAGMA_ONCE)
- # pragma once
- #endif
- namespace boost {
- namespace intrusive {
- template<class NodeTraits>
- class linear_slist_algorithms
-
- : public detail::common_slist_algorithms<NodeTraits>
-
- {
-
- typedef detail::common_slist_algorithms<NodeTraits> base_t;
-
- public:
- typedef typename NodeTraits::node node;
- typedef typename NodeTraits::node_ptr node_ptr;
- typedef typename NodeTraits::const_node_ptr const_node_ptr;
- typedef NodeTraits node_traits;
-
-
-
-
-
- typedef twin<node_ptr> node_pair;
- #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
-
-
-
-
-
-
-
- static void init(node_ptr this_node) BOOST_NOEXCEPT;
-
-
-
-
-
-
-
-
-
- static bool unique(const_node_ptr this_node) BOOST_NOEXCEPT;
-
-
-
-
-
-
- static bool inited(const_node_ptr this_node) BOOST_NOEXCEPT;
-
-
-
-
-
-
-
- static void unlink_after(node_ptr prev_node) BOOST_NOEXCEPT;
-
-
-
-
-
-
-
-
- static void unlink_after(node_ptr prev_node, node_ptr last_node) BOOST_NOEXCEPT;
-
-
-
-
-
-
-
- static void link_after(node_ptr prev_node, node_ptr this_node) BOOST_NOEXCEPT;
-
-
-
-
-
-
-
-
-
- static void transfer_after(node_ptr p, node_ptr b, node_ptr e) BOOST_NOEXCEPT;
- #else
- using base_t::transfer_after;
- #endif
-
-
-
-
-
-
-
- inline static void init_header(node_ptr this_node) BOOST_NOEXCEPT
- { NodeTraits::set_next(this_node, node_ptr()); }
-
-
-
-
-
-
-
- inline static node_ptr end_node(const_node_ptr) BOOST_NOEXCEPT
- { return node_ptr(); }
-
-
-
-
-
- inline static bool is_empty(const_node_ptr this_node) BOOST_NOEXCEPT
- { return !NodeTraits::get_next(this_node); }
-
-
-
-
-
- inline static bool is_sentinel(const_node_ptr this_node) BOOST_NOEXCEPT
- { return NodeTraits::get_next(this_node) == this_node; }
-
-
-
-
-
-
- inline static void set_sentinel(node_ptr this_node) BOOST_NOEXCEPT
- { NodeTraits::set_next(this_node, this_node); }
-
-
-
-
-
-
-
-
-
- inline static node_ptr
- get_previous_node(node_ptr prev_init_node, node_ptr this_node) BOOST_NOEXCEPT
- { return base_t::get_previous_node(prev_init_node, this_node); }
-
-
-
-
-
-
-
-
- static std::size_t count(const_node_ptr this_node) BOOST_NOEXCEPT
- {
- std::size_t result = 0;
- const_node_ptr p = this_node;
- do{
- p = NodeTraits::get_next(p);
- ++result;
- } while (p);
- return result;
- }
-
-
-
-
-
-
-
-
-
- inline static void swap_trailing_nodes(node_ptr this_node, node_ptr other_node) BOOST_NOEXCEPT
- {
- node_ptr this_nxt = NodeTraits::get_next(this_node);
- node_ptr other_nxt = NodeTraits::get_next(other_node);
- NodeTraits::set_next(this_node, other_nxt);
- NodeTraits::set_next(other_node, this_nxt);
- }
-
-
-
-
-
-
-
- static node_ptr reverse(node_ptr p) BOOST_NOEXCEPT
- {
- if(!p) return node_ptr();
- node_ptr i = NodeTraits::get_next(p);
- node_ptr first(p);
- while(i){
- node_ptr nxti(NodeTraits::get_next(i));
- base_t::unlink_after(p);
- NodeTraits::set_next(i, first);
- first = i;
- i = nxti;
- }
- return first;
- }
-
-
-
-
-
-
-
-
- static node_pair move_first_n_backwards(node_ptr p, std::size_t n) BOOST_NOEXCEPT
- {
- node_pair ret;
-
- if(!n || !p || !NodeTraits::get_next(p)){
- return ret;
- }
- node_ptr first = p;
- bool end_found = false;
- node_ptr new_last = node_ptr();
- node_ptr old_last = node_ptr();
-
-
-
-
- for(std::size_t i = 1; i <= n; ++i){
- new_last = first;
- first = NodeTraits::get_next(first);
- if(first == node_ptr()){
-
- n %= i;
- if(!n) return ret;
- old_last = new_last;
- i = 0;
-
- first = p;
-
- end_found = true;
- }
- }
-
-
- if(!end_found){
- old_last = base_t::get_previous_node(first, node_ptr());
- }
-
- NodeTraits::set_next(old_last, p);
- NodeTraits::set_next(new_last, node_ptr());
- ret.first = first;
- ret.second = new_last;
- return ret;
- }
-
-
-
-
-
-
-
-
- static node_pair move_first_n_forward(node_ptr p, std::size_t n) BOOST_NOEXCEPT
- {
- node_pair ret;
-
- if(!n || !p || !NodeTraits::get_next(p))
- return ret;
- node_ptr first = p;
-
-
-
- node_ptr old_last(first), next_to_it, new_last(p);
- std::size_t distance = 1;
- while(!!(next_to_it = node_traits::get_next(old_last))){
- if(distance++ > n)
- new_last = node_traits::get_next(new_last);
- old_last = next_to_it;
- }
-
-
- if(distance <= n){
-
-
- std::size_t new_before_last_pos = (distance - (n % distance))% distance;
-
- if(!new_before_last_pos)
- return ret;
- for( new_last = p
- ; --new_before_last_pos
- ; new_last = node_traits::get_next(new_last)){
-
- }
- }
-
- node_ptr new_first(node_traits::get_next(new_last));
-
- NodeTraits::set_next(old_last, p);
- NodeTraits::set_next(new_last, node_ptr());
- ret.first = new_first;
- ret.second = new_last;
- return ret;
- }
-
-
-
-
-
-
-
- static void transfer_after(node_ptr p, node_ptr other) BOOST_NOEXCEPT
- {
- if ((is_empty)(p)) {
- (swap_trailing_nodes)(p, other);
- }
- else {
- node_ptr other_last((get_previous_node)(other, node_ptr()));
- base_t::transfer_after(p, other, other_last);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Disposer>
- inline static std::size_t detach_and_dispose(node_ptr p, Disposer disposer) BOOST_NOEXCEPT
- { return base_t::unlink_after_and_dispose(p, node_ptr(), disposer); }
- };
- template<class NodeTraits>
- struct get_algo<LinearSListAlgorithms, NodeTraits>
- {
- typedef linear_slist_algorithms<NodeTraits> type;
- };
- }
- }
- #include <boost/intrusive/detail/config_end.hpp>
- #endif
|