-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnormalizer.cpp
More file actions
54 lines (48 loc) · 1.17 KB
/
normalizer.cpp
File metadata and controls
54 lines (48 loc) · 1.17 KB
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
#include "normalizer.h"
#include <assert.h>
#include <iostream>
Normalizer::Normalizer(BlockInfo* root): _running(false), _root(root)
{
}
void Normalizer::remember(BlockInfo* block)
{
assert(_known.count(block) == 0);
_known.insert(block);
}
void Normalizer::forget(BlockInfo* block)
{
assert(_known.count(block) > 0);
_known.erase(block);
}
void Normalizer::changeRoot(BlockInfo* newRoot)
{
_root = newRoot;
}
void Normalizer::normalize()
{
if (_running)
return;
_running = true;
/*
cout<<"Root ="<<(void*)_root<<endl;
cout<<"Known blocks: " << _known.size() << endl;
for (set<BlockInfo*>::iterator it = _known.begin(); it != _known.end(); ++it)
cout<<(void *)(*it)<<" ";
cout<<endl;
*/
set <BlockInfo*> reached_blocks;
_root->dfs(&reached_blocks);
/*
cout<<"Reached blocks (" << reached_blocks.size() << ") :";
for (set<BlockInfo*>::iterator it = reached_blocks.begin(); it != reached_blocks.end(); ++it)
cout << " " << (void *)(*it);
cout<<endl;
*/
set<BlockInfo*> known_before = _known;
for (set<BlockInfo*>::iterator it = known_before.begin(); it != known_before.end(); ++it)
{
if (!reached_blocks.count(*it))
delete (*it);
}
_running = false;
}