Make basic (unbalanced) insertion work.
This commit is contained in:
@@ -21,8 +21,8 @@ struct AppendBuffer : Buffer {
|
||||
|
||||
~AppendBuffer();
|
||||
|
||||
inline void key(char c);
|
||||
void append(const char *text, uint32_t length);
|
||||
inline uint32_t key(char c);
|
||||
uint32_t append(const char *text, uint32_t length, uint32_t *line_count);
|
||||
|
||||
const char *read(uint32_t pos, uint32_t *out_len);
|
||||
uint32_t count_lines(uint32_t pos, uint32_t length);
|
||||
@@ -33,5 +33,5 @@ private:
|
||||
|
||||
inline uint32_t find_newline(uint32_t target, uint32_t low, uint32_t high);
|
||||
|
||||
inline void _append(const char *text, uint32_t length);
|
||||
inline uint32_t _append(const char *text, uint32_t length);
|
||||
};
|
||||
|
||||
@@ -66,6 +66,7 @@ struct Petal : Shard {
|
||||
: Shard(ShardKind::Petal, length, lines), source(source), pos(pos) {};
|
||||
};
|
||||
|
||||
std::pair<ShardPtr, ShardPtr> split(Shard *n, uint32_t offset);
|
||||
std::pair<ShardPtr, ShardPtr> split_shard(Shard *n, uint32_t offset);
|
||||
ShardPtr concat_shard(ShardPtr left, ShardPtr right);
|
||||
|
||||
void print_shard(const Shard *shard, int depth = 0);
|
||||
|
||||
@@ -25,4 +25,18 @@ struct Vase {
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
void insert(uint32_t offset, const char *data, uint32_t len) {
|
||||
uint32_t lines = 0;
|
||||
uint32_t pos = append.append(data, len, &lines);
|
||||
|
||||
ShardPtr inserted = new Petal(len, lines, &append, pos);
|
||||
|
||||
auto [left, right] = split_shard(root.ptr, offset);
|
||||
|
||||
root = concat_shard(
|
||||
concat_shard(left, inserted),
|
||||
right
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user