8#ifndef INCLUDED_SDSL_RAM_FS
9#define INCLUDED_SDSL_RAM_FS
29inline bool exists(std::string
const & name)
32 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
33 return rf.m_map.find(name) != rf.m_map.end();
39 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
42 std::string cname = name;
43 rf.m_map.insert(std::make_pair(std::move(cname), std::move(data)));
47 rf.m_map[name] = std::move(data);
55 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
58 return rf.m_map[name].size();
70 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
71 return rf.m_map[name];
75inline int remove(std::string
const & name)
78 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
87inline int rename(
const std::string old_filename,
const std::string new_filename)
90 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
91 rf.m_map[new_filename] = std::move(rf.m_map[old_filename]);
97inline int open(std::string
const & name)
100 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
106 auto largest_fd = rf.m_fd_map.rbegin()->first;
109 auto smallest_fd = rf.m_fd_map.begin()->first;
110 fd = smallest_fd - 1;
114 rf.m_fd_map.erase(largest_fd);
117 rf.m_fd_map[fd] = name;
125 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
128 if (rf.m_fd_map.count(fd) == 0)
134 rf.m_fd_map.erase(fd);
135 rf.m_fd_map[-fd] =
"";
144 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
145 auto name = rf.m_fd_map[fd];
146 return rf.m_map[name];
153 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
154 if (rf.m_fd_map.count(fd) == 0)
156 auto name = rf.m_fd_map[fd];
157 rf.m_map[name].reserve(new_size);
158 rf.m_map[name].resize(new_size, 0);
166 std::lock_guard<std::recursive_mutex> lock(rf.m_rlock);
167 if (rf.m_fd_map.count(fd) == 0)
169 auto name = rf.m_fd_map[fd];
170 return rf.m_map[name].size();
216 return file.substr(1);
221inline int remove(std::string
const & file)
229 return std::remove(file.c_str());
234inline int rename(std::string
const & old_filename, std::string
const & new_filename)
246 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
size_t file_size(std::string const &name)
Get the file size.
void store(std::string const &name, content_type data)
content_type & content(std::string const &name)
Get the content.
int close(int const fd)
Get fd for file.
int truncate(int const fd, size_t new_size)
Get the content with fd.
bool exists(std::string const &name)
Check if the file exists.
int open(std::string const &name)
Get fd for file.
int remove(std::string const &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.
std::vector< char, track_allocator< char > > content_type
Namespace for the succinct data structure library.
std::string disk_file_name(std::string const &file)
Returns for a RAM-file the corresponding disk file name.
int remove(std::string const &)
Remove a file.
std::string ram_file_name(std::string const &file)
Returns the corresponding RAM-file name for file.
int rename(std::string const &old_filename, std::string const &new_filename)
Rename a file.
bool is_ram_file(std::string const &file)
Determines if the given file is a RAM-file.