"Fossies" - the Fresh Open Source Software Archive

Member "tcpflow-1.6.1/src/intrusive_list.h" (19 Feb 2021, 1179 Bytes) of package /linux/misc/tcpflow-1.6.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "intrusive_list.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef INTRUSIVE_LIST_H
    2 #define INTRUSIVE_LIST_H
    3 
    4 #include <iostream>
    5 #include <list>
    6 
    7 // implement boost::intrusive::list using std::list
    8 
    9 template <class T>
   10 class intrusive_list {
   11   public:
   12   intrusive_list():li(), len(0) {}
   13   
   14   typedef typename std::list<T*>::iterator iterator;
   15   
   16   inline void push_back(T* node) {
   17     li.push_back(node);
   18     len++;
   19     node->it = --li.end();
   20   }
   21 
   22   inline void erase(T* node) {
   23     if (!is_linked(node))
   24       return;
   25     li.erase(node->it);
   26     len--;
   27     reset(node);
   28   }
   29   
   30   inline void move_to_end(T* node) {
   31     if (!is_linked(node))
   32       return;
   33     li.splice(li.end(), li, node->it);
   34   }
   35   
   36   inline void reset(T* node) {
   37     node->it = li.end();
   38   }
   39   
   40   inline bool empty() {
   41     return li.empty();
   42   }
   43   
   44   inline size_t size() {
   45     // std::list.size() is O(n) in some platform. Is there any define flag for that?
   46     //return li.size();
   47     return len;
   48   }
   49   
   50   inline iterator begin() {
   51     return li.begin();
   52   }
   53   
   54   inline iterator end() {
   55     return li.end();
   56   }
   57   
   58   private:
   59   inline bool is_linked(T* node) {
   60     return node->it != li.end();
   61   }
   62   
   63   std::list<T*> li;
   64   size_t len;
   65 };
   66 
   67 #endif // INTRUSIVE_LIST_H