STXXL
1.4-dev
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
STXXL_BEGIN_NAMESPACE
25
26
//! \addtogroup stlcont_vector
27
//! \{
28
29
enum
pager_type
30
{
31
random
,
32
lru
33
};
34
35
//! Pager with \b random replacement strategy
36
template
<
unsigned
npages_>
37
class
random_pager
38
{
39
enum
{ n_pages = npages_ };
40
41
typedef
unsigned_type
size_type
;
42
43
size_type
num_pages
;
44
random_number<random_uniform_fast>
rnd
;
45
46
public
:
47
random_pager
(
size_type
num_pages = n_pages) : num_pages(num_pages) { }
48
size_type
kick
()
49
{
50
return
rnd(size());
51
}
52
53
void
hit
(
size_type
ipage)
54
{
55
STXXL_ASSERT
(ipage < size());
56
}
57
58
size_type
size
()
const
59
{
60
return
num_pages;
61
}
62
};
63
64
//! Pager with \b LRU replacement strategy
65
template
<
unsigned
npages_ = 0>
66
class
lru_pager
:
private
noncopyable
67
{
68
enum
{ n_pages = npages_ };
69
70
typedef
unsigned_type
size_type
;
71
typedef
std::list<size_type>
list_type
;
72
73
list_type
history
;
74
simple_vector<list_type::iterator>
history_entry
;
75
76
public
:
77
lru_pager
(
size_type
num_pages = n_pages) : history_entry(num_pages)
78
{
79
for
(
size_type
i = 0; i < size(); ++i)
80
history_entry[i] = history.insert(history.end(), i);
81
}
82
83
size_type
kick
()
84
{
85
return
history.back();
86
}
87
88
void
hit
(
size_type
ipage)
89
{
90
assert(ipage < size());
91
history.splice(history.begin(), history, history_entry[ipage]);
92
}
93
94
void
swap
(
lru_pager
& obj)
95
{
96
history.swap(obj.
history
);
97
history_entry.swap(obj.
history_entry
);
98
}
99
100
size_type
size
()
const
101
{
102
return
history_entry.size();
103
}
104
};
105
106
//! \}
107
108
STXXL_END_NAMESPACE
109
110
namespace
std {
111
112
template
<
unsigned
npages_>
113
void
swap(
stxxl::lru_pager<npages_>
& a,
114
stxxl::lru_pager<npages_>
& b)
115
{
116
a.
swap
(b);
117
}
118
119
}
// namespace std
120
121
#endif // !STXXL_CONTAINERS_PAGER_HEADER
122
// vim: et:ts=4:sw=4
STXXL_ASSERT
#define STXXL_ASSERT(condition)
Definition:
verbose.h:220
stxxl::lru_pager::kick
size_type kick()
Definition:
pager.h:83
stxxl::random_number< random_uniform_fast >
stxxl::random_pager::hit
void hit(size_type ipage)
Definition:
pager.h:53
stxxl::lru_pager::history
list_type history
Definition:
pager.h:73
stxxl::lru_pager::size_type
unsigned_type size_type
Definition:
pager.h:70
stxxl::lru
Definition:
pager.h:32
stxxl::random_pager::size
size_type size() const
Definition:
pager.h:58
stxxl::lru_pager::size
size_type size() const
Definition:
pager.h:100
stxxl::lru_pager::lru_pager
lru_pager(size_type num_pages=n_pages)
Definition:
pager.h:77
rand.h
stxxl::random_pager
Pager with random replacement strategy.
Definition:
pager.h:37
stxxl::random
Definition:
pager.h:31
stxxl::random_pager::random_pager
random_pager(size_type num_pages=n_pages)
Definition:
pager.h:47
stxxl::lru_pager::hit
void hit(size_type ipage)
Definition:
pager.h:88
stxxl::random_pager::kick
size_type kick()
Definition:
pager.h:48
simple_vector.h
stxxl::pager_type
pager_type
Definition:
pager.h:29
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:74
stxxl::random_pager::size_type
unsigned_type size_type
Definition:
pager.h:41
stxxl::lru_pager
Pager with LRU replacement strategy.
Definition:
pager.h:66
stxxl::simple_vector< list_type::iterator >
stxxl::lru_pager::swap
void swap(lru_pager &obj)
Definition:
pager.h:94
stxxl::unsigned_type
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
Definition:
types.h:64
noncopyable.h
stxxl::random_pager::num_pages
size_type num_pages
Definition:
pager.h:43
stxxl::lru_pager::list_type
std::list< size_type > list_type
Definition:
pager.h:71
stxxl::noncopyable
Definition:
noncopyable.h:33
stxxl::random_pager::rnd
random_number< random_uniform_fast > rnd
Definition:
pager.h:44
STXXL_END_NAMESPACE
#define STXXL_END_NAMESPACE
Definition:
namespace.h:17
include
stxxl
bits
containers
pager.h
STXXL 1.4.1-382-g263df0c
- Generated on Wed Sep 27 2017 06:25:34 for STXXL by
1.8.5