namespace vase.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "buffer.h"
|
||||
#include "pch.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
struct AppendBuffer : Buffer {
|
||||
char *buf = nullptr;
|
||||
uint64_t allocated_capacity = 0;
|
||||
@@ -21,3 +22,4 @@ struct AppendBuffer : Buffer {
|
||||
private:
|
||||
void grow(uint64_t len);
|
||||
};
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
struct Buffer {
|
||||
virtual const char *read(uint64_t pos) = 0;
|
||||
virtual uint64_t length() = 0;
|
||||
virtual ~Buffer() = default;
|
||||
};
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "buffer.h"
|
||||
#include "pch.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
struct OriginalBuffer : Buffer {
|
||||
const char *buf;
|
||||
uint64_t len;
|
||||
@@ -15,3 +16,4 @@ struct OriginalBuffer : Buffer {
|
||||
const char *read(uint64_t pos) override;
|
||||
uint64_t length() override;
|
||||
};
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -2,4 +2,6 @@
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
constexpr uint64_t PETAL_SIZE_MAX = 32 * 1024;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
#include "../shard.h"
|
||||
#include "pch.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
enum struct Direction : uint8_t {
|
||||
Forward,
|
||||
Backward
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "pch.h"
|
||||
#include "petal.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
struct LineIterator {
|
||||
PetalIterator it;
|
||||
const char *chunk;
|
||||
@@ -18,3 +19,4 @@ struct LineIterator {
|
||||
bool next(std::string *line);
|
||||
uint64_t byte_offset();
|
||||
};
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "iter.h"
|
||||
#include "pch.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
struct PetalIterator {
|
||||
Direction dir;
|
||||
Shard *root = nullptr;
|
||||
@@ -25,3 +26,4 @@ struct PetalIterator {
|
||||
private:
|
||||
Petal *_next(uint64_t *offset);
|
||||
};
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "constants.h"
|
||||
#include "pch.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
struct Shard {
|
||||
enum struct Kind : uint8_t {
|
||||
Branch,
|
||||
@@ -111,3 +112,4 @@ extern inline void dump_shard(Shard *node, int depth = 0) {
|
||||
if (!depth)
|
||||
std::cout << "\n\n";
|
||||
}
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
#include "constants.h"
|
||||
#include "iterators/line.h"
|
||||
#include "pch.h"
|
||||
#include "search.h"
|
||||
#include "shard.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
struct Point {
|
||||
uint64_t row;
|
||||
uint64_t col;
|
||||
@@ -98,3 +98,4 @@ private:
|
||||
std::string_view pattern, Range range, std::string_view options
|
||||
);
|
||||
};
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "internal/vase/buffer/append.h"
|
||||
#include "internal/vase/vase.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
AppendBuffer::AppendBuffer(std::filesystem::path base_dir) {
|
||||
base_dir /= "tapp.XXXXXX";
|
||||
char *s = strdup(base_dir.c_str());
|
||||
@@ -68,3 +69,4 @@ const char *AppendBuffer::read(uint64_t pos) {
|
||||
uint64_t AppendBuffer::length() {
|
||||
return current_size;
|
||||
}
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "internal/vase/buffer/original.h"
|
||||
#include "internal/vase/vase.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
OriginalBuffer::OriginalBuffer(std::filesystem::path base_dir) {
|
||||
if (!std::filesystem::exists(base_dir) || !std::filesystem::is_directory(base_dir))
|
||||
throw std::runtime_error("Swap directory does not exist or is not a directory.");
|
||||
@@ -43,3 +44,4 @@ const char *OriginalBuffer::read(uint64_t pos) {
|
||||
uint64_t OriginalBuffer::length() {
|
||||
return len;
|
||||
}
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "internal/vase/iterators/line.h"
|
||||
#include "internal/vase/vase.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
LineIterator::LineIterator(Shard *root, uint64_t line_num, Direction dir)
|
||||
: it(root, dir), dir(dir) {
|
||||
it.seek_line(line_num);
|
||||
@@ -71,3 +72,4 @@ bool LineIterator::next(std::string *line) {
|
||||
uint64_t LineIterator::byte_offset() {
|
||||
return last_line_offset;
|
||||
}
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "internal/vase/iterators/petal.h"
|
||||
#include "internal/vase/vase.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
PetalIterator::PetalIterator(Shard *r, Direction dir)
|
||||
: dir(dir), root(r) {
|
||||
if (!root)
|
||||
@@ -156,3 +157,4 @@ bool PetalIterator::next(const char **data, uint64_t *out_len) {
|
||||
uint64_t PetalIterator::byte_offset() {
|
||||
return last_offset;
|
||||
}
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "internal/vase/vase.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
std::vector<ReplacePart> Vase::parse_replace(std::string_view s) {
|
||||
std::vector<ReplacePart> parts;
|
||||
std::string constant;
|
||||
@@ -149,3 +150,4 @@ std::vector<Range> Vase::regex_search(
|
||||
result.push_back({point_of(match.start), point_of(match.end)});
|
||||
return result;
|
||||
}
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "internal/vase/iterators/petal.h"
|
||||
#include "internal/vase/vase.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
std::vector<RegexMatch> Vase::_regex_search(
|
||||
std::string_view pattern, Range range, std::string_view options
|
||||
) {
|
||||
@@ -294,3 +294,4 @@ std::vector<RegexMatch> Vase::_regex_search(
|
||||
|
||||
return results;
|
||||
}
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "internal/vase/shard.h"
|
||||
#include "internal/vase/vase.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
void Shard::retain(Shard *n) {
|
||||
if (n)
|
||||
n->refs++;
|
||||
@@ -256,3 +257,4 @@ Shard *Shard::from_file(std::filesystem::path path, OriginalBuffer *o) {
|
||||
return pieces[0];
|
||||
return build(pieces.data(), 0, pieces.size());
|
||||
}
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "internal/vase/vase.h"
|
||||
#include "internal/vase/iterators/line.h"
|
||||
#include "internal/vase/iterators/petal.h"
|
||||
|
||||
namespace crib::internal::vase {
|
||||
Vase::Vase(std::filesystem::path path, std::filesystem::path swapdir)
|
||||
: path(path), swapdir(swapdir) {
|
||||
if (!std::filesystem::exists(swapdir) || !std::filesystem::is_directory(swapdir))
|
||||
@@ -397,3 +396,4 @@ void Vase::move_lines(Point *point, uint64_t amount, Direction dir) {
|
||||
}
|
||||
clamp(point);
|
||||
}
|
||||
} // namespace crib::internal::vase
|
||||
|
||||
@@ -2,6 +2,4 @@
|
||||
#include "pch.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user