From 386de7a8ed140667fe1b3b92a40fa903457efd4c Mon Sep 17 00:00:00 2001 From: Matuush Date: Tue, 18 Mar 2025 14:50:38 +0100 Subject: [PATCH] Treap interface definition --- file.hpp | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/file.hpp b/file.hpp index 4c9a05c..3343a9b 100644 --- a/file.hpp +++ b/file.hpp @@ -1,6 +1,49 @@ +#include +#include +#include +using std::string; +typedef unsigned long long priority_type; +#define RAND_MAX (1 << 62) +class line; +typedef std::pair two_lines; + +class line { + priority_type priority; + string text; + line *left, *right; + +public: + line(priority_type _p, string _t) : priority(_p), text(_t) {} + + two_lines split(string s) { return two_lines(nullptr, nullptr); } + void join(line *l) {} + + void insert(line *l) {} + void remove(string s) {} + line* find(string s) { return nullptr; } +}; // Treap file representation -class file { +struct file { + line* root; -} + file() { + srand(120); + root = nullptr; + } + void insert(string s) { + line *l = new line(rand(), s); + auto two = root->split(s); + two.first->join(l); + two.first->join(two.second); + } + void remove(string s) { + auto two = root->split(s); + two.first = two.first->split(s).first; // TODO sharp split + two.first->join(two.second); + } + line* find(string s) { + return root->find(s); + } +};