-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteTable.cpp
59 lines (48 loc) · 1.44 KB
/
DeleteTable.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
//
// Created by Junchen Liu on 4/24/2022.
//
#include "DeleteTable.h"
#include <filesystem>
#include <fstream>
DeleteTable::DeleteTable() {
//Find if there exist dt file, if so load
if (std::filesystem::exists(std::filesystem::path(fileName))){
this->load();
}
}
void DeleteTable::del(int min_key, int max_key){
vec.emplace_back(min_key,max_key);
}
unsigned long int DeleteTable::getTimeInt(int key) {
for (auto it = vec.rbegin(); it != vec.rend(); ++it)
{
if(key < it->maxKey && key > it->minKey){
return it->t;
}
}
return 0;
}
void DeleteTable::close() {
this->save();
}
void DeleteTable::load() {
ifstream file(fileName);
std::string line, item, op_string, min_str, max_str,timestamp_str;
while (std::getline(file, line))
{
std::stringstream linestream(line);
std::getline(linestream, min_str, ' '); // First argument is a key
std::getline(linestream, max_str, ' '); // Second argument is if visible
std::getline(linestream, timestamp_str, ' '); // Second argument is if visible
int min_key = stoi(min_str);
int max_key = stoi(max_str);
unsigned long int t = stoi(timestamp_str);
vec.emplace_back(min_key,max_key,t);
}
}
void DeleteTable::save() {
std::ofstream file(fileName);
for (const auto &i : vec) {
file << i.minKey << ' ' << i.maxKey << ' '<< i.t << ' ' << std::endl;
}
}