ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
CellHeap.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*---------------------------- File CellHeap.h -----------------------------*/
3
/*--------------------------------------------------------------------------*/
38
/*--------------------------------------------------------------------------*/
39
/*----------------------------- DEFINITIONS --------------------------------*/
40
/*--------------------------------------------------------------------------*/
41
42
#ifndef __ADS_CellHeap
43
#define __ADS_CellHeap
44
/* self-identification: #endif constant */
45
46
/*--------------------------------------------------------------------------*/
47
/*------------------------------ INCLUDES ----------------------------------*/
48
/*--------------------------------------------------------------------------*/
49
50
#include "
ADS/Contract.h
"
51
52
#include <cstddef>
53
#include <set>
54
#include <vector>
55
56
/*--------------------------------------------------------------------------*/
57
/*--------------------------- NAMESPACE ------------------------------------*/
58
/*--------------------------------------------------------------------------*/
59
60
namespace
ADS
61
{
62
63
/*--------------------------------------------------------------------------*/
64
/*---------------------------- CLASS CellHeap ------------------------------*/
65
/*--------------------------------------------------------------------------*/
66
68
class
CellHeap
69
{
70
71
/*--------------------------------------------------------------------------*/
72
public
:
75
using
Value
= long;
76
78
static
constexpr
Value
nil
= -1;
79
82
static
Value
atom
(
long
k );
83
85
[[nodiscard]]
static
bool
isCell
(
Value
v );
86
89
explicit
CellHeap
( std::size_t n );
90
107
Value
cons
(
Value
car
,
Value
cdr
);
108
111
[[nodiscard]]
Value
car
(
Value
c )
const
;
112
115
[[nodiscard]]
Value
cdr
(
Value
c )
const
;
116
119
void
setCar
(
Value
c ,
Value
v );
120
123
void
setCdr
(
Value
c ,
Value
v );
124
127
void
addRoot
(
Value
c );
128
130
void
removeRoot
(
Value
c );
131
173
std::size_t
collect
(
bool
reversal =
true
);
174
176
[[nodiscard]] std::size_t
freeCells
(
void
)
const
;
177
178
/*--------------------------------------------------------------------------*/
179
private
:
180
struct
Cell
181
{
183
Value
car
=
nil
,
cdr
=
nil
;
185
bool
mark =
false
;
186
bool
cdrSide =
false
;
188
bool
free =
true
;
189
};
190
191
void
markReversal(
Value
root );
192
void
markStack(
Value
root );
193
195
[[nodiscard]] std::vector< bool > reachable(
void
)
const
;
196
197
std::vector< Cell > f_C;
198
Value
f_free =
nil
;
199
std::size_t f_nfree = 0;
200
std::multiset< Value > f_roots;
201
202
};
// end( class CellHeap )
203
204
/*--------------------------------------------------------------------------*/
205
206
}
// end( namespace ADS )
207
208
/*--------------------------------------------------------------------------*/
209
/*-------------------------- IMPLEMENTATION --------------------------------*/
210
/*--------------------------------------------------------------------------*/
211
212
#include "ADS/memory/impl/CellHeap.tpp"
213
214
/*--------------------------------------------------------------------------*/
215
216
#endif
/* CellHeap.h included */
217
218
/*--------------------------------------------------------------------------*/
219
/*-------------------------- End File CellHeap.h ---------------------------*/
220
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
ADS::CellHeap::setCdr
void setCdr(Value c, Value v)
the field cdr of the cell set to
ADS::CellHeap::addRoot
void addRoot(Value c)
the cell made a root, once more
ADS::CellHeap::cons
Value cons(Value car, Value cdr)
a new cell with the fields car and cdr, after a collection if no cell is free
ADS::CellHeap::nil
static constexpr Value nil
the empty field
Definition
CellHeap.h:78
ADS::CellHeap::cdr
Value cdr(Value c) const
the field cdr of the cell
ADS::CellHeap::setCar
void setCar(Value c, Value v)
the field car of the cell set to
ADS::CellHeap::Value
long Value
a field: nil, an atom (atom( k ), , for ) or a cell (its address, )
Definition
CellHeap.h:75
ADS::CellHeap::collect
std::size_t collect(bool reversal=true)
marks the cells reachable from the roots, by pointer reversal or with a stack, and frees the others; ...
ADS::CellHeap::removeRoot
void removeRoot(Value c)
one of the roots removed, if there is one
ADS::CellHeap::car
Value car(Value c) const
the field car of the cell
ADS::CellHeap::isCell
static bool isCell(Value v)
whether is the address of a cell
ADS::CellHeap::CellHeap
CellHeap(std::size_t n)
the heap of cells, all free
ADS::CellHeap::atom
static Value atom(long k)
the atom
ADS::CellHeap::freeCells
std::size_t freeCells(void) const
the number of the free cells
ADS
Definition
ADT.h:96
ADS
memory
CellHeap.h
Generated by
1.17.0