8#ifndef INCLUDED_SDSL_RAM_FS
9#define INCLUDED_SDSL_RAM_FS
26inline bool exists(
const std::string & name)
29 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
30 return rf.m_map.find(name) != rf.m_map.end();
36 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
39 std::string cname = name;
40 rf.m_map.insert(std::make_pair(std::move(cname), std::move(data)));
44 rf.m_map[name] = std::move(data);
52 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
53 if (
exists(name)) {
return rf.m_map[name].size(); }
64 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
65 return rf.m_map[name];
69inline int remove(
const std::string & name)
72 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
73 if (
exists(name)) { rf.m_map.erase(name); }
78inline int rename(
const std::string old_filename,
const std::string new_filename)
81 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
82 rf.m_map[new_filename] = std::move(rf.m_map[old_filename]);
88inline int open(
const std::string & name)
91 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
94 auto largest_fd = rf.m_fd_map.rbegin()->first;
97 auto smallest_fd = rf.m_fd_map.begin()->first;
102 rf.m_fd_map.erase(largest_fd);
105 rf.m_fd_map[fd] = name;
113 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
114 if (fd >= -1)
return -1;
115 if (rf.m_fd_map.count(fd) == 0) {
return -1; }
118 rf.m_fd_map.erase(fd);
119 rf.m_fd_map[-fd] =
"";
128 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
129 auto name = rf.m_fd_map[fd];
130 return rf.m_map[name];
137 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
138 if (rf.m_fd_map.count(fd) == 0)
return -1;
139 auto name = rf.m_fd_map[fd];
140 rf.m_map[name].reserve(new_size);
141 rf.m_map[name].resize(new_size, 0);
149 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
150 if (rf.m_fd_map.count(fd) == 0)
return 0;
151 auto name = rf.m_fd_map[fd];
152 return rf.m_map[name].size();
162 if (file[0] ==
'@') {
return true; }
189 return file.substr(1);
194inline int remove(
const std::string & file)
199 return std::remove(file.c_str());
204inline int rename(
const std::string & old_filename,
const std::string & new_filename)
216 return std::rename(old_filename.c_str(), new_filename.c_str());
static ramfs_storage & ram_fs()
memory_tracking.hpp contains two function for allocating and deallocating memory
int open(const std::string &name)
Get fd for file.
bool exists(const std::string &name)
Check if the file exists.
void store(const std::string &name, content_type data)
int close(const int fd)
Get fd for file.
int remove(const std::string &name)
Remove the file with key name
int rename(const std::string old_filename, const std::string new_filename)
Rename the file. Change key old_filename into new_filename.
size_t file_size(const std::string &name)
Get the file size.
std::vector< char, track_allocator< char > > content_type
content_type & content(const std::string &name)
Get the content.
int truncate(const int fd, size_t new_size)
Get the content with fd.
Namespace for the succinct data structure library.
bool is_ram_file(const std::string &file)
Determines if the given file is a RAM-file.
std::string ram_file_name(const std::string &file)
Returns the corresponding RAM-file name for file.
int rename(const std::string &old_filename, const std::string &new_filename)
Rename a file.
std::string disk_file_name(const std::string &file)
Returns for a RAM-file the corresponding disk file name.
int remove(const std::string &)
Remove a file.