STXXL
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
pager.h
Go to the documentation of this file.
1
/***************************************************************************
2
* include/stxxl/bits/containers/pager.h
3
*
4
* Part of the STXXL. See http://stxxl.sourceforge.net
5
*
6
* Copyright (C) 2002, 2003, 2006 Roman Dementiev <
[email protected]
>
7
* Copyright (C) 2011 Andreas Beckmann <
[email protected]
>
8
*
9
* Distributed under the Boost Software License, Version 1.0.
10
* (See accompanying file LICENSE_1_0.txt or copy at
11
* http://www.boost.org/LICENSE_1_0.txt)
12
**************************************************************************/
13
14
#ifndef STXXL_CONTAINERS_PAGER_HEADER
15
#define STXXL_CONTAINERS_PAGER_HEADER
16
17
#include <list>
18
#include <cassert>
19
20
#include <
stxxl/bits/noncopyable.h
>
21
#include <
stxxl/bits/common/rand.h
>
22
#include <
stxxl/bits/common/simple_vector.h
>
23
24
25
STXXL_BEGIN_NAMESPACE
26
27
//! \addtogroup stlcont_vector
28
//! \{
29
30
enum
pager_type
31
{
32
random
,
33
lru
34
};
35
36
//! Pager with \b random replacement strategy
37
template
<
unsigned
npages_>
38
class
random_pager
39
{
40
enum
{ n_pages = npages_ };
41
42
typedef
unsigned_type
size_type
;
43
44
size_type
num_pages
;
45
random_number<random_uniform_fast>
rnd
;
46
47
public
:
48
random_pager
(
size_type
num_pages = n_pages) : num_pages(num_pages) { }
49
size_type
kick
()
50
{
51
return
rnd(size());
52
}
53
54
void
hit
(
size_type
ipage)
55
{
56
STXXL_ASSERT
(ipage < size());
57
}
58
59
size_type
size
()
const
60
{
61
return
num_pages;
62
}
63
};
64
65
//! Pager with \b LRU replacement strategy
66
template
<
unsigned
npages_ = 0>
67
class
lru_pager
:
private
noncopyable
68
{
69
enum
{ n_pages = npages_ };
70
71
typedef
unsigned_type
size_type
;
72
typedef
std::list<size_type>
list_type
;
73
74
list_type
history
;
75
simple_vector<list_type::iterator>
history_entry
;
76
77
public
:
78
lru_pager
(
size_type
num_pages = n_pages) : history_entry(num_pages)
79
{
80
for
(
size_type
i = 0; i < size(); ++i)
81
history_entry[i] = history.insert(history.end(), i);
82
}
83
84
size_type
kick
()
85
{
86
return
history.back();
87
}
88
89
void
hit
(
size_type
ipage)
90
{
91
assert(ipage < size());
92
history.splice(history.begin(), history, history_entry[ipage]);
93
}
94
95
void
swap
(
lru_pager
& obj)
96
{
97
history.swap(obj.
history
);
98
history_entry.swap(obj.
history_entry
);
99
}
100
101
size_type
size
()
const
102
{
103
return
history_entry.size();
104
}
105
};
106
107
//! \}
108
109
STXXL_END_NAMESPACE
110
111
namespace
std {
112
113
template
<
unsigned
npages_>
114
void
swap(
stxxl::lru_pager<npages_>
& a,
115
stxxl::lru_pager<npages_>
& b)
116
{
117
a.
swap
(b);
118
}
119
120
}
// namespace std
121
122
#endif // !STXXL_CONTAINERS_PAGER_HEADER
123
// vim: et:ts=4:sw=4
STXXL_ASSERT
#define STXXL_ASSERT(condition)
Definition:
verbose.h:157
stxxl::lru_pager::kick
size_type kick()
Definition:
pager.h:84
stxxl::random_number< random_uniform_fast >
stxxl::random_pager::hit
void hit(size_type ipage)
Definition:
pager.h:54
stxxl::lru_pager::history
list_type history
Definition:
pager.h:74
stxxl::lru_pager::size_type
unsigned_type size_type
Definition:
pager.h:71
stxxl::lru
Definition:
pager.h:33
stxxl::random_pager::size
size_type size() const
Definition:
pager.h:59
stxxl::lru_pager::size
size_type size() const
Definition:
pager.h:101
stxxl::lru_pager::lru_pager
lru_pager(size_type num_pages=n_pages)
Definition:
pager.h:78
rand.h
stxxl::random_pager
Pager with random replacement strategy.
Definition:
pager.h:38
stxxl::random
Definition:
pager.h:32
stxxl::random_pager::random_pager
random_pager(size_type num_pages=n_pages)
Definition:
pager.h:48
stxxl::lru_pager::hit
void hit(size_type ipage)
Definition:
pager.h:89
stxxl::random_pager::kick
size_type kick()
Definition:
pager.h:49
simple_vector.h
stxxl::pager_type
pager_type
Definition:
pager.h:30
STXXL_BEGIN_NAMESPACE
#define STXXL_BEGIN_NAMESPACE
Definition:
namespace.h:16
stxxl::lru_pager::history_entry
simple_vector< list_type::iterator > history_entry
Definition:
pager.h:75
stxxl::random_pager::size_type
unsigned_type size_type
Definition:
pager.h:42
stxxl::lru_pager
Pager with LRU replacement strategy.
Definition:
pager.h:67
stxxl::simple_vector< list_type::iterator >
stxxl::lru_pager::swap
void swap(lru_pager &obj)
Definition:
pager.h:95
stxxl::unsigned_type
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
Definition:
types.h:67
noncopyable.h
stxxl::random_pager::num_pages
size_type num_pages
Definition:
pager.h:44
stxxl::lru_pager::list_type
std::list< size_type > list_type
Definition:
pager.h:72
stxxl::noncopyable
Definition:
noncopyable.h:33
stxxl::random_pager::rnd
random_number< random_uniform_fast > rnd
Definition:
pager.h:45
STXXL_END_NAMESPACE
#define STXXL_END_NAMESPACE
Definition:
namespace.h:17
include
stxxl
bits
containers
pager.h
STXXL 1.4.0
- Generated on Thu Dec 12 2013 15:30:24 for STXXL by
1.8.5