• 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 <memory>
00017 #include <list>
00018 
00019 #include <stxxl/bits/noncopyable.h>
00020 #include <stxxl/bits/common/utils.h>
00021 #include <stxxl/bits/compat_auto_ptr.h>
00022 
00023 
00024 __STXXL_BEGIN_NAMESPACE
00025 
00026 namespace btree
00027 {
00028     class lru_pager : private noncopyable
00029     {
00030         unsigned_type npages_;
00031         typedef std::list<int_type> list_type;
00032 
00033         compat_auto_ptr<list_type>::result history;
00034         std::vector<list_type::iterator> history_entry;
00035 
00036     public:
00037         lru_pager() : npages_(0)
00038         { }
00039 
00040         lru_pager(unsigned_type npages) :
00041             npages_(npages),
00042             history(new list_type),
00043             history_entry(npages_)
00044         {
00045             for (unsigned_type i = 0; i < npages_; i++)
00046             {
00047                 history_entry[i] = history->insert(history->end(), static_cast<int_type>(i));
00048             }
00049         }
00050         ~lru_pager() { }
00051         int_type kick()
00052         {
00053             return history->back();
00054         }
00055         void hit(int_type ipage)
00056         {
00057             assert(ipage < int_type(npages_));
00058             assert(ipage >= 0);
00059             history->splice(history->begin(), *history, history_entry[ipage]);
00060         }
00061         void swap(lru_pager & obj)
00062         {
00063             std::swap(npages_, obj.npages_);
00064             // workaround for buggy GCC 3.4 STL
00065             //std::swap(history,obj.history);
00066             compat_auto_ptr<list_type>::result tmp = obj.history;
00067             obj.history = history;
00068             history = tmp;
00069             std::swap(history_entry, obj.history_entry);
00070         }
00071     };
00072 }
00073 
00074 __STXXL_END_NAMESPACE
00075 
00076 
00077 namespace std
00078 {
00079     inline void swap(stxxl::btree::lru_pager & a,
00080                      stxxl::btree::lru_pager & b)
00081     {
00082         a.swap(b);
00083     }
00084 }
00085 
00086 #endif /* STXXL_CONTAINERS_BTREE__BTREE_PAGER_H */

Generated by  doxygen 1.7.1