• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

btree_pager.h

00001 /***************************************************************************
00002  *  include/stxxl/bits/containers/btree/btree_pager.h
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2006 Roman Dementiev <[email protected]>
00007  *
00008  *  Distributed under the Boost Software License, Version 1.0.
00009  *  (See accompanying file LICENSE_1_0.txt or copy at
00010  *  http://www.boost.org/LICENSE_1_0.txt)
00011  **************************************************************************/
00012 
00013 #ifndef STXXL_CONTAINERS_BTREE__BTREE_PAGER_H
00014 #define STXXL_CONTAINERS_BTREE__BTREE_PAGER_H
00015 
00016 #include <list>
00017 #include <vector>
00018 #include <cassert>
00019 
00020 #include <stxxl/bits/noncopyable.h>
00021 #include <stxxl/bits/common/types.h>
00022 #include <stxxl/bits/compat_unique_ptr.h>
00023 
00024 
00025 __STXXL_BEGIN_NAMESPACE
00026 
00027 namespace btree
00028 {
00029     class lru_pager : private noncopyable
00030     {
00031         unsigned_type npages_;
00032         typedef std::list<int_type> list_type;
00033 
00034         compat_unique_ptr<list_type>::result history;
00035         std::vector<list_type::iterator> history_entry;
00036 
00037     public:
00038         lru_pager() : npages_(0)
00039         { }
00040 
00041         lru_pager(unsigned_type npages) :
00042             npages_(npages),
00043             history(new list_type),
00044             history_entry(npages_, history->begin())
00045         {
00046             for (unsigned_type i = 0; i < npages_; i++)
00047             {
00048                 history_entry[i] = history->insert(history->end(), static_cast<int_type>(i));
00049             }
00050         }
00051         ~lru_pager() { }
00052         int_type kick()
00053         {
00054             return history->back();
00055         }
00056         void hit(int_type ipage)
00057         {
00058             assert(ipage < int_type(npages_));
00059             assert(ipage >= 0);
00060 #if defined(__GXX_EXPERIMENTAL_CXX0X__) && ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) == 40500)
00061             // HACK! Remove ASAP!
00062             // work around C++ Standard Library Issue http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#1133
00063             history->splice(history->begin(), std::move(*history), history_entry[ipage]);
00064 #else
00065             history->splice(history->begin(), *history, history_entry[ipage]);
00066 #endif
00067         }
00068         void swap(lru_pager & obj)
00069         {
00070             std::swap(npages_, obj.npages_);
00071             std::swap(history, obj.history);
00072             std::swap(history_entry, obj.history_entry);
00073         }
00074     };
00075 }
00076 
00077 __STXXL_END_NAMESPACE
00078 
00079 
00080 namespace std
00081 {
00082     inline void swap(stxxl::btree::lru_pager & a,
00083                      stxxl::btree::lru_pager & b)
00084     {
00085         a.swap(b);
00086     }
00087 }
00088 
00089 #endif /* STXXL_CONTAINERS_BTREE__BTREE_PAGER_H */

Generated by  doxygen 1.7.1