Small improvements
This commit is contained in:
@@ -39,6 +39,14 @@ struct Edit {
|
||||
String string;
|
||||
};
|
||||
|
||||
struct Cursor {
|
||||
union {
|
||||
Range range;
|
||||
int64_t pos[2];
|
||||
};
|
||||
int64_t ifront;
|
||||
};
|
||||
|
||||
// - Buffer should be initialized before use!
|
||||
struct Buffer {
|
||||
Allocator allocator;
|
||||
@@ -83,6 +91,43 @@ Range MakeRange(int64_t a, int64_t b) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int64_t GetFront(Cursor cursor) {
|
||||
int64_t result = cursor.pos[cursor.ifront];
|
||||
return result;
|
||||
}
|
||||
|
||||
int64_t GetBack(Cursor cursor) {
|
||||
int64_t index = (cursor.ifront + 1) % 2;
|
||||
int64_t result = cursor.pos[index];
|
||||
return result;
|
||||
}
|
||||
|
||||
Cursor MakeCursor(int64_t front, int64_t back) {
|
||||
Cursor result = {};
|
||||
if (front >= back) {
|
||||
result.range.min = back;
|
||||
result.range.max = front;
|
||||
result.ifront = 1;
|
||||
} else {
|
||||
result.range.min = front;
|
||||
result.range.max = back;
|
||||
result.ifront = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Cursor ChangeBack(Cursor cursor, int64_t back) {
|
||||
int64_t front = GetFront(cursor);
|
||||
Cursor result = MakeCursor(front, back);
|
||||
return result;
|
||||
}
|
||||
|
||||
Cursor ChangeFront(Cursor cursor, int64_t front) {
|
||||
int64_t back = GetBack(cursor);
|
||||
Cursor result = MakeCursor(front, back);
|
||||
return result;
|
||||
}
|
||||
|
||||
void AddEdit(Array<Edit> *edits, Range range, String string) {
|
||||
edits->add({range, string});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user