-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathused_map.cpp
More file actions
37 lines (37 loc) · 822 Bytes
/
used_map.cpp
File metadata and controls
37 lines (37 loc) · 822 Bytes
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
#include "used_map.h"
void UsedMap::loadFromFile() {
ifstream in;
in.open(filename, ios::in | ios::binary);
if (in.is_open()) {
in.read((char *)map_array, maxn * sizeof(bool));
}
else {
memset(map_array, 0, maxn * sizeof(bool));
}
in.close();
}
void UsedMap::saveToFile() {
ofstream out;
out.open(filename, ios::out | ios::binary | ios::trunc);
out.seekp(0, out.beg);
out.write((char *)map_array, maxn * sizeof(bool));
out.close();
}
UsedMap::UsedMap(const SIZE_T max_slots, const string & filename) {
maxn = max_slots;
this->filename = filename;
map_array = new bool[maxn];
this->loadFromFile();
}
ID_T UsedMap::findEmptySlot() const {
for (ID_T i = 1; i < maxn; i++) {
if (map_array[i] == false) {
return i;
}
}
return 0;
}
UsedMap::~UsedMap() {
this->saveToFile();
delete [] map_array;
}