-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
58 lines (39 loc) · 1.24 KB
/
test.cpp
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
55
56
57
58
/*
This file is part of MiniBitmap.
Copyright (C) 2020 Yukino Song
Copyright (C) 2020 ReimuNotMoe
This program is free software: you can redistribute it and/or modify
it under the terms of the Apache License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <MiniBitmap.hpp>
#include <iostream>
#include <cassert>
using namespace YukiWorkshop;
int main() {
MiniBitmap m;
m.mark_as_used(0, 10);
m.mark_as_unused(2, 5);
m.mark_as_used(20, 30);
m.mark_as_used(50, 20);
m.mark_as_unused(33);
m.mark_as_unused(66);
auto data = m.serialize();
std::cout << "Serialized size: " << data.size() << "\n";
MiniBitmap m2;
m2.deserialize(data);
assert(!m2.is_used(11, 8));
puts("Used:");
for (auto &it : m2.used_regions()) {
std::cout << "offset: " << it.first << ", length: " << it.second << "\n";
}
puts("Unused:");
for (auto &it : m2.unused_regions(70)) {
std::cout << "offset: " << it.first << ", length: " << it.second << "\n";
}
std::cout << "Max offset: " << m2.max_offset() << "\n";
std::cout << "Total used size: " << m2.used_size() << "\n";
return 0;
}