epoc32/include/stdapis/boost/multi_index/detail/hash_index_node.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /* Copyright 2003-2006 Joaquín M López Muñoz.
     2  * Distributed under the Boost Software License, Version 1.0.
     3  * (See accompanying file LICENSE_1_0.txt or copy at
     4  * http://www.boost.org/LICENSE_1_0.txt)
     5  *
     6  * See http://www.boost.org/libs/multi_index for library home page.
     7  */
     8 
     9 #ifndef BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_NODE_HPP
    10 #define BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_NODE_HPP
    11 
    12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
    13 #pragma once
    14 #endif
    15 
    16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
    17 #include <functional>
    18 
    19 namespace boost{
    20 
    21 namespace multi_index{
    22 
    23 namespace detail{
    24 
    25 /* singly-linked node for use by hashed_index */
    26 
    27 struct hashed_index_node_impl
    28 {
    29   hashed_index_node_impl*& next(){return next_;}
    30   hashed_index_node_impl*  next()const{return next_;}
    31 
    32   /* algorithmic stuff */
    33 
    34   static void increment(
    35     hashed_index_node_impl*& x,
    36     hashed_index_node_impl* bbegin,hashed_index_node_impl* bbend)
    37   {
    38     std::less_equal<hashed_index_node_impl*> leq;
    39 
    40     x=x->next();
    41     if(leq(bbegin,x)&&leq(x,bbend)){ /* bucket node */
    42       do{
    43         ++x;
    44       }while(x->next()==x);
    45       x=x->next();
    46     }
    47   }
    48 
    49   static void link(
    50     hashed_index_node_impl* x,hashed_index_node_impl* pos)
    51   {
    52     x->next()=pos->next();
    53     pos->next()=x;
    54   };
    55 
    56   static void unlink(hashed_index_node_impl* x)
    57   {
    58     hashed_index_node_impl* y=x->next();
    59     while(y->next()!=x){y=y->next();}
    60     y->next()=x->next();
    61   }
    62 
    63   static hashed_index_node_impl* prev(hashed_index_node_impl* x)
    64   {
    65     hashed_index_node_impl* y=x->next();
    66     while(y->next()!=x){y=y->next();}
    67     return y;
    68   }
    69 
    70   static void unlink_next(hashed_index_node_impl* x)
    71   {
    72     x->next()=x->next()->next();
    73   }
    74 
    75 private:
    76   hashed_index_node_impl* next_;
    77 };
    78 
    79 template<typename Super>
    80 struct hashed_index_node_trampoline:hashed_index_node_impl{};
    81 
    82 template<typename Super>
    83 struct hashed_index_node:Super,hashed_index_node_trampoline<Super>
    84 {
    85   hashed_index_node_impl*       impl()
    86     {return static_cast<impl_type*>(this);}
    87   const hashed_index_node_impl* impl()const
    88     {return static_cast<const impl_type*>(this);}
    89 
    90   static hashed_index_node* from_impl(hashed_index_node_impl *x)
    91     {return static_cast<hashed_index_node*>(static_cast<impl_type*>(x));}
    92   static const hashed_index_node* from_impl(const hashed_index_node_impl* x)
    93   {
    94     return static_cast<const hashed_index_node*>(
    95       static_cast<const impl_type*>(x));
    96   }
    97 
    98   static void increment(
    99     hashed_index_node*& x,
   100     hashed_index_node_impl* bbegin,hashed_index_node_impl* bend)
   101   {
   102     hashed_index_node_impl* xi=x->impl();
   103     impl_type::increment(xi,bbegin,bend);
   104     x=from_impl(xi);
   105   }
   106 
   107 private:
   108   typedef hashed_index_node_trampoline<Super> impl_type;
   109 };
   110 
   111 } /* namespace multi_index::detail */
   112 
   113 } /* namespace multi_index */
   114 
   115 } /* namespace boost */
   116 
   117 #endif