/usr/include/stxxl/bits/containers/pager.h is in libstxxl-dev 1.3.1-5ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | /***************************************************************************
* include/stxxl/bits/containers/pager.h
*
* Part of the STXXL. See http://stxxl.sourceforge.net
*
* Copyright (C) 2002, 2003, 2006 Roman Dementiev <dementiev@ira.uka.de>
* Copyright (C) 2011 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
**************************************************************************/
#ifndef STXXL_PAGER_HEADER
#define STXXL_PAGER_HEADER
#include <list>
#include <cassert>
#include <stxxl/bits/noncopyable.h>
#include <stxxl/bits/common/rand.h>
#include <stxxl/bits/common/simple_vector.h>
__STXXL_BEGIN_NAMESPACE
//! \addtogroup stlcontinternals
//! \{
enum pager_type
{
random,
lru
};
//! \brief Pager with \b random replacement strategy
template <unsigned npages_>
class random_pager
{
random_number<random_uniform_fast> rnd;
public:
enum { n_pages = npages_ };
random_pager() { }
int_type kick()
{
return rnd(npages_);
}
void hit(int_type ipage)
{
assert(ipage < int_type(npages_));
assert(ipage >= 0);
}
};
//! \brief Pager with \b LRU replacement strategy
template <unsigned npages_ = 0>
class lru_pager : private noncopyable
{
typedef unsigned_type size_type;
typedef std::list<size_type> list_type;
list_type history;
simple_vector<list_type::iterator> history_entry;
public:
enum { n_pages = npages_ };
lru_pager() : history_entry(n_pages)
{
for (size_type i = 0; i < n_pages; ++i)
history_entry[i] = history.insert(history.end(), i);
}
size_type kick()
{
return history.back();
}
void hit(size_type ipage)
{
assert(ipage < n_pages);
history.splice(history.begin(), history, history_entry[ipage]);
}
void swap(lru_pager & obj)
{
history.swap(obj.history);
history_entry.swap(obj.history_entry);
}
};
// specialization, size is specified at runtime
template <>
class lru_pager<0> : private noncopyable
{
typedef unsigned_type size_type;
typedef std::list<size_type> list_type;
size_type n_pages;
list_type history;
simple_vector<list_type::iterator> history_entry;
public:
lru_pager(size_type npages_ = 0) : n_pages(npages_), history_entry(n_pages)
{
for (size_type i = 0; i < n_pages; ++i)
history_entry[i] = history.insert(history.end(), i);
}
size_type kick()
{
return history.back();
}
void hit(size_type ipage)
{
assert(ipage < n_pages);
history.splice(history.begin(), history, history_entry[ipage]);
}
void swap(lru_pager & obj)
{
std::swap(n_pages, obj.n_pages);
history.swap(obj.history);
history_entry.swap(obj.history_entry);
}
};
//! \}
__STXXL_END_NAMESPACE
namespace std
{
template <unsigned npages_>
void swap(stxxl::lru_pager<npages_> & a,
stxxl::lru_pager<npages_> & b)
{
a.swap(b);
}
}
#endif // !STXXL_PAGER_HEADER
// vim: et:ts=4:sw=4
|