From 36de891d7753957bd1f56b9810402a909d469d7c Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 15 Jan 2017 07:09:01 -0700 Subject: [PATCH 1/8] Convert BufferOffsetIndex to new naming convention --- src/bindings/bindings.cc | 2 +- src/bindings/buffer-offset-index-wrapper.cc | 24 +++--- src/bindings/buffer-offset-index-wrapper.h | 10 +-- src/core/buffer-offset-index.cc | 42 +++++----- src/core/buffer-offset-index.h | 16 ++-- src/core/marker-index.cc | 8 +- src/core/marker-index.h | 2 +- src/core/text.cc | 4 +- src/core/text.h | 2 +- test/js/buffer-index.test.js | 4 +- test/js/reference-buffer-offset-index.js | 4 +- test/js/reference-buffer-offset-index.test.js | 76 +++++++++---------- 12 files changed, 97 insertions(+), 97 deletions(-) diff --git a/src/bindings/bindings.cc b/src/bindings/bindings.cc index 0a529eb8..0a429604 100644 --- a/src/bindings/bindings.cc +++ b/src/bindings/bindings.cc @@ -10,7 +10,7 @@ void Init(Local exports) { PointWrapper::Init(); PatchWrapper::Init(exports); MarkerIndexWrapper::Init(exports); - BufferOffsetIndexWrapper::Init(exports); + BufferOffsetIndexWrapper::init(exports); } NODE_MODULE(superstring, Init) diff --git a/src/bindings/buffer-offset-index-wrapper.cc b/src/bindings/buffer-offset-index-wrapper.cc index d9f2ee11..fcb5d881 100644 --- a/src/bindings/buffer-offset-index-wrapper.cc +++ b/src/bindings/buffer-offset-index-wrapper.cc @@ -3,23 +3,23 @@ using namespace v8; -void BufferOffsetIndexWrapper::Init(Local exports) { - Local constructor_template = Nan::New(New); +void BufferOffsetIndexWrapper::init(Local exports) { + Local constructor_template = Nan::New(construct); constructor_template->SetClassName(Nan::New("BufferOffsetIndex").ToLocalChecked()); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); const auto &prototype_template = constructor_template->PrototypeTemplate(); - prototype_template->Set(Nan::New("splice").ToLocalChecked(), Nan::New(Splice)); - prototype_template->Set(Nan::New("positionForCharacterIndex").ToLocalChecked(), Nan::New(PositionForCharacterIndex)); - prototype_template->Set(Nan::New("characterIndexForPosition").ToLocalChecked(), Nan::New(CharacterIndexForPosition)); + prototype_template->Set(Nan::New("splice").ToLocalChecked(), Nan::New(splice)); + prototype_template->Set(Nan::New("position_for_character_index").ToLocalChecked(), Nan::New(position_for_character_index)); + prototype_template->Set(Nan::New("character_index_for_position").ToLocalChecked(), Nan::New(character_index_for_position)); exports->Set(Nan::New("BufferOffsetIndex").ToLocalChecked(), constructor_template->GetFunction()); } -void BufferOffsetIndexWrapper::New(const Nan::FunctionCallbackInfo &info) { +void BufferOffsetIndexWrapper::construct(const Nan::FunctionCallbackInfo &info) { BufferOffsetIndexWrapper *buffer_offset_index = new BufferOffsetIndexWrapper(); buffer_offset_index->Wrap(info.This()); } -void BufferOffsetIndexWrapper::Splice(const Nan::FunctionCallbackInfo &info) { +void BufferOffsetIndexWrapper::splice(const Nan::FunctionCallbackInfo &info) { BufferOffsetIndex &buffer_offset_index = Nan::ObjectWrap::Unwrap(info.This())->buffer_offset_index; auto start_row = info[0].As()->Value(); @@ -29,25 +29,25 @@ void BufferOffsetIndexWrapper::Splice(const Nan::FunctionCallbackInfo &in for (size_t i = 0; i < new_line_lengths.size(); i++) { new_line_lengths[i] = js_new_line_lengths->Get(i).As()->Value(); } - buffer_offset_index.Splice(start_row, deleted_lines_count, new_line_lengths); + buffer_offset_index.splice(start_row, deleted_lines_count, new_line_lengths); } -void BufferOffsetIndexWrapper::CharacterIndexForPosition(const Nan::FunctionCallbackInfo &info) { +void BufferOffsetIndexWrapper::character_index_for_position(const Nan::FunctionCallbackInfo &info) { BufferOffsetIndex &buffer_offset_index = Nan::ObjectWrap::Unwrap(info.This())->buffer_offset_index; auto position = PointWrapper::PointFromJS(info[0]); if (position) { - auto result = buffer_offset_index.CharacterIndexForPosition(*position); + auto result = buffer_offset_index.character_index_for_position(*position); info.GetReturnValue().Set(Nan::New(result)); } } -void BufferOffsetIndexWrapper::PositionForCharacterIndex(const Nan::FunctionCallbackInfo &info) { +void BufferOffsetIndexWrapper::position_for_character_index(const Nan::FunctionCallbackInfo &info) { BufferOffsetIndex &buffer_offset_index = Nan::ObjectWrap::Unwrap(info.This())->buffer_offset_index; auto character_index = Nan::To(info[0]); if (character_index.IsJust()) { - auto result = buffer_offset_index.PositionForCharacterIndex(character_index.FromJust()); + auto result = buffer_offset_index.position_for_character_index(character_index.FromJust()); info.GetReturnValue().Set(PointWrapper::FromPoint(result)); } } diff --git a/src/bindings/buffer-offset-index-wrapper.h b/src/bindings/buffer-offset-index-wrapper.h index 8918dc45..7aec52bb 100644 --- a/src/bindings/buffer-offset-index-wrapper.h +++ b/src/bindings/buffer-offset-index-wrapper.h @@ -3,13 +3,13 @@ class BufferOffsetIndexWrapper : public Nan::ObjectWrap { public: - static void Init(v8::Local exports); + static void init(v8::Local exports); private: - static void New(const Nan::FunctionCallbackInfo &info); - static void Splice(const Nan::FunctionCallbackInfo &info); - static void CharacterIndexForPosition(const Nan::FunctionCallbackInfo &info); - static void PositionForCharacterIndex(const Nan::FunctionCallbackInfo &info); + static void construct(const Nan::FunctionCallbackInfo &info); + static void splice(const Nan::FunctionCallbackInfo &info); + static void character_index_for_position(const Nan::FunctionCallbackInfo &info); + static void position_for_character_index(const Nan::FunctionCallbackInfo &info); BufferOffsetIndex buffer_offset_index; }; diff --git a/src/core/buffer-offset-index.cc b/src/core/buffer-offset-index.cc index b693e4fc..abdd628f 100644 --- a/src/core/buffer-offset-index.cc +++ b/src/core/buffer-offset-index.cc @@ -54,9 +54,9 @@ BufferOffsetIndex::~BufferOffsetIndex() { } } -void BufferOffsetIndex::Splice(unsigned start_row, unsigned deleted_lines_count, std::vector &new_line_lengths) { - auto start_node = FindAndBubbleNodeUpToRoot(start_row - 1); - auto end_node = FindAndBubbleNodeUpToRoot(start_row + deleted_lines_count); +void BufferOffsetIndex::splice(unsigned start_row, unsigned deleted_lines_count, std::vector &new_line_lengths) { + auto start_node = find_and_bubble_node_up_to_root(start_row - 1); + auto end_node = find_and_bubble_node_up_to_root(start_row + deleted_lines_count); if (start_node) { if (start_node->right) { @@ -65,7 +65,7 @@ void BufferOffsetIndex::Splice(unsigned start_row, unsigned deleted_lines_count, } if (!new_line_lengths.empty()) { - start_node->right = BuildLineNodeTreeFromLineLengths(new_line_lengths, 0, new_line_lengths.size(), 1); + start_node->right = build_node_tree_from_line_lengths(new_line_lengths, 0, new_line_lengths.size(), 1); } start_node->compute_subtree_extents(); @@ -76,7 +76,7 @@ void BufferOffsetIndex::Splice(unsigned start_row, unsigned deleted_lines_count, } if (!new_line_lengths.empty()) { - end_node->left = BuildLineNodeTreeFromLineLengths(new_line_lengths, 0, new_line_lengths.size(), 1); + end_node->left = build_node_tree_from_line_lengths(new_line_lengths, 0, new_line_lengths.size(), 1); } end_node->compute_subtree_extents(); @@ -85,7 +85,7 @@ void BufferOffsetIndex::Splice(unsigned start_row, unsigned deleted_lines_count, delete root; } - root = BuildLineNodeTreeFromLineLengths(new_line_lengths, 0, new_line_lengths.size(), 1); + root = build_node_tree_from_line_lengths(new_line_lengths, 0, new_line_lengths.size(), 1); } if (end_node) { @@ -96,16 +96,16 @@ void BufferOffsetIndex::Splice(unsigned start_row, unsigned deleted_lines_count, if (start_node) { start_node->priority = rng(rng_engine); - BubbleNodeDown(start_node, end_node); + bubble_node_down(start_node, end_node); } if (end_node) { end_node->priority = rng(rng_engine); - BubbleNodeDown(end_node, nullptr); + bubble_node_down(end_node, nullptr); } } -unsigned BufferOffsetIndex::CharacterIndexForPosition(Point position) const { +unsigned BufferOffsetIndex::character_index_for_position(Point position) const { auto left_ancestor_row = 0u; auto left_ancestor_char_index = 0u; auto current_node_char_index = 0u; @@ -131,7 +131,7 @@ unsigned BufferOffsetIndex::CharacterIndexForPosition(Point position) const { } } -Point BufferOffsetIndex::PositionForCharacterIndex(unsigned char_index) const { +Point BufferOffsetIndex::position_for_character_index(unsigned char_index) const { auto left_ancestor_row = 0u; auto left_ancestor_char_index = 0u; auto left_ancestor_length = 0u; @@ -161,7 +161,7 @@ Point BufferOffsetIndex::PositionForCharacterIndex(unsigned char_index) const { } } -LineNode *BufferOffsetIndex::FindAndBubbleNodeUpToRoot(unsigned row) { +LineNode *BufferOffsetIndex::find_and_bubble_node_up_to_root(unsigned row) { auto left_ancestor_row = 0u; auto current_node = root; auto ancestors_stack = std::vector(); @@ -185,9 +185,9 @@ LineNode *BufferOffsetIndex::FindAndBubbleNodeUpToRoot(unsigned row) { ancestors_stack.pop_back(); auto root_parent = ancestors_stack.empty() ? nullptr : ancestors_stack.back(); if (root->right == current_node) { - RotateNodeLeft(current_node, root, root_parent); + rotate_node_left(current_node, root, root_parent); } else { // root->left == current_node - RotateNodeRight(current_node, root, root_parent); + rotate_node_right(current_node, root, root_parent); } } @@ -197,17 +197,17 @@ LineNode *BufferOffsetIndex::FindAndBubbleNodeUpToRoot(unsigned row) { } } -void BufferOffsetIndex::BubbleNodeDown(LineNode * root, LineNode * root_parent) { +void BufferOffsetIndex::bubble_node_down(LineNode * root, LineNode * root_parent) { while (true) { auto left_child_priority = root->left ? root->left->priority : UINT_MAX; auto right_child_priority = root->right ? root->right->priority : UINT_MAX; if (left_child_priority < right_child_priority && left_child_priority < root->priority) { auto pivot = root->left; - RotateNodeRight(pivot, root, root_parent); + rotate_node_right(pivot, root, root_parent); root_parent = pivot; } else if (right_child_priority < root->priority) { auto pivot = root->right; - RotateNodeLeft(pivot, root, root_parent); + rotate_node_left(pivot, root, root_parent); root_parent = pivot; } else { break; @@ -215,7 +215,7 @@ void BufferOffsetIndex::BubbleNodeDown(LineNode * root, LineNode * root_parent) } } -void BufferOffsetIndex::RotateNodeLeft(LineNode * pivot, LineNode * root, LineNode * root_parent) { +void BufferOffsetIndex::rotate_node_left(LineNode * pivot, LineNode * root, LineNode * root_parent) { if (root_parent) { if (root == root_parent->left) { root_parent->left = pivot; @@ -233,7 +233,7 @@ void BufferOffsetIndex::RotateNodeLeft(LineNode * pivot, LineNode * root, LineNo pivot->compute_subtree_extents(); } -void BufferOffsetIndex::RotateNodeRight(LineNode * pivot, LineNode * root, LineNode * root_parent) { +void BufferOffsetIndex::rotate_node_right(LineNode * pivot, LineNode * root, LineNode * root_parent) { if (root_parent) { if (root == root_parent->left) { root_parent->left = pivot; @@ -251,7 +251,7 @@ void BufferOffsetIndex::RotateNodeRight(LineNode * pivot, LineNode * root, LineN pivot->compute_subtree_extents(); } -LineNode *BufferOffsetIndex::BuildLineNodeTreeFromLineLengths(std::vector &line_lengths, unsigned start, unsigned end, unsigned min_priority) { +LineNode *BufferOffsetIndex::build_node_tree_from_line_lengths(std::vector &line_lengths, unsigned start, unsigned end, unsigned min_priority) { if (start == end) { return nullptr; } else { @@ -259,8 +259,8 @@ LineNode *BufferOffsetIndex::BuildLineNodeTreeFromLineLengths(std::vector&); - unsigned CharacterIndexForPosition(Point) const; - Point PositionForCharacterIndex(unsigned) const; + void splice(unsigned, unsigned, std::vector&); + unsigned character_index_for_position(Point) const; + Point position_for_character_index(unsigned) const; private: - LineNode *FindAndBubbleNodeUpToRoot(unsigned); - void BubbleNodeDown(LineNode *, LineNode *); - void RotateNodeLeft(LineNode *, LineNode *, LineNode *); - void RotateNodeRight(LineNode *, LineNode *, LineNode *); - LineNode *BuildLineNodeTreeFromLineLengths(std::vector&, unsigned, unsigned, unsigned); + LineNode *find_and_bubble_node_up_to_root(unsigned); + void bubble_node_down(LineNode *, LineNode *); + void rotate_node_left(LineNode *, LineNode *, LineNode *); + void rotate_node_right(LineNode *, LineNode *, LineNode *); + LineNode *build_node_tree_from_line_lengths(std::vector&, unsigned, unsigned, unsigned); LineNode *root; std::default_random_engine rng_engine; diff --git a/src/core/marker-index.cc b/src/core/marker-index.cc index b21e7cc5..c76d31ef 100644 --- a/src/core/marker-index.cc +++ b/src/core/marker-index.cc @@ -542,14 +542,14 @@ MarkerIndex::SpliceResult MarkerIndex::Splice(Point start, Point old_extent, Poi DeleteNode(end_node); } else if (end_node->IsMarkerEndpoint()) { end_node->priority = GenerateRandomNumber(); - BubbleNodeDown(end_node); + bubble_node_down(end_node); } else { DeleteNode(end_node); } if (start_node->IsMarkerEndpoint()) { start_node->priority = GenerateRandomNumber(); - BubbleNodeDown(start_node); + bubble_node_down(start_node); } else { DeleteNode(start_node); } @@ -665,7 +665,7 @@ void MarkerIndex::DeleteNode(Node *node) { node_position_cache.erase(node); node->priority = INT_MAX; - BubbleNodeDown(node); + bubble_node_down(node); if (node->parent) { if (node->parent->left == node) { @@ -696,7 +696,7 @@ void MarkerIndex::BubbleNodeUp(Node *node) { } } -void MarkerIndex::BubbleNodeDown(Node *node) { +void MarkerIndex::bubble_node_down(Node *node) { while (true) { int left_child_priority = (node->left) ? node->left->priority : INT_MAX; int right_child_priority = (node->right) ? node->right->priority : INT_MAX; diff --git a/src/core/marker-index.h b/src/core/marker-index.h index 25f96195..7ef8f350 100644 --- a/src/core/marker-index.h +++ b/src/core/marker-index.h @@ -98,7 +98,7 @@ class MarkerIndex { void DeleteNode(Node *node); void DeleteSubtree(Node *node); void BubbleNodeUp(Node *node); - void BubbleNodeDown(Node *node); + void bubble_node_down(Node *node); void RotateNodeLeft(Node *pivot); void RotateNodeRight(Node *pivot); void GetStartingAndEndingMarkersWithinSubtree(const Node *node, flat_set *starting, flat_set *ending); diff --git a/src/core/text.cc b/src/core/text.cc index a5e2a504..9832dec4 100644 --- a/src/core/text.cc +++ b/src/core/text.cc @@ -67,7 +67,7 @@ TextSlice::operator Text() const { } std::pair TextSlice::Split(Point position) { - size_t index = CharacterIndexForPosition(position); + size_t index = character_index_for_position(position); return { TextSlice{text, start_index, start_index + index}, TextSlice{text, start_index + index, end_index} @@ -82,7 +82,7 @@ TextSlice TextSlice::Prefix(Point prefix_end) { return Split(prefix_end).first; } -size_t TextSlice::CharacterIndexForPosition(Point target) { +size_t TextSlice::character_index_for_position(Point target) { Point position; auto begin = text->begin() + start_index; auto end = text->begin() + end_index; diff --git a/src/core/text.h b/src/core/text.h index 2cb9b476..ff9bb114 100644 --- a/src/core/text.h +++ b/src/core/text.h @@ -27,7 +27,7 @@ struct TextSlice { std::pair Split(Point); TextSlice Prefix(Point); TextSlice Suffix(Point); - size_t CharacterIndexForPosition(Point); + size_t character_index_for_position(Point); }; std::ostream &operator<<(std::ostream &stream, const Text *text); diff --git a/test/js/buffer-index.test.js b/test/js/buffer-index.test.js index 9d3d8790..d367ac52 100644 --- a/test/js/buffer-index.test.js +++ b/test/js/buffer-index.test.js @@ -31,8 +31,8 @@ describe('BufferOffsetIndex', () => { const row = random(10) <= 1 ? Infinity : random.intBetween(0, referenceIndex.getLineCount() + 10) const column = random(10) <= 1 ? Infinity : random.intBetween(0, referenceIndex.getLongestColumn() + 10) const position = {row, column} - assert.equal(bufferIndex.characterIndexForPosition(position), referenceIndex.characterIndexForPosition(position)) - assert.deepEqual(bufferIndex.positionForCharacterIndex(index), referenceIndex.positionForCharacterIndex(index)) + assert.equal(bufferIndex.character_index_for_position(position), referenceIndex.character_index_for_position(position)) + assert.deepEqual(bufferIndex.position_for_character_index(index), referenceIndex.position_for_character_index(index)) } } } diff --git a/test/js/reference-buffer-offset-index.js b/test/js/reference-buffer-offset-index.js index cc2077e9..7130bc39 100644 --- a/test/js/reference-buffer-offset-index.js +++ b/test/js/reference-buffer-offset-index.js @@ -23,7 +23,7 @@ module.exports = class ReferenceBufferOffsetIndex { this.longestColumn = this.lineLengths.reduce((a, b) => Math.max(a, b), 0) } - positionForCharacterIndex (index) { + position_for_character_index (index) { let charIndex = 0 let row = 0 for (const lineLength of this.lineLengths) { @@ -38,7 +38,7 @@ module.exports = class ReferenceBufferOffsetIndex { return {row, column: Math.min(index - charIndex, lineLength)} } - characterIndexForPosition (position) { + character_index_for_position (position) { const charIndex = this.lineLengths.slice(0, position.row).reduce((a, b) => a + b, 0) const lineLength = this.lineLengths[position.row] if (lineLength == null) { diff --git a/test/js/reference-buffer-offset-index.test.js b/test/js/reference-buffer-offset-index.test.js index 515df73c..3646bbe0 100644 --- a/test/js/reference-buffer-offset-index.test.js +++ b/test/js/reference-buffer-offset-index.test.js @@ -5,45 +5,45 @@ describe('ReferenceBufferOffsetIndex', () => { it('maps character indices to 2d points and viceversa', () => { const bufferIndex = new ReferenceBufferOffsetIndex() bufferIndex.splice(0, 0, [1, 3, 5]) // a|bcd|efghi - assert.deepEqual(bufferIndex.positionForCharacterIndex(0), {row: 0, column: 0}) - assert.equal(bufferIndex.characterIndexForPosition({row: 0, column: 0}), 0) - assert.deepEqual(bufferIndex.positionForCharacterIndex(1), {row: 1, column: 0}) - assert.equal(bufferIndex.characterIndexForPosition({row: 1, column: 0}), 1) - assert.deepEqual(bufferIndex.positionForCharacterIndex(2), {row: 1, column: 1}) - assert.equal(bufferIndex.characterIndexForPosition({row: 1, column: 1}), 2) - assert.deepEqual(bufferIndex.positionForCharacterIndex(4), {row: 2, column: 0}) - assert.equal(bufferIndex.characterIndexForPosition({row: 2, column: 0}), 4) - assert.deepEqual(bufferIndex.positionForCharacterIndex(7), {row: 2, column: 3}) - assert.equal(bufferIndex.characterIndexForPosition({row: 2, column: 3}), 7) - assert.deepEqual(bufferIndex.positionForCharacterIndex(8), {row: 2, column: 4}) - assert.equal(bufferIndex.characterIndexForPosition({row: 2, column: 4}), 8) - assert.deepEqual(bufferIndex.positionForCharacterIndex(Infinity), {row: 2, column: 5}) - assert.equal(bufferIndex.characterIndexForPosition({row: 2, column: 5}), 9) - assert.equal(bufferIndex.characterIndexForPosition({row: 2, column: 6}), 9) - assert.equal(bufferIndex.characterIndexForPosition({row: 2, column: Infinity}), 9) - assert.equal(bufferIndex.characterIndexForPosition({row: Infinity, column: Infinity}), 9) + assert.deepEqual(bufferIndex.position_for_character_index(0), {row: 0, column: 0}) + assert.equal(bufferIndex.character_index_for_position({row: 0, column: 0}), 0) + assert.deepEqual(bufferIndex.position_for_character_index(1), {row: 1, column: 0}) + assert.equal(bufferIndex.character_index_for_position({row: 1, column: 0}), 1) + assert.deepEqual(bufferIndex.position_for_character_index(2), {row: 1, column: 1}) + assert.equal(bufferIndex.character_index_for_position({row: 1, column: 1}), 2) + assert.deepEqual(bufferIndex.position_for_character_index(4), {row: 2, column: 0}) + assert.equal(bufferIndex.character_index_for_position({row: 2, column: 0}), 4) + assert.deepEqual(bufferIndex.position_for_character_index(7), {row: 2, column: 3}) + assert.equal(bufferIndex.character_index_for_position({row: 2, column: 3}), 7) + assert.deepEqual(bufferIndex.position_for_character_index(8), {row: 2, column: 4}) + assert.equal(bufferIndex.character_index_for_position({row: 2, column: 4}), 8) + assert.deepEqual(bufferIndex.position_for_character_index(Infinity), {row: 2, column: 5}) + assert.equal(bufferIndex.character_index_for_position({row: 2, column: 5}), 9) + assert.equal(bufferIndex.character_index_for_position({row: 2, column: 6}), 9) + assert.equal(bufferIndex.character_index_for_position({row: 2, column: Infinity}), 9) + assert.equal(bufferIndex.character_index_for_position({row: Infinity, column: Infinity}), 9) bufferIndex.splice(0, 2, [5, 1, 4]) // abcde|f|ghij|klmno - assert.deepEqual(bufferIndex.positionForCharacterIndex(0), {row: 0, column: 0}) - assert.equal(bufferIndex.characterIndexForPosition({row: 0, column: 0}), 0) - assert.deepEqual(bufferIndex.positionForCharacterIndex(1), {row: 0, column: 1}) - assert.equal(bufferIndex.characterIndexForPosition({row: 0, column: 1}), 1) - assert.deepEqual(bufferIndex.positionForCharacterIndex(5), {row: 1, column: 0}) - assert.equal(bufferIndex.characterIndexForPosition({row: 1, column: 0}), 5) - assert.deepEqual(bufferIndex.positionForCharacterIndex(6), {row: 2, column: 0}) - assert.equal(bufferIndex.characterIndexForPosition({row: 2, column: 0}), 6) - assert.deepEqual(bufferIndex.positionForCharacterIndex(7), {row: 2, column: 1}) - assert.equal(bufferIndex.characterIndexForPosition({row: 2, column: 1}), 7) - assert.deepEqual(bufferIndex.positionForCharacterIndex(10), {row: 3, column: 0}) - assert.equal(bufferIndex.characterIndexForPosition({row: 3, column: 0}), 10) - assert.deepEqual(bufferIndex.positionForCharacterIndex(13), {row: 3, column: 3}) - assert.equal(bufferIndex.characterIndexForPosition({row: 3, column: 3}), 13) - assert.deepEqual(bufferIndex.positionForCharacterIndex(14), {row: 3, column: 4}) - assert.equal(bufferIndex.characterIndexForPosition({row: 3, column: 4}), 14) - assert.deepEqual(bufferIndex.positionForCharacterIndex(Infinity), {row: 3, column: 5}) - assert.equal(bufferIndex.characterIndexForPosition({row: 3, column: 5}), 15) - assert.equal(bufferIndex.characterIndexForPosition({row: 3, column: 6}), 15) - assert.equal(bufferIndex.characterIndexForPosition({row: 3, column: Infinity}), 15) - assert.equal(bufferIndex.characterIndexForPosition({row: Infinity, column: Infinity}), 15) + assert.deepEqual(bufferIndex.position_for_character_index(0), {row: 0, column: 0}) + assert.equal(bufferIndex.character_index_for_position({row: 0, column: 0}), 0) + assert.deepEqual(bufferIndex.position_for_character_index(1), {row: 0, column: 1}) + assert.equal(bufferIndex.character_index_for_position({row: 0, column: 1}), 1) + assert.deepEqual(bufferIndex.position_for_character_index(5), {row: 1, column: 0}) + assert.equal(bufferIndex.character_index_for_position({row: 1, column: 0}), 5) + assert.deepEqual(bufferIndex.position_for_character_index(6), {row: 2, column: 0}) + assert.equal(bufferIndex.character_index_for_position({row: 2, column: 0}), 6) + assert.deepEqual(bufferIndex.position_for_character_index(7), {row: 2, column: 1}) + assert.equal(bufferIndex.character_index_for_position({row: 2, column: 1}), 7) + assert.deepEqual(bufferIndex.position_for_character_index(10), {row: 3, column: 0}) + assert.equal(bufferIndex.character_index_for_position({row: 3, column: 0}), 10) + assert.deepEqual(bufferIndex.position_for_character_index(13), {row: 3, column: 3}) + assert.equal(bufferIndex.character_index_for_position({row: 3, column: 3}), 13) + assert.deepEqual(bufferIndex.position_for_character_index(14), {row: 3, column: 4}) + assert.equal(bufferIndex.character_index_for_position({row: 3, column: 4}), 14) + assert.deepEqual(bufferIndex.position_for_character_index(Infinity), {row: 3, column: 5}) + assert.equal(bufferIndex.character_index_for_position({row: 3, column: 5}), 15) + assert.equal(bufferIndex.character_index_for_position({row: 3, column: 6}), 15) + assert.equal(bufferIndex.character_index_for_position({row: 3, column: Infinity}), 15) + assert.equal(bufferIndex.character_index_for_position({row: Infinity, column: Infinity}), 15) }) }) From 3e24efd91e6b26cc0f054182146ef624ae6bdd5d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 15 Jan 2017 07:25:17 -0700 Subject: [PATCH 2/8] Convert MarkerIndex to new naming convention --- src/bindings/bindings.cc | 2 +- src/bindings/marker-index-wrapper.cc | 164 +++++++------- src/bindings/marker-index-wrapper.h | 50 ++--- src/core/marker-index.cc | 308 +++++++++++++-------------- src/core/marker-index.h | 92 ++++---- 5 files changed, 308 insertions(+), 308 deletions(-) diff --git a/src/bindings/bindings.cc b/src/bindings/bindings.cc index 0a429604..de28205c 100644 --- a/src/bindings/bindings.cc +++ b/src/bindings/bindings.cc @@ -9,7 +9,7 @@ using namespace v8; void Init(Local exports) { PointWrapper::Init(); PatchWrapper::Init(exports); - MarkerIndexWrapper::Init(exports); + MarkerIndexWrapper::init(exports); BufferOffsetIndexWrapper::init(exports); } diff --git a/src/bindings/marker-index-wrapper.cc b/src/bindings/marker-index-wrapper.cc index 077d14ff..8fd7b06d 100644 --- a/src/bindings/marker-index-wrapper.cc +++ b/src/bindings/marker-index-wrapper.cc @@ -16,36 +16,36 @@ static Nan::Persistent inside_string; static Nan::Persistent overlap_string; static Nan::Persistent surround_string; -void MarkerIndexWrapper::Init(Local exports) { - Local constructor_template = Nan::New(New); +void MarkerIndexWrapper::init(Local exports) { + Local constructor_template = Nan::New(construct); constructor_template->SetClassName(Nan::New("MarkerIndex").ToLocalChecked()); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); const auto &prototype_template = constructor_template->PrototypeTemplate(); prototype_template->Set(Nan::New("generateRandomNumber").ToLocalChecked(), - Nan::New(GenerateRandomNumber)); - prototype_template->Set(Nan::New("insert").ToLocalChecked(), Nan::New(Insert)); - prototype_template->Set(Nan::New("setExclusive").ToLocalChecked(), Nan::New(SetExclusive)); - prototype_template->Set(Nan::New("delete").ToLocalChecked(), Nan::New(Delete)); - prototype_template->Set(Nan::New("splice").ToLocalChecked(), Nan::New(Splice)); - prototype_template->Set(Nan::New("getStart").ToLocalChecked(), Nan::New(GetStart)); - prototype_template->Set(Nan::New("getEnd").ToLocalChecked(), Nan::New(GetEnd)); - prototype_template->Set(Nan::New("getRange").ToLocalChecked(), Nan::New(GetRange)); - prototype_template->Set(Nan::New("compare").ToLocalChecked(), Nan::New(Compare)); + Nan::New(generate_random_number)); + prototype_template->Set(Nan::New("insert").ToLocalChecked(), Nan::New(insert)); + prototype_template->Set(Nan::New("setExclusive").ToLocalChecked(), Nan::New(set_exclusive)); + prototype_template->Set(Nan::New("delete").ToLocalChecked(), Nan::New(delete_marker)); + prototype_template->Set(Nan::New("splice").ToLocalChecked(), Nan::New(splice)); + prototype_template->Set(Nan::New("getStart").ToLocalChecked(), Nan::New(get_start)); + prototype_template->Set(Nan::New("getEnd").ToLocalChecked(), Nan::New(get_end)); + prototype_template->Set(Nan::New("getRange").ToLocalChecked(), Nan::New(get_range)); + prototype_template->Set(Nan::New("compare").ToLocalChecked(), Nan::New(compare)); prototype_template->Set(Nan::New("findIntersecting").ToLocalChecked(), - Nan::New(FindIntersecting)); + Nan::New(find_intersecting)); prototype_template->Set(Nan::New("findContaining").ToLocalChecked(), - Nan::New(FindContaining)); + Nan::New(find_containing)); prototype_template->Set(Nan::New("findContainedIn").ToLocalChecked(), - Nan::New(FindContainedIn)); + Nan::New(find_contained_in)); prototype_template->Set(Nan::New("findStartingIn").ToLocalChecked(), - Nan::New(FindStartingIn)); + Nan::New(find_starting_in)); prototype_template->Set(Nan::New("findStartingAt").ToLocalChecked(), - Nan::New(FindStartingAt)); - prototype_template->Set(Nan::New("findEndingIn").ToLocalChecked(), Nan::New(FindEndingIn)); - prototype_template->Set(Nan::New("findEndingAt").ToLocalChecked(), Nan::New(FindEndingAt)); - prototype_template->Set(Nan::New("dump").ToLocalChecked(), Nan::New(Dump)); + Nan::New(find_starting_at)); + prototype_template->Set(Nan::New("findEndingIn").ToLocalChecked(), Nan::New(find_ending_in)); + prototype_template->Set(Nan::New("findEndingAt").ToLocalChecked(), Nan::New(find_ending_at)); + prototype_template->Set(Nan::New("dump").ToLocalChecked(), Nan::New(dump)); start_string.Reset(Nan::Persistent(Nan::New("start").ToLocalChecked())); end_string.Reset(Nan::Persistent(Nan::New("end").ToLocalChecked())); @@ -57,18 +57,18 @@ void MarkerIndexWrapper::Init(Local exports) { exports->Set(Nan::New("MarkerIndex").ToLocalChecked(), constructor_template->GetFunction()); } -void MarkerIndexWrapper::New(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::construct(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *marker_index = new MarkerIndexWrapper(Local::Cast(info[0])); marker_index->Wrap(info.This()); } -void MarkerIndexWrapper::GenerateRandomNumber(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::generate_random_number(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - int random = wrapper->marker_index.GenerateRandomNumber(); + int random = wrapper->marker_index.generate_random_number(); info.GetReturnValue().Set(Nan::New(random)); } -Local MarkerIndexWrapper::MarkerIdsToJS(const MarkerIndex::MarkerIdSet &marker_ids) { +Local MarkerIndexWrapper::marker_ids_to_js(const MarkerIndex::MarkerIdSet &marker_ids) { Isolate *isolate = v8::Isolate::GetCurrent(); Local context = isolate->GetCurrentContext(); Local js_set = v8::Set::New(isolate); @@ -82,7 +82,7 @@ Local MarkerIndexWrapper::MarkerIdsToJS(const MarkerIndex::MarkerIdSet &mar return js_set; } -Local MarkerIndexWrapper::SnapshotToJS(const unordered_map &snapshot) { +Local MarkerIndexWrapper::snapshot_to_js(const unordered_map &snapshot) { Local result_object = Nan::New(); for (auto &pair : snapshot) { Local range = Nan::New(); @@ -93,8 +93,8 @@ Local MarkerIndexWrapper::SnapshotToJS(const unordered_map MarkerIndexWrapper::MarkerIdFromJS(Local value) { - auto result = UnsignedFromJS(value); +optional MarkerIndexWrapper::marker_id_from_js(Local value) { + auto result = unsigned_from_js(value); if (result) { return *result; } else { @@ -102,7 +102,7 @@ optional MarkerIndexWrapper::MarkerIdFromJS(Local } } -optional MarkerIndexWrapper::UnsignedFromJS(Local value) { +optional MarkerIndexWrapper::unsigned_from_js(Local value) { Nan::Maybe result = Nan::To(value); if (!result.IsJust()) { Nan::ThrowTypeError("Expected an non-negative integer value."); @@ -111,7 +111,7 @@ optional MarkerIndexWrapper::UnsignedFromJS(Local value) { return result.FromJust(); } -optional MarkerIndexWrapper::BoolFromJS(Local value) { +optional MarkerIndexWrapper::bool_from_js(Local value) { Nan::MaybeLocal maybe_boolean = Nan::To(value); Local boolean; if (!maybe_boolean.ToLocal(&boolean)) { @@ -122,83 +122,83 @@ optional MarkerIndexWrapper::BoolFromJS(Local value) { return boolean->Value(); } -void MarkerIndexWrapper::Insert(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::insert(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional id = MarkerIdFromJS(info[0]); + optional id = marker_id_from_js(info[0]); optional start = PointWrapper::PointFromJS(info[1]); optional end = PointWrapper::PointFromJS(info[2]); if (id && start && end) { - wrapper->marker_index.Insert(*id, *start, *end); + wrapper->marker_index.insert(*id, *start, *end); } } -void MarkerIndexWrapper::SetExclusive(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::set_exclusive(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional id = MarkerIdFromJS(info[0]); - optional exclusive = BoolFromJS(info[1]); + optional id = marker_id_from_js(info[0]); + optional exclusive = bool_from_js(info[1]); if (id && exclusive) { - wrapper->marker_index.SetExclusive(*id, *exclusive); + wrapper->marker_index.set_exclusive(*id, *exclusive); } } -void MarkerIndexWrapper::Delete(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::delete_marker(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional id = MarkerIdFromJS(info[0]); + optional id = marker_id_from_js(info[0]); if (id) { - wrapper->marker_index.Delete(*id); + wrapper->marker_index.delete_marker(*id); } } -void MarkerIndexWrapper::Splice(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::splice(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); optional start = PointWrapper::PointFromJS(info[0]); optional old_extent = PointWrapper::PointFromJS(info[1]); optional new_extent = PointWrapper::PointFromJS(info[2]); if (start && old_extent && new_extent) { - MarkerIndex::SpliceResult result = wrapper->marker_index.Splice(*start, *old_extent, *new_extent); + MarkerIndex::SpliceResult result = wrapper->marker_index.splice(*start, *old_extent, *new_extent); Local invalidated = Nan::New(); - invalidated->Set(Nan::New(touch_string), MarkerIdsToJS(result.touch)); - invalidated->Set(Nan::New(inside_string), MarkerIdsToJS(result.inside)); - invalidated->Set(Nan::New(inside_string), MarkerIdsToJS(result.inside)); - invalidated->Set(Nan::New(overlap_string), MarkerIdsToJS(result.overlap)); - invalidated->Set(Nan::New(surround_string), MarkerIdsToJS(result.surround)); + invalidated->Set(Nan::New(touch_string), marker_ids_to_js(result.touch)); + invalidated->Set(Nan::New(inside_string), marker_ids_to_js(result.inside)); + invalidated->Set(Nan::New(inside_string), marker_ids_to_js(result.inside)); + invalidated->Set(Nan::New(overlap_string), marker_ids_to_js(result.overlap)); + invalidated->Set(Nan::New(surround_string), marker_ids_to_js(result.surround)); info.GetReturnValue().Set(invalidated); } } -void MarkerIndexWrapper::GetStart(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::get_start(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional id = MarkerIdFromJS(info[0]); + optional id = marker_id_from_js(info[0]); if (id) { - Point result = wrapper->marker_index.GetStart(*id); + Point result = wrapper->marker_index.get_start(*id); info.GetReturnValue().Set(PointWrapper::FromPoint(result)); } } -void MarkerIndexWrapper::GetEnd(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::get_end(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional id = MarkerIdFromJS(info[0]); + optional id = marker_id_from_js(info[0]); if (id) { - Point result = wrapper->marker_index.GetEnd(*id); + Point result = wrapper->marker_index.get_end(*id); info.GetReturnValue().Set(PointWrapper::FromPoint(result)); } } -void MarkerIndexWrapper::GetRange(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::get_range(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional id = MarkerIdFromJS(info[0]); + optional id = marker_id_from_js(info[0]); if (id) { - Range range = wrapper->marker_index.GetRange(*id); + Range range = wrapper->marker_index.get_range(*id); auto result = Nan::New(2); result->Set(0, PointWrapper::FromPoint(range.start)); result->Set(1, PointWrapper::FromPoint(range.end)); @@ -206,101 +206,101 @@ void MarkerIndexWrapper::GetRange(const Nan::FunctionCallbackInfo &info) } } -void MarkerIndexWrapper::Compare(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::compare(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional id1 = MarkerIdFromJS(info[0]); - optional id2 = MarkerIdFromJS(info[1]); + optional id1 = marker_id_from_js(info[0]); + optional id2 = marker_id_from_js(info[1]); if (id1 && id2) { - info.GetReturnValue().Set(wrapper->marker_index.Compare(*id1, *id2)); + info.GetReturnValue().Set(wrapper->marker_index.compare(*id1, *id2)); } } -void MarkerIndexWrapper::FindIntersecting(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::find_intersecting(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); optional start = PointWrapper::PointFromJS(info[0]); optional end = PointWrapper::PointFromJS(info[1]); if (start && end) { - MarkerIndex::MarkerIdSet result = wrapper->marker_index.FindIntersecting(*start, *end); - info.GetReturnValue().Set(MarkerIdsToJS(result)); + MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_intersecting(*start, *end); + info.GetReturnValue().Set(marker_ids_to_js(result)); } } -void MarkerIndexWrapper::FindContaining(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::find_containing(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); optional start = PointWrapper::PointFromJS(info[0]); optional end = PointWrapper::PointFromJS(info[1]); if (start && end) { - MarkerIndex::MarkerIdSet result = wrapper->marker_index.FindContaining(*start, *end); - info.GetReturnValue().Set(MarkerIdsToJS(result)); + MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_containing(*start, *end); + info.GetReturnValue().Set(marker_ids_to_js(result)); } } -void MarkerIndexWrapper::FindContainedIn(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::find_contained_in(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); optional start = PointWrapper::PointFromJS(info[0]); optional end = PointWrapper::PointFromJS(info[1]); if (start && end) { - MarkerIndex::MarkerIdSet result = wrapper->marker_index.FindContainedIn(*start, *end); - info.GetReturnValue().Set(MarkerIdsToJS(result)); + MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_contained_in(*start, *end); + info.GetReturnValue().Set(marker_ids_to_js(result)); } } -void MarkerIndexWrapper::FindStartingIn(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::find_starting_in(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); optional start = PointWrapper::PointFromJS(info[0]); optional end = PointWrapper::PointFromJS(info[1]); if (start && end) { - MarkerIndex::MarkerIdSet result = wrapper->marker_index.FindStartingIn(*start, *end); - info.GetReturnValue().Set(MarkerIdsToJS(result)); + MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_starting_in(*start, *end); + info.GetReturnValue().Set(marker_ids_to_js(result)); } } -void MarkerIndexWrapper::FindStartingAt(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::find_starting_at(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); optional position = PointWrapper::PointFromJS(info[0]); if (position) { - MarkerIndex::MarkerIdSet result = wrapper->marker_index.FindStartingAt(*position); - info.GetReturnValue().Set(MarkerIdsToJS(result)); + MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_starting_at(*position); + info.GetReturnValue().Set(marker_ids_to_js(result)); } } -void MarkerIndexWrapper::FindEndingIn(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::find_ending_in(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); optional start = PointWrapper::PointFromJS(info[0]); optional end = PointWrapper::PointFromJS(info[1]); if (start && end) { - MarkerIndex::MarkerIdSet result = wrapper->marker_index.FindEndingIn(*start, *end); - info.GetReturnValue().Set(MarkerIdsToJS(result)); + MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_ending_in(*start, *end); + info.GetReturnValue().Set(marker_ids_to_js(result)); } } -void MarkerIndexWrapper::FindEndingAt(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::find_ending_at(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); optional position = PointWrapper::PointFromJS(info[0]); if (position) { - MarkerIndex::MarkerIdSet result = wrapper->marker_index.FindEndingAt(*position); - info.GetReturnValue().Set(MarkerIdsToJS(result)); + MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_ending_at(*position); + info.GetReturnValue().Set(marker_ids_to_js(result)); } } -void MarkerIndexWrapper::Dump(const Nan::FunctionCallbackInfo &info) { +void MarkerIndexWrapper::dump(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - unordered_map snapshot = wrapper->marker_index.Dump(); - info.GetReturnValue().Set(SnapshotToJS(snapshot)); + unordered_map snapshot = wrapper->marker_index.dump(); + info.GetReturnValue().Set(snapshot_to_js(snapshot)); } MarkerIndexWrapper::MarkerIndexWrapper(v8::Local seed) diff --git a/src/bindings/marker-index-wrapper.h b/src/bindings/marker-index-wrapper.h index 699567c8..aad8e261 100644 --- a/src/bindings/marker-index-wrapper.h +++ b/src/bindings/marker-index-wrapper.h @@ -5,33 +5,33 @@ class MarkerIndexWrapper : public Nan::ObjectWrap { public: - static void Init(v8::Local exports); + static void init(v8::Local exports); private: - static void New(const Nan::FunctionCallbackInfo &info); - static void GenerateRandomNumber(const Nan::FunctionCallbackInfo &info); - static bool IsFinite(v8::Local number); - static v8::Local MarkerIdsToJS(const MarkerIndex::MarkerIdSet &marker_ids); - static v8::Local SnapshotToJS(const std::unordered_map &snapshot); - static optional MarkerIdFromJS(v8::Local value); - static optional UnsignedFromJS(v8::Local value); - static optional BoolFromJS(v8::Local value); - static void Insert(const Nan::FunctionCallbackInfo &info); - static void SetExclusive(const Nan::FunctionCallbackInfo &info); - static void Delete(const Nan::FunctionCallbackInfo &info); - static void Splice(const Nan::FunctionCallbackInfo &info); - static void GetStart(const Nan::FunctionCallbackInfo &info); - static void GetEnd(const Nan::FunctionCallbackInfo &info); - static void GetRange(const Nan::FunctionCallbackInfo &info); - static void Compare(const Nan::FunctionCallbackInfo &info); - static void FindIntersecting(const Nan::FunctionCallbackInfo &info); - static void FindContaining(const Nan::FunctionCallbackInfo &info); - static void FindContainedIn(const Nan::FunctionCallbackInfo &info); - static void FindStartingIn(const Nan::FunctionCallbackInfo &info); - static void FindStartingAt(const Nan::FunctionCallbackInfo &info); - static void FindEndingIn(const Nan::FunctionCallbackInfo &info); - static void FindEndingAt(const Nan::FunctionCallbackInfo &info); - static void Dump(const Nan::FunctionCallbackInfo &info); + static void construct(const Nan::FunctionCallbackInfo &info); + static void generate_random_number(const Nan::FunctionCallbackInfo &info); + static bool is_finite(v8::Local number); + static v8::Local marker_ids_to_js(const MarkerIndex::MarkerIdSet &marker_ids); + static v8::Local snapshot_to_js(const std::unordered_map &snapshot); + static optional marker_id_from_js(v8::Local value); + static optional unsigned_from_js(v8::Local value); + static optional bool_from_js(v8::Local value); + static void insert(const Nan::FunctionCallbackInfo &info); + static void set_exclusive(const Nan::FunctionCallbackInfo &info); + static void delete_marker(const Nan::FunctionCallbackInfo &info); + static void splice(const Nan::FunctionCallbackInfo &info); + static void get_start(const Nan::FunctionCallbackInfo &info); + static void get_end(const Nan::FunctionCallbackInfo &info); + static void get_range(const Nan::FunctionCallbackInfo &info); + static void compare(const Nan::FunctionCallbackInfo &info); + static void find_intersecting(const Nan::FunctionCallbackInfo &info); + static void find_containing(const Nan::FunctionCallbackInfo &info); + static void find_contained_in(const Nan::FunctionCallbackInfo &info); + static void find_starting_in(const Nan::FunctionCallbackInfo &info); + static void find_starting_at(const Nan::FunctionCallbackInfo &info); + static void find_ending_in(const Nan::FunctionCallbackInfo &info); + static void find_ending_at(const Nan::FunctionCallbackInfo &info); + static void dump(const Nan::FunctionCallbackInfo &info); MarkerIndexWrapper(v8::Local seed); MarkerIndex marker_index; }; diff --git a/src/core/marker-index.cc b/src/core/marker-index.cc index c76d31ef..6f59c2fb 100644 --- a/src/core/marker-index.cc +++ b/src/core/marker-index.cc @@ -15,7 +15,7 @@ MarkerIndex::Node::Node(Node *parent, Point left_extent) : left_extent {left_extent}, priority {0} {} -bool MarkerIndex::Node::IsMarkerEndpoint() { +bool MarkerIndex::Node::is_marker_endpoint() { return (start_marker_ids.size() + end_marker_ids.size()) > 0; } @@ -23,7 +23,7 @@ MarkerIndex::Iterator::Iterator(MarkerIndex *marker_index) : marker_index {marker_index}, current_node {nullptr} {} -void MarkerIndex::Iterator::Reset() { +void MarkerIndex::Iterator::reset() { current_node = marker_index->root; if (current_node) { current_node_position = current_node->left_extent; @@ -34,8 +34,8 @@ void MarkerIndex::Iterator::Reset() { right_ancestor_position_stack.clear(); } -MarkerIndex::Node *MarkerIndex::Iterator::InsertMarkerStart(const MarkerId &id, const Point &start_position, const Point &end_position) { - Reset(); +MarkerIndex::Node *MarkerIndex::Iterator::insert_marker_start(const MarkerId &id, const Point &start_position, const Point &end_position) { + reset(); if (!current_node) { return marker_index->root = new Node(nullptr, start_position); @@ -44,35 +44,35 @@ MarkerIndex::Node *MarkerIndex::Iterator::InsertMarkerStart(const MarkerId &id, while (true) { switch (start_position.Compare(current_node_position)) { case 0: - MarkRight(id, start_position, end_position); + mark_right(id, start_position, end_position); return current_node; case -1: - MarkRight(id, start_position, end_position); + mark_right(id, start_position, end_position); if (current_node->left) { - DescendLeft(); + descend_left(); break; } else { - InsertLeftChild(start_position); - DescendLeft(); - MarkRight(id, start_position, end_position); + insert_left_child(start_position); + descend_left(); + mark_right(id, start_position, end_position); return current_node; } case 1: if (current_node->right) { - DescendRight(); + descend_right(); break; } else { - InsertRightChild(start_position); - DescendRight(); - MarkRight(id, start_position, end_position); + insert_right_child(start_position); + descend_right(); + mark_right(id, start_position, end_position); return current_node; } } } } -MarkerIndex::Node *MarkerIndex::Iterator::InsertMarkerEnd(const MarkerId &id, const Point &start_position, const Point &end_position) { - Reset(); +MarkerIndex::Node *MarkerIndex::Iterator::insert_marker_end(const MarkerId &id, const Point &start_position, const Point &end_position) { + reset(); if (!current_node) { return marker_index->root = new Node(nullptr, end_position); @@ -81,35 +81,35 @@ MarkerIndex::Node *MarkerIndex::Iterator::InsertMarkerEnd(const MarkerId &id, co while (true) { switch (end_position.Compare(current_node_position)) { case 0: - MarkLeft(id, start_position, end_position); + mark_left(id, start_position, end_position); return current_node; case -1: if (current_node->left) { - DescendLeft(); + descend_left(); break; } else { - InsertLeftChild(end_position); - DescendLeft(); - MarkLeft(id, start_position, end_position); + insert_left_child(end_position); + descend_left(); + mark_left(id, start_position, end_position); return current_node; } case 1: - MarkLeft(id, start_position, end_position); + mark_left(id, start_position, end_position); if (current_node->right) { - DescendRight(); + descend_right(); break; } else { - InsertRightChild(end_position); - DescendRight(); - MarkLeft(id, start_position, end_position); + insert_right_child(end_position); + descend_right(); + mark_left(id, start_position, end_position); return current_node; } } } } -MarkerIndex::Node *MarkerIndex::Iterator::InsertSpliceBoundary(const Point &position, bool is_insertion_end) { - Reset(); +MarkerIndex::Node *MarkerIndex::Iterator::insert_splice_boundary(const Point &position, bool is_insertion_end) { + reset(); while (true) { int comparison = position.Compare(current_node_position); @@ -117,40 +117,40 @@ MarkerIndex::Node *MarkerIndex::Iterator::InsertSpliceBoundary(const Point &posi return current_node; } else if (comparison < 0) { if (current_node->left) { - DescendLeft(); + descend_left(); } else { - InsertLeftChild(position); + insert_left_child(position); return current_node->left; } } else { // comparison > 0 if (current_node->right) { - DescendRight(); + descend_right(); } else { - InsertRightChild(position); + insert_right_child(position); return current_node->right; } } } } -void MarkerIndex::Iterator::FindIntersecting(const Point &start, const Point &end, MarkerIdSet *result) { - Reset(); +void MarkerIndex::Iterator::find_intersecting(const Point &start, const Point &end, MarkerIdSet *result) { + reset(); if (!current_node) return; while (true) { - CacheNodePosition(); + cache_node_position(); if (start < current_node_position) { if (current_node->left) { - CheckIntersection(start, end, result); - DescendLeft(); + check_intersection(start, end, result); + descend_left(); } else { break; } } else { if (current_node->right) { - CheckIntersection(start, end, result); - DescendRight(); + check_intersection(start, end, result); + descend_right(); } else { break; } @@ -158,18 +158,18 @@ void MarkerIndex::Iterator::FindIntersecting(const Point &start, const Point &en } do { - CheckIntersection(start, end, result); - MoveToSuccessor(); - CacheNodePosition(); + check_intersection(start, end, result); + move_to_successor(); + cache_node_position(); } while (current_node && current_node_position <= end); } -void MarkerIndex::Iterator::FindContainedIn(const Point &start, const Point &end, MarkerIdSet *result) { - Reset(); +void MarkerIndex::Iterator::find_contained_in(const Point &start, const Point &end, MarkerIdSet *result) { + reset(); if (!current_node) return; - SeekToFirstNodeGreaterThanOrEqualTo(start); + seek_to_first_node_greater_than_or_equal_to(start); MarkerIdSet started; while (current_node && current_node_position <= end) { @@ -177,49 +177,49 @@ void MarkerIndex::Iterator::FindContainedIn(const Point &start, const Point &end for (MarkerId id : current_node->end_marker_ids) { if (started.count(id) > 0) result->insert(id); } - CacheNodePosition(); - MoveToSuccessor(); + cache_node_position(); + move_to_successor(); } } -void MarkerIndex::Iterator::FindStartingIn(const Point &start, const Point &end, MarkerIdSet *result) { - Reset(); +void MarkerIndex::Iterator::find_starting_in(const Point &start, const Point &end, MarkerIdSet *result) { + reset(); if (!current_node) return; - SeekToFirstNodeGreaterThanOrEqualTo(start); + seek_to_first_node_greater_than_or_equal_to(start); while (current_node && current_node_position <= end) { result->insert(current_node->start_marker_ids.begin(), current_node->start_marker_ids.end()); - CacheNodePosition(); - MoveToSuccessor(); + cache_node_position(); + move_to_successor(); } } -void MarkerIndex::Iterator::FindEndingIn(const Point &start, const Point &end, MarkerIdSet *result) { - Reset(); +void MarkerIndex::Iterator::find_ending_in(const Point &start, const Point &end, MarkerIdSet *result) { + reset(); if (!current_node) return; - SeekToFirstNodeGreaterThanOrEqualTo(start); + seek_to_first_node_greater_than_or_equal_to(start); while (current_node && current_node_position <= end) { result->insert(current_node->end_marker_ids.begin(), current_node->end_marker_ids.end()); - CacheNodePosition(); - MoveToSuccessor(); + cache_node_position(); + move_to_successor(); } } -unordered_map MarkerIndex::Iterator::Dump() { - Reset(); +unordered_map MarkerIndex::Iterator::dump() { + reset(); unordered_map snapshot; if (!current_node) return snapshot; while (current_node && current_node->left) { - CacheNodePosition(); - DescendLeft(); + cache_node_position(); + descend_left(); } while (current_node) { @@ -233,14 +233,14 @@ unordered_map MarkerIndex::Iterator::Dump() { snapshot[id].end = current_node_position; } - CacheNodePosition(); - MoveToSuccessor(); + cache_node_position(); + move_to_successor(); } return snapshot; } -void MarkerIndex::Iterator::Ascend() { +void MarkerIndex::Iterator::ascend() { if (current_node->parent) { if (current_node->parent->left == current_node) { current_node_position = right_ancestor_position; @@ -260,7 +260,7 @@ void MarkerIndex::Iterator::Ascend() { } } -void MarkerIndex::Iterator::DescendLeft() { +void MarkerIndex::Iterator::descend_left() { left_ancestor_position_stack.push_back(left_ancestor_position); right_ancestor_position_stack.push_back(right_ancestor_position); @@ -269,7 +269,7 @@ void MarkerIndex::Iterator::DescendLeft() { current_node_position = left_ancestor_position.Traverse(current_node->left_extent); } -void MarkerIndex::Iterator::DescendRight() { +void MarkerIndex::Iterator::descend_right() { left_ancestor_position_stack.push_back(left_ancestor_position); right_ancestor_position_stack.push_back(right_ancestor_position); @@ -278,46 +278,46 @@ void MarkerIndex::Iterator::DescendRight() { current_node_position = left_ancestor_position.Traverse(current_node->left_extent); } -void MarkerIndex::Iterator::MoveToSuccessor() { +void MarkerIndex::Iterator::move_to_successor() { if (!current_node) return; if (current_node->right) { - DescendRight(); + descend_right(); while (current_node->left) { - DescendLeft(); + descend_left(); } } else { while (current_node->parent && current_node->parent->right == current_node) { - Ascend(); + ascend(); } - Ascend(); + ascend(); } } -void MarkerIndex::Iterator::SeekToFirstNodeGreaterThanOrEqualTo(const Point &position) { +void MarkerIndex::Iterator::seek_to_first_node_greater_than_or_equal_to(const Point &position) { while (true) { - CacheNodePosition(); + cache_node_position(); if (position == current_node_position) { break; } else if (position < current_node_position) { if (current_node->left) { - DescendLeft(); + descend_left(); } else { break; } } else { // position > current_node_position if (current_node->right) { - DescendRight(); + descend_right(); } else { break; } } } - if (current_node_position < position) MoveToSuccessor(); + if (current_node_position < position) move_to_successor(); } -void MarkerIndex::Iterator::MarkRight(const MarkerId &id, const Point &start_position, const Point &end_position) { +void MarkerIndex::Iterator::mark_right(const MarkerId &id, const Point &start_position, const Point &end_position) { if (left_ancestor_position < start_position && start_position <= current_node_position && right_ancestor_position <= end_position) { @@ -325,21 +325,21 @@ void MarkerIndex::Iterator::MarkRight(const MarkerId &id, const Point &start_pos } } -void MarkerIndex::Iterator::MarkLeft(const MarkerId &id, const Point &start_position, const Point &end_position) { +void MarkerIndex::Iterator::mark_left(const MarkerId &id, const Point &start_position, const Point &end_position) { if (!current_node_position.IsZero() && start_position <= left_ancestor_position && current_node_position <= end_position) { current_node->left_marker_ids.insert(id); } } -MarkerIndex::Node *MarkerIndex::Iterator::InsertLeftChild(const Point &position) { +MarkerIndex::Node *MarkerIndex::Iterator::insert_left_child(const Point &position) { return current_node->left = new Node(current_node, position.Traversal(left_ancestor_position)); } -MarkerIndex::Node *MarkerIndex::Iterator::InsertRightChild(const Point &position) { +MarkerIndex::Node *MarkerIndex::Iterator::insert_right_child(const Point &position) { return current_node->right = new Node(current_node, position.Traversal(current_node_position)); } -void MarkerIndex::Iterator::CheckIntersection(const Point &start, const Point &end, MarkerIdSet *result) { +void MarkerIndex::Iterator::check_intersection(const Point &start, const Point &end, MarkerIdSet *result) { if (left_ancestor_position <= end && start <= current_node_position) { result->insert(current_node->left_marker_ids.begin(), current_node->left_marker_ids.end()); } @@ -354,7 +354,7 @@ void MarkerIndex::Iterator::CheckIntersection(const Point &start, const Point &e } } -void MarkerIndex::Iterator::CacheNodePosition() const { +void MarkerIndex::Iterator::cache_node_position() const { marker_index->node_position_cache.insert({current_node, current_node_position}); } @@ -365,16 +365,16 @@ MarkerIndex::MarkerIndex(unsigned seed) iterator {this} {} MarkerIndex::~MarkerIndex() { - if (root) DeleteSubtree(root); + if (root) delete_subtree(root); } -int MarkerIndex::GenerateRandomNumber() { +int MarkerIndex::generate_random_number() { return random_distribution(random_engine); } -void MarkerIndex::Insert(MarkerId id, Point start, Point end) { - Node *start_node = iterator.InsertMarkerStart(id, start, end); - Node *end_node = iterator.InsertMarkerEnd(id, start, end); +void MarkerIndex::insert(MarkerId id, Point start, Point end) { + Node *start_node = iterator.insert_marker_start(id, start, end); + Node *end_node = iterator.insert_marker_end(id, start, end); node_position_cache.insert({start_node, start}); node_position_cache.insert({end_node, end}); @@ -383,20 +383,20 @@ void MarkerIndex::Insert(MarkerId id, Point start, Point end) { end_node->end_marker_ids.insert(id); if (start_node->priority == 0) { - start_node->priority = GenerateRandomNumber(); - BubbleNodeUp(start_node); + start_node->priority = generate_random_number(); + bubble_node_up(start_node); } if (end_node->priority == 0) { - end_node->priority = GenerateRandomNumber(); - BubbleNodeUp(end_node); + end_node->priority = generate_random_number(); + bubble_node_up(end_node); } start_nodes_by_id.insert({id, start_node}); end_nodes_by_id.insert({id, end_node}); } -void MarkerIndex::SetExclusive(MarkerId id, bool exclusive) { +void MarkerIndex::set_exclusive(MarkerId id, bool exclusive) { if (exclusive) { exclusive_marker_ids.insert(id); } else { @@ -404,7 +404,7 @@ void MarkerIndex::SetExclusive(MarkerId id, bool exclusive) { } } -void MarkerIndex::Delete(MarkerId id) { +void MarkerIndex::delete_marker(MarkerId id) { Node *start_node = start_nodes_by_id.find(id)->second; Node *end_node = end_nodes_by_id.find(id)->second; @@ -423,19 +423,19 @@ void MarkerIndex::Delete(MarkerId id) { start_node->start_marker_ids.erase(id); end_node->end_marker_ids.erase(id); - if (!start_node->IsMarkerEndpoint()) { - DeleteNode(start_node); + if (!start_node->is_marker_endpoint()) { + delete_node(start_node); } - if (end_node != start_node && !end_node->IsMarkerEndpoint()) { - DeleteNode(end_node); + if (end_node != start_node && !end_node->is_marker_endpoint()) { + delete_node(end_node); } start_nodes_by_id.erase(id); end_nodes_by_id.erase(id); } -MarkerIndex::SpliceResult MarkerIndex::Splice(Point start, Point old_extent, Point new_extent) { +MarkerIndex::SpliceResult MarkerIndex::splice(Point start, Point old_extent, Point new_extent) { node_position_cache.clear(); SpliceResult invalidated; @@ -443,13 +443,13 @@ MarkerIndex::SpliceResult MarkerIndex::Splice(Point start, Point old_extent, Poi if (!root || (old_extent.IsZero() && new_extent.IsZero())) return invalidated; bool is_insertion = old_extent.IsZero(); - Node *start_node = iterator.InsertSpliceBoundary(start, false); - Node *end_node = iterator.InsertSpliceBoundary(start.Traverse(old_extent), is_insertion); + Node *start_node = iterator.insert_splice_boundary(start, false); + Node *end_node = iterator.insert_splice_boundary(start.Traverse(old_extent), is_insertion); start_node->priority = -1; - BubbleNodeUp(start_node); + bubble_node_up(start_node); end_node->priority = -2; - BubbleNodeUp(end_node); + bubble_node_up(end_node); MarkerIdSet starting_inside_splice; MarkerIdSet ending_inside_splice; @@ -480,7 +480,7 @@ MarkerIndex::SpliceResult MarkerIndex::Splice(Point start, Point old_extent, Poi } } } else { - GetStartingAndEndingMarkersWithinSubtree(start_node->right, &starting_inside_splice, &ending_inside_splice); + get_starting_and_ending_markers_within_subtree(start_node->right, &starting_inside_splice, &ending_inside_splice); for (MarkerId id : ending_inside_splice) { end_node->end_marker_ids.insert(id); @@ -515,10 +515,10 @@ MarkerIndex::SpliceResult MarkerIndex::Splice(Point start, Point old_extent, Poi } } - PopulateSpliceInvalidationSets(&invalidated, start_node, end_node, starting_inside_splice, ending_inside_splice); + populate_splice_invalidation_sets(&invalidated, start_node, end_node, starting_inside_splice, ending_inside_splice); if (start_node->right) { - DeleteSubtree(start_node->right); + delete_subtree(start_node->right); start_node->right = nullptr; } @@ -539,69 +539,69 @@ MarkerIndex::SpliceResult MarkerIndex::Splice(Point start, Point old_extent, Poi } end_nodes_by_id[id] = start_node; } - DeleteNode(end_node); - } else if (end_node->IsMarkerEndpoint()) { - end_node->priority = GenerateRandomNumber(); + delete_node(end_node); + } else if (end_node->is_marker_endpoint()) { + end_node->priority = generate_random_number(); bubble_node_down(end_node); } else { - DeleteNode(end_node); + delete_node(end_node); } - if (start_node->IsMarkerEndpoint()) { - start_node->priority = GenerateRandomNumber(); + if (start_node->is_marker_endpoint()) { + start_node->priority = generate_random_number(); bubble_node_down(start_node); } else { - DeleteNode(start_node); + delete_node(start_node); } return invalidated; } -Point MarkerIndex::GetStart(MarkerId id) const { +Point MarkerIndex::get_start(MarkerId id) const { auto result = start_nodes_by_id.find(id); if (result == start_nodes_by_id.end()) return Point(); else - return GetNodePosition(result->second); + return get_node_position(result->second); } -Point MarkerIndex::GetEnd(MarkerId id) const { +Point MarkerIndex::get_end(MarkerId id) const { auto result = end_nodes_by_id.find(id); if (result == end_nodes_by_id.end()) return Point(); else - return GetNodePosition(result->second); + return get_node_position(result->second); } -Range MarkerIndex::GetRange(MarkerId id) const { - return Range{GetStart(id), GetEnd(id)}; +Range MarkerIndex::get_range(MarkerId id) const { + return Range{get_start(id), get_end(id)}; } -int MarkerIndex::Compare(MarkerId id1, MarkerId id2) const { - switch (GetStart(id1).Compare(GetStart(id2))) { +int MarkerIndex::compare(MarkerId id1, MarkerId id2) const { + switch (get_start(id1).Compare(get_start(id2))) { case -1: return -1; case 1: return 1; default: - return GetEnd(id2).Compare(GetEnd(id1)); + return get_end(id2).Compare(get_end(id1)); } } -flat_set MarkerIndex::FindIntersecting(Point start, Point end) { +flat_set MarkerIndex::find_intersecting(Point start, Point end) { MarkerIdSet result; - iterator.FindIntersecting(start, end, &result); + iterator.find_intersecting(start, end, &result); return result; } -flat_set MarkerIndex::FindContaining(Point start, Point end) { +flat_set MarkerIndex::find_containing(Point start, Point end) { MarkerIdSet containing_start; - iterator.FindIntersecting(start, start, &containing_start); + iterator.find_intersecting(start, start, &containing_start); if (end == start) { return containing_start; } else { MarkerIdSet containing_end; - iterator.FindIntersecting(end, end, &containing_end); + iterator.find_intersecting(end, end, &containing_end); MarkerIdSet containing_start_and_end; for (MarkerId id : containing_start) { if (containing_end.count(id) > 0) { @@ -612,37 +612,37 @@ flat_set MarkerIndex::FindContaining(Point start, Point e } } -flat_set MarkerIndex::FindContainedIn(Point start, Point end) { +flat_set MarkerIndex::find_contained_in(Point start, Point end) { MarkerIdSet result; - iterator.FindContainedIn(start, end, &result); + iterator.find_contained_in(start, end, &result); return result; } -flat_set MarkerIndex::FindStartingIn(Point start, Point end) { +flat_set MarkerIndex::find_starting_in(Point start, Point end) { MarkerIdSet result; - iterator.FindStartingIn(start, end, &result); + iterator.find_starting_in(start, end, &result); return result; } -flat_set MarkerIndex::FindStartingAt(Point position) { - return FindStartingIn(position, position); +flat_set MarkerIndex::find_starting_at(Point position) { + return find_starting_in(position, position); } -flat_set MarkerIndex::FindEndingIn(Point start, Point end) { +flat_set MarkerIndex::find_ending_in(Point start, Point end) { MarkerIdSet result; - iterator.FindEndingIn(start, end, &result); + iterator.find_ending_in(start, end, &result); return result; } -flat_set MarkerIndex::FindEndingAt(Point position) { - return FindEndingIn(position, position); +flat_set MarkerIndex::find_ending_at(Point position) { + return find_ending_in(position, position); } -unordered_map MarkerIndex::Dump() { - return iterator.Dump(); +unordered_map MarkerIndex::dump() { + return iterator.dump(); } -Point MarkerIndex::GetNodePosition(const Node *node) const { +Point MarkerIndex::get_node_position(const Node *node) const { auto cache_entry = node_position_cache.find(node); if (cache_entry == node_position_cache.end()) { Point position = node->left_extent; @@ -661,7 +661,7 @@ Point MarkerIndex::GetNodePosition(const Node *node) const { } } -void MarkerIndex::DeleteNode(Node *node) { +void MarkerIndex::delete_node(Node *node) { node_position_cache.erase(node); node->priority = INT_MAX; @@ -680,18 +680,18 @@ void MarkerIndex::DeleteNode(Node *node) { delete node; } -void MarkerIndex::DeleteSubtree(Node *node) { - if (node->left) DeleteSubtree(node->left); - if (node->right) DeleteSubtree(node->right); +void MarkerIndex::delete_subtree(Node *node) { + if (node->left) delete_subtree(node->left); + if (node->right) delete_subtree(node->right); delete node; } -void MarkerIndex::BubbleNodeUp(Node *node) { +void MarkerIndex::bubble_node_up(Node *node) { while (node->parent && node->priority < node->parent->priority) { if (node == node->parent->left) { - RotateNodeRight(node); + rotate_node_right(node); } else { - RotateNodeLeft(node); + rotate_node_left(node); } } } @@ -702,16 +702,16 @@ void MarkerIndex::bubble_node_down(Node *node) { int right_child_priority = (node->right) ? node->right->priority : INT_MAX; if (left_child_priority < right_child_priority && left_child_priority < node->priority) { - RotateNodeRight(node->left); + rotate_node_right(node->left); } else if (right_child_priority < node->priority) { - RotateNodeLeft(node->right); + rotate_node_left(node->right); } else { break; } } } -void MarkerIndex::RotateNodeLeft(Node *rotation_pivot) { +void MarkerIndex::rotate_node_left(Node *rotation_pivot) { Node *rotation_root = rotation_pivot->parent; if (rotation_root->parent) { @@ -748,7 +748,7 @@ void MarkerIndex::RotateNodeLeft(Node *rotation_pivot) { } } -void MarkerIndex::RotateNodeRight(Node *rotation_pivot) { +void MarkerIndex::rotate_node_right(Node *rotation_pivot) { Node *rotation_root = rotation_pivot->parent; if (rotation_root->parent) { @@ -789,18 +789,18 @@ void MarkerIndex::RotateNodeRight(Node *rotation_pivot) { } } -void MarkerIndex::GetStartingAndEndingMarkersWithinSubtree(const Node *node, MarkerIdSet *starting, MarkerIdSet *ending) { +void MarkerIndex::get_starting_and_ending_markers_within_subtree(const Node *node, MarkerIdSet *starting, MarkerIdSet *ending) { if (node == nullptr) { return; } - GetStartingAndEndingMarkersWithinSubtree(node->left, starting, ending); + get_starting_and_ending_markers_within_subtree(node->left, starting, ending); starting->insert(node->start_marker_ids.begin(), node->start_marker_ids.end()); ending->insert(node->end_marker_ids.begin(), node->end_marker_ids.end()); - GetStartingAndEndingMarkersWithinSubtree(node->right, starting, ending); + get_starting_and_ending_markers_within_subtree(node->right, starting, ending); } -void MarkerIndex::PopulateSpliceInvalidationSets(SpliceResult *invalidated, const Node *start_node, const Node *end_node, const MarkerIdSet &starting_inside_splice, const MarkerIdSet &ending_inside_splice) { +void MarkerIndex::populate_splice_invalidation_sets(SpliceResult *invalidated, const Node *start_node, const Node *end_node, const MarkerIdSet &starting_inside_splice, const MarkerIdSet &ending_inside_splice) { invalidated->touch.insert(start_node->end_marker_ids.begin(), start_node->end_marker_ids.end()); invalidated->touch.insert(end_node->start_marker_ids.begin(), end_node->start_marker_ids.end()); diff --git a/src/core/marker-index.h b/src/core/marker-index.h index 7ef8f350..14f4cc74 100644 --- a/src/core/marker-index.h +++ b/src/core/marker-index.h @@ -21,25 +21,25 @@ class MarkerIndex { MarkerIndex(unsigned seed); ~MarkerIndex(); - int GenerateRandomNumber(); - void Insert(MarkerId id, Point start, Point end); - void SetExclusive(MarkerId id, bool exclusive); - void Delete(MarkerId id); - SpliceResult Splice(Point start, Point old_extent, Point new_extent); - Point GetStart(MarkerId id) const; - Point GetEnd(MarkerId id) const; - Range GetRange(MarkerId id) const; + int generate_random_number(); + void insert(MarkerId id, Point start, Point end); + void set_exclusive(MarkerId id, bool exclusive); + void delete_marker(MarkerId id); + SpliceResult splice(Point start, Point old_extent, Point new_extent); + Point get_start(MarkerId id) const; + Point get_end(MarkerId id) const; + Range get_range(MarkerId id) const; - int Compare(MarkerId id1, MarkerId id2) const; - flat_set FindIntersecting(Point start, Point end); - flat_set FindContaining(Point start, Point end); - flat_set FindContainedIn(Point start, Point end); - flat_set FindStartingIn(Point start, Point end); - flat_set FindStartingAt(Point position); - flat_set FindEndingIn(Point start, Point end); - flat_set FindEndingAt(Point position); + int compare(MarkerId id1, MarkerId id2) const; + flat_set find_intersecting(Point start, Point end); + flat_set find_containing(Point start, Point end); + flat_set find_contained_in(Point start, Point end); + flat_set find_starting_in(Point start, Point end); + flat_set find_starting_at(Point position); + flat_set find_ending_in(Point start, Point end); + flat_set find_ending_at(Point position); - std::unordered_map Dump(); + std::unordered_map dump(); private: friend class Iterator; @@ -56,34 +56,34 @@ class MarkerIndex { int priority; Node(Node *parent, Point left_extent); - bool IsMarkerEndpoint(); + bool is_marker_endpoint(); }; class Iterator { public: Iterator(MarkerIndex *marker_index); - void Reset(); - Node* InsertMarkerStart(const MarkerId &id, const Point &start_position, const Point &end_position); - Node* InsertMarkerEnd(const MarkerId &id, const Point &start_position, const Point &end_position); - Node* InsertSpliceBoundary(const Point &position, bool is_insertion_end); - void FindIntersecting(const Point &start, const Point &end, flat_set *result); - void FindContainedIn(const Point &start, const Point &end, flat_set *result); - void FindStartingIn(const Point &start, const Point &end, flat_set *result); - void FindEndingIn(const Point &start, const Point &end, flat_set *result); - std::unordered_map Dump(); + void reset(); + Node* insert_marker_start(const MarkerId &id, const Point &start_position, const Point &end_position); + Node* insert_marker_end(const MarkerId &id, const Point &start_position, const Point &end_position); + Node* insert_splice_boundary(const Point &position, bool is_insertion_end); + void find_intersecting(const Point &start, const Point &end, flat_set *result); + void find_contained_in(const Point &start, const Point &end, flat_set *result); + void find_starting_in(const Point &start, const Point &end, flat_set *result); + void find_ending_in(const Point &start, const Point &end, flat_set *result); + std::unordered_map dump(); private: - void Ascend(); - void DescendLeft(); - void DescendRight(); - void MoveToSuccessor(); - void SeekToFirstNodeGreaterThanOrEqualTo(const Point &position); - void MarkRight(const MarkerId &id, const Point &start_position, const Point &end_position); - void MarkLeft(const MarkerId &id, const Point &start_position, const Point &end_position); - Node* InsertLeftChild(const Point &position); - Node* InsertRightChild(const Point &position); - void CheckIntersection(const Point &start, const Point &end, flat_set *results); - void CacheNodePosition() const; + void ascend(); + void descend_left(); + void descend_right(); + void move_to_successor(); + void seek_to_first_node_greater_than_or_equal_to(const Point &position); + void mark_right(const MarkerId &id, const Point &start_position, const Point &end_position); + void mark_left(const MarkerId &id, const Point &start_position, const Point &end_position); + Node* insert_left_child(const Point &position); + Node* insert_right_child(const Point &position); + void check_intersection(const Point &start, const Point &end, flat_set *results); + void cache_node_position() const; MarkerIndex *marker_index; Node *current_node; @@ -94,15 +94,15 @@ class MarkerIndex { std::vector right_ancestor_position_stack; }; - Point GetNodePosition(const Node *node) const; - void DeleteNode(Node *node); - void DeleteSubtree(Node *node); - void BubbleNodeUp(Node *node); + Point get_node_position(const Node *node) const; + void delete_node(Node *node); + void delete_subtree(Node *node); + void bubble_node_up(Node *node); void bubble_node_down(Node *node); - void RotateNodeLeft(Node *pivot); - void RotateNodeRight(Node *pivot); - void GetStartingAndEndingMarkersWithinSubtree(const Node *node, flat_set *starting, flat_set *ending); - void PopulateSpliceInvalidationSets(SpliceResult *invalidated, const Node *start_node, const Node *end_node, const flat_set &starting_inside_splice, const flat_set &ending_inside_splice); + void rotate_node_left(Node *pivot); + void rotate_node_right(Node *pivot); + void get_starting_and_ending_markers_within_subtree(const Node *node, flat_set *starting, flat_set *ending); + void populate_splice_invalidation_sets(SpliceResult *invalidated, const Node *start_node, const Node *end_node, const flat_set &starting_inside_splice, const flat_set &ending_inside_splice); std::default_random_engine random_engine; std::uniform_int_distribution random_distribution; From d283bd3b14d2bfa78e2d59bea1297f80aa4f9eb3 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 15 Jan 2017 07:38:08 -0700 Subject: [PATCH 3/8] Convert Patch to new naming convention --- src/bindings/bindings.cc | 2 +- src/bindings/patch-wrapper.cc | 150 ++++++++-------- src/bindings/patch-wrapper.h | 36 ++-- src/core/patch.cc | 318 +++++++++++++++++----------------- src/core/patch.h | 62 +++---- 5 files changed, 284 insertions(+), 284 deletions(-) diff --git a/src/bindings/bindings.cc b/src/bindings/bindings.cc index de28205c..4ebbeca0 100644 --- a/src/bindings/bindings.cc +++ b/src/bindings/bindings.cc @@ -8,7 +8,7 @@ using namespace v8; void Init(Local exports) { PointWrapper::Init(); - PatchWrapper::Init(exports); + PatchWrapper::init(exports); MarkerIndexWrapper::init(exports); BufferOffsetIndexWrapper::init(exports); } diff --git a/src/bindings/patch-wrapper.cc b/src/bindings/patch-wrapper.cc index 31c75944..a77a26fb 100644 --- a/src/bindings/patch-wrapper.cc +++ b/src/bindings/patch-wrapper.cc @@ -14,7 +14,7 @@ static Nan::Persistent hunk_wrapper_constructor; static Nan::Persistent patch_wrapper_constructor_template; static Nan::Persistent patch_wrapper_constructor; -static unique_ptr TextFromJS(Nan::MaybeLocal maybe_string) { +static unique_ptr text_from_js(Nan::MaybeLocal maybe_string) { Local string; if (!maybe_string.ToLocal(&string)) { Nan::ThrowTypeError("Expected a string."); @@ -26,36 +26,36 @@ static unique_ptr TextFromJS(Nan::MaybeLocal maybe_string) { return text; } -static Local TextToJS(Text *text) { +static Local text_to_js(Text *text) { return Nan::New(text->data(), text->size()).ToLocalChecked(); } class HunkWrapper : public Nan::ObjectWrap { public: - static void Init() { + static void init() { new_text_string.Reset(Nan::New("newText").ToLocalChecked()); old_text_string.Reset(Nan::New("oldText").ToLocalChecked()); static Nan::Persistent old_text_string; - Local constructor_template = Nan::New(New); + Local constructor_template = Nan::New(construct); constructor_template->SetClassName(Nan::New("Hunk").ToLocalChecked()); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); const auto &instance_template = constructor_template->InstanceTemplate(); - Nan::SetAccessor(instance_template, Nan::New("oldStart").ToLocalChecked(), GetOldStart); - Nan::SetAccessor(instance_template, Nan::New("newStart").ToLocalChecked(), GetNewStart); - Nan::SetAccessor(instance_template, Nan::New("oldEnd").ToLocalChecked(), GetOldEnd); - Nan::SetAccessor(instance_template, Nan::New("newEnd").ToLocalChecked(), GetNewEnd); + Nan::SetAccessor(instance_template, Nan::New("oldStart").ToLocalChecked(), get_old_start); + Nan::SetAccessor(instance_template, Nan::New("newStart").ToLocalChecked(), get_new_start); + Nan::SetAccessor(instance_template, Nan::New("oldEnd").ToLocalChecked(), get_old_end); + Nan::SetAccessor(instance_template, Nan::New("newEnd").ToLocalChecked(), get_new_end); // Non-enumerable legacy properties for backward compatibility - Nan::SetAccessor(instance_template, Nan::New("start").ToLocalChecked(), GetNewStart, nullptr, Handle(), + Nan::SetAccessor(instance_template, Nan::New("start").ToLocalChecked(), get_new_start, nullptr, Handle(), AccessControl::DEFAULT, PropertyAttribute::DontEnum); - Nan::SetAccessor(instance_template, Nan::New("oldExtent").ToLocalChecked(), GetOldExtent, nullptr, Handle(), + Nan::SetAccessor(instance_template, Nan::New("oldExtent").ToLocalChecked(), get_old_extent, nullptr, Handle(), AccessControl::DEFAULT, PropertyAttribute::DontEnum); - Nan::SetAccessor(instance_template, Nan::New("newExtent").ToLocalChecked(), GetNewExtent, nullptr, Handle(), + Nan::SetAccessor(instance_template, Nan::New("newExtent").ToLocalChecked(), get_new_extent, nullptr, Handle(), AccessControl::DEFAULT, PropertyAttribute::DontEnum); const auto &prototype_template = constructor_template->PrototypeTemplate(); - prototype_template->Set(Nan::New("toString").ToLocalChecked(), Nan::New(ToString)); + prototype_template->Set(Nan::New("toString").ToLocalChecked(), Nan::New(to_string)); hunk_wrapper_constructor.Reset(constructor_template->GetFunction()); } @@ -64,10 +64,10 @@ class HunkWrapper : public Nan::ObjectWrap { if (Nan::NewInstance(Nan::New(hunk_wrapper_constructor)).ToLocal(&result)) { (new HunkWrapper(hunk))->Wrap(result); if (hunk.new_text) { - result->Set(Nan::New(new_text_string), TextToJS(hunk.new_text)); + result->Set(Nan::New(new_text_string), text_to_js(hunk.new_text)); } if (hunk.old_text) { - result->Set(Nan::New(old_text_string), TextToJS(hunk.old_text)); + result->Set(Nan::New(old_text_string), text_to_js(hunk.old_text)); } return result; } else { @@ -78,39 +78,39 @@ class HunkWrapper : public Nan::ObjectWrap { private: HunkWrapper(Patch::Hunk hunk) : hunk(hunk) {} - static void New(const Nan::FunctionCallbackInfo &info) {} + static void construct(const Nan::FunctionCallbackInfo &info) {} - static void GetOldStart(v8::Local property, const Nan::PropertyCallbackInfo &info) { + static void get_old_start(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.old_start)); } - static void GetNewStart(v8::Local property, const Nan::PropertyCallbackInfo &info) { + static void get_new_start(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.new_start)); } - static void GetOldEnd(v8::Local property, const Nan::PropertyCallbackInfo &info) { + static void get_old_end(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.old_end)); } - static void GetNewEnd(v8::Local property, const Nan::PropertyCallbackInfo &info) { + static void get_new_end(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.new_end)); } - static void GetOldExtent(v8::Local property, const Nan::PropertyCallbackInfo &info) { + static void get_old_extent(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.old_end.Traversal(hunk.old_start))); } - static void GetNewExtent(v8::Local property, const Nan::PropertyCallbackInfo &info) { + static void get_new_extent(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.new_end.Traversal(hunk.new_start))); } - static void ToString(const Nan::FunctionCallbackInfo &info) { + static void to_string(const Nan::FunctionCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; std::stringstream result; result << hunk; @@ -120,33 +120,33 @@ class HunkWrapper : public Nan::ObjectWrap { Patch::Hunk hunk; }; -void PatchWrapper::Init(Local exports) { - HunkWrapper::Init(); +void PatchWrapper::init(Local exports) { + HunkWrapper::init(); - Local constructor_template_local = Nan::New(New); + Local constructor_template_local = Nan::New(construct); constructor_template_local->SetClassName(Nan::New("Patch").ToLocalChecked()); - constructor_template_local->Set(Nan::New("deserialize").ToLocalChecked(), Nan::New(Deserialize)); - constructor_template_local->Set(Nan::New("compose").ToLocalChecked(), Nan::New(Compose)); + constructor_template_local->Set(Nan::New("deserialize").ToLocalChecked(), Nan::New(deserialize)); + constructor_template_local->Set(Nan::New("compose").ToLocalChecked(), Nan::New(compose)); constructor_template_local->InstanceTemplate()->SetInternalFieldCount(1); const auto &prototype_template = constructor_template_local->PrototypeTemplate(); - prototype_template->Set(Nan::New("splice").ToLocalChecked(), Nan::New(Splice)); - prototype_template->Set(Nan::New("spliceOld").ToLocalChecked(), Nan::New(SpliceOld)); - prototype_template->Set(Nan::New("copy").ToLocalChecked(), Nan::New(Copy)); - prototype_template->Set(Nan::New("invert").ToLocalChecked(), Nan::New(Invert)); - prototype_template->Set(Nan::New("getHunks").ToLocalChecked(), Nan::New(GetHunks)); + prototype_template->Set(Nan::New("splice").ToLocalChecked(), Nan::New(splice)); + prototype_template->Set(Nan::New("spliceOld").ToLocalChecked(), Nan::New(splice_old)); + prototype_template->Set(Nan::New("copy").ToLocalChecked(), Nan::New(copy)); + prototype_template->Set(Nan::New("invert").ToLocalChecked(), Nan::New(invert)); + prototype_template->Set(Nan::New("getHunks").ToLocalChecked(), Nan::New(get_hunks)); prototype_template->Set(Nan::New("getHunksInOldRange").ToLocalChecked(), - Nan::New(GetHunksInOldRange)); + Nan::New(get_hunks_in_old_range)); prototype_template->Set(Nan::New("getHunksInNewRange").ToLocalChecked(), - Nan::New(GetHunksInNewRange)); + Nan::New(get_hunks_in_new_range)); prototype_template->Set(Nan::New("hunkForOldPosition").ToLocalChecked(), - Nan::New(HunkForOldPosition)); + Nan::New(hunk_for_old_position)); prototype_template->Set(Nan::New("hunkForNewPosition").ToLocalChecked(), - Nan::New(HunkForNewPosition)); - prototype_template->Set(Nan::New("serialize").ToLocalChecked(), Nan::New(Serialize)); - prototype_template->Set(Nan::New("getDotGraph").ToLocalChecked(), Nan::New(GetDotGraph)); - prototype_template->Set(Nan::New("getJSON").ToLocalChecked(), Nan::New(GetJSON)); - prototype_template->Set(Nan::New("rebalance").ToLocalChecked(), Nan::New(Rebalance)); - prototype_template->Set(Nan::New("getHunkCount").ToLocalChecked(), Nan::New(GetHunkCount)); + Nan::New(hunk_for_new_position)); + prototype_template->Set(Nan::New("serialize").ToLocalChecked(), Nan::New(serialize)); + prototype_template->Set(Nan::New("getDotGraph").ToLocalChecked(), Nan::New(get_dot_graph)); + prototype_template->Set(Nan::New("getJSON").ToLocalChecked(), Nan::New(get_json)); + prototype_template->Set(Nan::New("rebalance").ToLocalChecked(), Nan::New(rebalance)); + prototype_template->Set(Nan::New("getHunkCount").ToLocalChecked(), Nan::New(get_hunk_count)); patch_wrapper_constructor_template.Reset(constructor_template_local); patch_wrapper_constructor.Reset(constructor_template_local->GetFunction()); exports->Set(Nan::New("Patch").ToLocalChecked(), Nan::New(patch_wrapper_constructor)); @@ -154,7 +154,7 @@ void PatchWrapper::Init(Local exports) { PatchWrapper::PatchWrapper(Patch &&patch) : patch{std::move(patch)} {} -void PatchWrapper::New(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::construct(const Nan::FunctionCallbackInfo &info) { bool merges_adjacent_hunks = true; Local options; @@ -169,7 +169,7 @@ void PatchWrapper::New(const Nan::FunctionCallbackInfo &info) { patch->Wrap(info.This()); } -void PatchWrapper::Splice(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::splice(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; optional start = PointWrapper::PointFromJS(info[0]); @@ -181,23 +181,23 @@ void PatchWrapper::Splice(const Nan::FunctionCallbackInfo &info) { unique_ptr inserted_text; if (info.Length() >= 4) { - deleted_text = TextFromJS(Nan::To(info[3])); + deleted_text = text_from_js(Nan::To(info[3])); if (!deleted_text) return; } if (info.Length() >= 5) { - inserted_text = TextFromJS(Nan::To(info[4])); + inserted_text = text_from_js(Nan::To(info[4])); if (!inserted_text) return; } - if (!patch.Splice(*start, *deletion_extent, *insertion_extent, move(deleted_text), + if (!patch.splice(*start, *deletion_extent, *insertion_extent, move(deleted_text), move(inserted_text))) { Nan::ThrowError("Can't splice into a frozen patch"); } } } -void PatchWrapper::SpliceOld(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::splice_old(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; optional start = PointWrapper::PointFromJS(info[0]); @@ -205,46 +205,46 @@ void PatchWrapper::SpliceOld(const Nan::FunctionCallbackInfo &info) { optional insertion_extent = PointWrapper::PointFromJS(info[2]); if (start && deletion_extent && insertion_extent) { - if (!patch.SpliceOld(*start, *deletion_extent, *insertion_extent)) { - Nan::ThrowError("Can't spliceOld into a frozen patch"); + if (!patch.splice_old(*start, *deletion_extent, *insertion_extent)) { + Nan::ThrowError("Can't splice_old into a frozen patch"); } } } -void PatchWrapper::Copy(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::copy(const Nan::FunctionCallbackInfo &info) { Local result; if (Nan::NewInstance(Nan::New(patch_wrapper_constructor)).ToLocal(&result)) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - auto wrapper = new PatchWrapper{patch.Copy()}; + auto wrapper = new PatchWrapper{patch.copy()}; wrapper->Wrap(result); info.GetReturnValue().Set(result); } } -void PatchWrapper::Invert(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::invert(const Nan::FunctionCallbackInfo &info) { Local result; if (Nan::NewInstance(Nan::New(patch_wrapper_constructor)).ToLocal(&result)) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - auto wrapper = new PatchWrapper{patch.Invert()}; + auto wrapper = new PatchWrapper{patch.invert()}; wrapper->Wrap(result); info.GetReturnValue().Set(result); } } -void PatchWrapper::GetHunks(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::get_hunks(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; Local js_result = Nan::New(); size_t i = 0; - for (auto hunk : patch.GetHunks()) { + for (auto hunk : patch.get_hunks()) { js_result->Set(i++, HunkWrapper::FromHunk(hunk)); } info.GetReturnValue().Set(js_result); } -void PatchWrapper::GetHunksInOldRange(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::get_hunks_in_old_range(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; optional start = PointWrapper::PointFromJS(info[0]); @@ -254,7 +254,7 @@ void PatchWrapper::GetHunksInOldRange(const Nan::FunctionCallbackInfo &in Local js_result = Nan::New(); size_t i = 0; - for (auto hunk : patch.GetHunksInOldRange(*start, *end)) { + for (auto hunk : patch.get_hunks_in_old_range(*start, *end)) { js_result->Set(i++, HunkWrapper::FromHunk(hunk)); } @@ -262,7 +262,7 @@ void PatchWrapper::GetHunksInOldRange(const Nan::FunctionCallbackInfo &in } } -void PatchWrapper::GetHunksInNewRange(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::get_hunks_in_new_range(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; optional start = PointWrapper::PointFromJS(info[0]); @@ -272,7 +272,7 @@ void PatchWrapper::GetHunksInNewRange(const Nan::FunctionCallbackInfo &in Local js_result = Nan::New(); size_t i = 0; - for (auto hunk : patch.GetHunksInNewRange(*start, *end)) { + for (auto hunk : patch.get_hunks_in_new_range(*start, *end)) { js_result->Set(i++, HunkWrapper::FromHunk(hunk)); } @@ -280,11 +280,11 @@ void PatchWrapper::GetHunksInNewRange(const Nan::FunctionCallbackInfo &in } } -void PatchWrapper::HunkForOldPosition(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::hunk_for_old_position(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; optional start = PointWrapper::PointFromJS(info[0]); if (start) { - auto hunk = patch.HunkForOldPosition(*start); + auto hunk = patch.hunk_for_old_position(*start); if (hunk) { info.GetReturnValue().Set(HunkWrapper::FromHunk(*hunk)); } else { @@ -293,11 +293,11 @@ void PatchWrapper::HunkForOldPosition(const Nan::FunctionCallbackInfo &in } } -void PatchWrapper::HunkForNewPosition(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::hunk_for_new_position(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; optional start = PointWrapper::PointFromJS(info[0]); if (start) { - auto hunk = patch.HunkForNewPosition(*start); + auto hunk = patch.hunk_for_new_position(*start); if (hunk) { info.GetReturnValue().Set(HunkWrapper::FromHunk(*hunk)); } else { @@ -306,13 +306,13 @@ void PatchWrapper::HunkForNewPosition(const Nan::FunctionCallbackInfo &in } } -void PatchWrapper::Serialize(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::serialize(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; static vector serialization_vector; serialization_vector.clear(); - patch.Serialize(&serialization_vector); + patch.serialize(&serialization_vector); Local result; auto maybe_result = Nan::CopyBuffer(reinterpret_cast(serialization_vector.data()), serialization_vector.size()); @@ -321,7 +321,7 @@ void PatchWrapper::Serialize(const Nan::FunctionCallbackInfo &info) { } } -void PatchWrapper::Deserialize(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::deserialize(const Nan::FunctionCallbackInfo &info) { Local result; if (Nan::NewInstance(Nan::New(patch_wrapper_constructor)).ToLocal(&result)) { if (info[0]->IsUint8Array()) { @@ -335,7 +335,7 @@ void PatchWrapper::Deserialize(const Nan::FunctionCallbackInfo &info) { } } -void PatchWrapper::Compose(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::compose(const Nan::FunctionCallbackInfo &info) { Local result; if (Nan::NewInstance(Nan::New(patch_wrapper_constructor)).ToLocal(&result)) { Local js_patches = Local::Cast(info[0]); @@ -362,25 +362,25 @@ void PatchWrapper::Compose(const Nan::FunctionCallbackInfo &info) { } } -void PatchWrapper::GetDotGraph(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::get_dot_graph(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - std::string graph = patch.GetDotGraph(); + std::string graph = patch.get_dot_graph(); info.GetReturnValue().Set(Nan::New(graph).ToLocalChecked()); } -void PatchWrapper::GetJSON(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::get_json(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - std::string graph = patch.GetJSON(); + std::string graph = patch.get_json(); info.GetReturnValue().Set(Nan::New(graph).ToLocalChecked()); } -void PatchWrapper::GetHunkCount(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::get_hunk_count(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - uint32_t hunk_count = patch.GetHunkCount(); + uint32_t hunk_count = patch.get_hunk_count(); info.GetReturnValue().Set(Nan::New(hunk_count)); } -void PatchWrapper::Rebalance(const Nan::FunctionCallbackInfo &info) { +void PatchWrapper::rebalance(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - patch.Rebalance(); + patch.rebalance(); } diff --git a/src/bindings/patch-wrapper.h b/src/bindings/patch-wrapper.h index 8af42bfe..0cda0b2c 100644 --- a/src/bindings/patch-wrapper.h +++ b/src/bindings/patch-wrapper.h @@ -3,27 +3,27 @@ class PatchWrapper : public Nan::ObjectWrap { public: - static void Init(v8::Local exports); + static void init(v8::Local exports); private: PatchWrapper(Patch &&patch); - static void New(const Nan::FunctionCallbackInfo &info); - static void Splice(const Nan::FunctionCallbackInfo &info); - static void SpliceOld(const Nan::FunctionCallbackInfo &info); - static void Copy(const Nan::FunctionCallbackInfo &info); - static void Invert(const Nan::FunctionCallbackInfo &info); - static void GetHunks(const Nan::FunctionCallbackInfo &info); - static void GetHunksInOldRange(const Nan::FunctionCallbackInfo &info); - static void GetHunksInNewRange(const Nan::FunctionCallbackInfo &info); - static void HunkForOldPosition(const Nan::FunctionCallbackInfo &info); - static void HunkForNewPosition(const Nan::FunctionCallbackInfo &info); - static void Serialize(const Nan::FunctionCallbackInfo &info); - static void Deserialize(const Nan::FunctionCallbackInfo &info); - static void Compose(const Nan::FunctionCallbackInfo &info); - static void GetDotGraph(const Nan::FunctionCallbackInfo &info); - static void GetJSON(const Nan::FunctionCallbackInfo &info); - static void GetHunkCount(const Nan::FunctionCallbackInfo &info); - static void Rebalance(const Nan::FunctionCallbackInfo &info); + static void construct(const Nan::FunctionCallbackInfo &info); + static void splice(const Nan::FunctionCallbackInfo &info); + static void splice_old(const Nan::FunctionCallbackInfo &info); + static void copy(const Nan::FunctionCallbackInfo &info); + static void invert(const Nan::FunctionCallbackInfo &info); + static void get_hunks(const Nan::FunctionCallbackInfo &info); + static void get_hunks_in_old_range(const Nan::FunctionCallbackInfo &info); + static void get_hunks_in_new_range(const Nan::FunctionCallbackInfo &info); + static void hunk_for_old_position(const Nan::FunctionCallbackInfo &info); + static void hunk_for_new_position(const Nan::FunctionCallbackInfo &info); + static void serialize(const Nan::FunctionCallbackInfo &info); + static void deserialize(const Nan::FunctionCallbackInfo &info); + static void compose(const Nan::FunctionCallbackInfo &info); + static void get_dot_graph(const Nan::FunctionCallbackInfo &info); + static void get_json(const Nan::FunctionCallbackInfo &info); + static void get_hunk_count(const Nan::FunctionCallbackInfo &info); + static void rebalance(const Nan::FunctionCallbackInfo &info); Patch patch; }; diff --git a/src/core/patch.cc b/src/core/patch.cc index 616bd1f5..c2a182b2 100644 --- a/src/core/patch.cc +++ b/src/core/patch.cc @@ -33,7 +33,7 @@ struct Patch::Node { unique_ptr old_text; unique_ptr new_text; - void GetSubtreeEnd(Point *old_end, Point *new_end) { + void get_subtree_end(Point *old_end, Point *new_end) { Node *node = this; *old_end = Point::Zero(); *new_end = Point::Zero(); @@ -46,7 +46,7 @@ struct Patch::Node { } } - Node *Copy() { + Node *copy() { return new Node{ left, right, @@ -59,7 +59,7 @@ struct Patch::Node { }; } - Node *Invert() { + Node *invert() { return new Node{ left, right, @@ -72,7 +72,7 @@ struct Patch::Node { }; } - void WriteDotGraph(std::stringstream &result, Point left_ancestor_old_end, Point left_ancestor_new_end) { + void write_dot_graph(std::stringstream &result, Point left_ancestor_old_end, Point left_ancestor_new_end) { Point node_old_start = left_ancestor_old_end.Traverse(old_distance_from_left_ancestor); Point node_new_start = left_ancestor_new_end.Traverse(new_distance_from_left_ancestor); Point node_old_end = node_old_start.Traverse(old_extent); @@ -89,7 +89,7 @@ struct Patch::Node { result << "node_" << this << " -> "; if (left) { result << "node_" << left << endl; - left->WriteDotGraph(result, left_ancestor_old_end, left_ancestor_new_end); + left->write_dot_graph(result, left_ancestor_old_end, left_ancestor_new_end); } else { result << "node_" << this << "_left_null" << endl; result << "node_" << this << "_left_null [label=\"\" shape=point]" << endl; @@ -98,14 +98,14 @@ struct Patch::Node { result << "node_" << this << " -> "; if (right) { result << "node_" << right << endl; - right->WriteDotGraph(result, node_old_end, node_new_end); + right->write_dot_graph(result, node_old_end, node_new_end); } else { result << "node_" << this << "_right_null" << endl; result << "node_" << this << "_right_null [label=\"\" shape=point]" << endl; } } - void WriteJSON(std::stringstream &result, Point left_ancestor_old_end, Point left_ancestor_new_end) { + void write_json(std::stringstream &result, Point left_ancestor_old_end, Point left_ancestor_new_end) { Point node_old_start = left_ancestor_old_end.Traverse(old_distance_from_left_ancestor); Point node_new_start = left_ancestor_new_end.Traverse(new_distance_from_left_ancestor); Point node_old_end = node_old_start.Traverse(old_extent); @@ -119,14 +119,14 @@ struct Patch::Node { result << "\"newEnd\": {\"row\": " << node_new_end.row << ", \"column\": " << node_new_end.column << "}, "; result << "\"left\": "; if (left) { - left->WriteJSON(result, left_ancestor_old_end, left_ancestor_new_end); + left->write_json(result, left_ancestor_old_end, left_ancestor_new_end); } else { result << "null"; } result << ", "; result << "\"right\": "; if (right) { - right->WriteJSON(result, node_old_end, node_new_end); + right->write_json(result, node_old_end, node_new_end); } else { result << "null"; } @@ -181,11 +181,11 @@ Patch::Patch(Node *root, uint32_t hunk_count, bool merges_adjacent_hunks) Patch::Patch(const vector &patches_to_compose) : Patch() { bool left_to_right = true; for (const Patch *patch : patches_to_compose) { - auto hunks = patch->GetHunks(); + auto hunks = patch->get_hunks(); if (left_to_right) { for (auto iter = hunks.begin(), end = hunks.end(); iter != end; ++iter) { - Splice(iter->new_start, iter->old_end.Traversal(iter->old_start), + splice(iter->new_start, iter->old_end.Traversal(iter->old_start), iter->new_end.Traversal(iter->new_start), iter->old_text ? unique_ptr{new Text(*iter->old_text)} : nullptr, iter->new_text ? unique_ptr{new Text(*iter->new_text)} : nullptr); @@ -193,7 +193,7 @@ Patch::Patch(const vector &patches_to_compose) : Patch() { } else { for (auto iter = hunks.rbegin(), end = hunks.rend(); iter != end; ++iter) { - Splice(iter->old_start, iter->old_end.Traversal(iter->old_start), + splice(iter->old_start, iter->old_end.Traversal(iter->old_start), iter->new_end.Traversal(iter->new_start), iter->old_text ? unique_ptr{new Text(*iter->old_text)} : nullptr, iter->new_text ? unique_ptr{new Text(*iter->new_text)} : nullptr); @@ -209,12 +209,12 @@ Patch::~Patch() { if (frozen_node_array) { free(frozen_node_array); } else { - DeleteNode(&root); + delete_node(&root); } } } -Patch::Node *Patch::BuildNode(Node *left, Node *right, +Patch::Node *Patch::build_node(Node *left, Node *right, Point old_distance_from_left_ancestor, Point new_distance_from_left_ancestor, Point old_extent, Point new_extent, unique_ptr old_text, @@ -230,7 +230,7 @@ Patch::Node *Patch::BuildNode(Node *left, Node *right, move(new_text)}; } -void Patch::DeleteNode(Node **node_to_delete) { +void Patch::delete_node(Node **node_to_delete) { if (*node_to_delete) { node_stack.clear(); node_stack.push_back(*node_to_delete); @@ -251,7 +251,7 @@ void Patch::DeleteNode(Node **node_to_delete) { } template -Patch::Node *Patch::SplayNodeEndingBefore(Point target) { +Patch::Node *Patch::splay_node_ending_before(Point target) { Node *splayed_node = nullptr; Point left_ancestor_end = Point::Zero(); Node *node = root; @@ -284,14 +284,14 @@ Patch::Node *Patch::SplayNodeEndingBefore(Point target) { if (splayed_node) { node_stack.resize(splayed_node_ancestor_count); - SplayNode(splayed_node); + splay_node(splayed_node); } return splayed_node; } template -Patch::Node *Patch::SplayNodeStartingBefore(Point target) { +Patch::Node *Patch::splay_node_starting_before(Point target) { Node *splayed_node = nullptr; Point left_ancestor_end = Point::Zero(); Node *node = root; @@ -324,14 +324,14 @@ Patch::Node *Patch::SplayNodeStartingBefore(Point target) { if (splayed_node) { node_stack.resize(splayed_node_ancestor_count); - SplayNode(splayed_node); + splay_node(splayed_node); } return splayed_node; } template -Patch::Node *Patch::SplayNodeEndingAfter(Point splice_start, Point splice_end) { +Patch::Node *Patch::splay_node_ending_after(Point splice_start, Point splice_end) { Node *splayed_node = nullptr; Point left_ancestor_end = Point::Zero(); Node *node = root; @@ -364,14 +364,14 @@ Patch::Node *Patch::SplayNodeEndingAfter(Point splice_start, Point splice_end) { if (splayed_node) { node_stack.resize(splayed_node_ancestor_count); - SplayNode(splayed_node); + splay_node(splayed_node); } return splayed_node; } template -Patch::Node *Patch::SplayNodeStartingAfter(Point splice_start, Point splice_end) { +Patch::Node *Patch::splay_node_starting_after(Point splice_start, Point splice_end) { Node *splayed_node = nullptr; Point left_ancestor_end = Point::Zero(); Node *node = root; @@ -404,19 +404,19 @@ Patch::Node *Patch::SplayNodeStartingAfter(Point splice_start, Point splice_end) if (splayed_node) { node_stack.resize(splayed_node_ancestor_count); - SplayNode(splayed_node); + splay_node(splayed_node); } return splayed_node; } template -vector Patch::GetHunksInRange(Point start, Point end, bool inclusive) { +vector Patch::get_hunks_in_range(Point start, Point end, bool inclusive) { vector result; if (!root) return result; - Node *lower_bound = SplayNodeStartingBefore(start); + Node *lower_bound = splay_node_starting_before(start); node_stack.clear(); left_ancestor_stack.clear(); @@ -491,8 +491,8 @@ vector Patch::GetHunksInRange(Point start, Point end, bool inclusive) { } template -optional Patch::HunkForPosition(Point target) { - Node *lower_bound = SplayNodeStartingBefore(target); +optional Patch::hunk_for_position(Point target) { + Node *lower_bound = splay_node_starting_before(target); if (lower_bound) { Point old_start = lower_bound->old_distance_from_left_ancestor; Point new_start = lower_bound->new_distance_from_left_ancestor; @@ -506,10 +506,10 @@ optional Patch::HunkForPosition(Point target) { } } -bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, +bool Patch::splice(Point new_splice_start, Point new_deletion_extent, Point new_insertion_extent, unique_ptr deleted_text, unique_ptr inserted_text) { - if (IsFrozen()) { + if (is_frozen()) { return false; } @@ -518,7 +518,7 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, } if (!root) { - root = BuildNode(nullptr, nullptr, new_splice_start, new_splice_start, + root = build_node(nullptr, nullptr, new_splice_start, new_splice_start, new_deletion_extent, new_insertion_extent, move(deleted_text), move(inserted_text)); return true; @@ -527,14 +527,14 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, Point new_deletion_end = new_splice_start.Traverse(new_deletion_extent); Point new_insertion_end = new_splice_start.Traverse(new_insertion_extent); - Node *lower_bound = SplayNodeStartingBefore(new_splice_start); + Node *lower_bound = splay_node_starting_before(new_splice_start); unique_ptr old_text = - ComputeOldText(move(deleted_text), new_splice_start, new_deletion_end); + compute_old_text(move(deleted_text), new_splice_start, new_deletion_end); Node *upper_bound = - SplayNodeEndingAfter(new_splice_start, new_deletion_end); + splay_node_ending_after(new_splice_start, new_deletion_end); if (upper_bound && lower_bound && lower_bound != upper_bound) { if (lower_bound != upper_bound->left) { - RotateNodeRight(lower_bound, upper_bound->left, upper_bound); + rotate_node_right(lower_bound, upper_bound->left, upper_bound); } } @@ -590,12 +590,12 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, if (lower_bound == upper_bound) { if (root->old_extent.IsZero() && root->new_extent.IsZero()) { - DeleteRoot(); + delete_root(); } } else { upper_bound->left = lower_bound->left; lower_bound->left = nullptr; - DeleteNode(&lower_bound); + delete_node(&lower_bound); } } else if (overlaps_upper_bound) { @@ -620,14 +620,14 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, upper_bound->old_text = move(old_text); - DeleteNode(&lower_bound->right); + delete_node(&lower_bound->right); if (upper_bound->left != lower_bound) { - DeleteNode(&upper_bound->left); + delete_node(&upper_bound->left); } } else if (overlaps_lower_bound) { Point rightmost_child_old_end, rightmost_child_new_end; - lower_bound->GetSubtreeEnd(&rightmost_child_old_end, + lower_bound->get_subtree_end(&rightmost_child_old_end, &rightmost_child_new_end); Point old_deletion_end = rightmost_child_old_end.Traverse( new_deletion_end.Traversal(rightmost_child_new_end)); @@ -651,8 +651,8 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, lower_bound->old_text = move(old_text); - DeleteNode(&lower_bound->right); - RotateNodeRight(lower_bound, upper_bound, nullptr); + delete_node(&lower_bound->right); + rotate_node_right(lower_bound, upper_bound, nullptr); // Splice doesn't overlap either bound } else { @@ -663,7 +663,7 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, assert(new_deletion_extent.IsZero()); assert(new_splice_start == upper_bound_new_start); - root = BuildNode(upper_bound->left, upper_bound, upper_bound_old_start, + root = build_node(upper_bound->left, upper_bound, upper_bound_old_start, upper_bound_new_start, Point::Zero(), new_insertion_extent, move(old_text), move(inserted_text)); @@ -673,19 +673,19 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, upper_bound->new_distance_from_left_ancestor = Point::Zero(); } else { Point rightmost_child_old_end, rightmost_child_new_end; - lower_bound->GetSubtreeEnd(&rightmost_child_old_end, + lower_bound->get_subtree_end(&rightmost_child_old_end, &rightmost_child_new_end); Point old_splice_start = lower_bound_old_end.Traverse( new_splice_start.Traversal(lower_bound_new_end)); Point old_deletion_end = rightmost_child_old_end.Traverse( new_deletion_end.Traversal(rightmost_child_new_end)); - root = BuildNode( + root = build_node( lower_bound, upper_bound, old_splice_start, new_splice_start, old_deletion_end.Traversal(old_splice_start), new_insertion_extent, move(old_text), move(inserted_text)); - DeleteNode(&lower_bound->right); + delete_node(&lower_bound->right); upper_bound->left = nullptr; upper_bound->old_distance_from_left_ancestor = upper_bound_old_start.Traversal(old_deletion_end); @@ -702,7 +702,7 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, Point lower_bound_old_end = lower_bound_old_start.Traverse(lower_bound->old_extent); Point rightmost_child_old_end, rightmost_child_new_end; - lower_bound->GetSubtreeEnd(&rightmost_child_old_end, + lower_bound->get_subtree_end(&rightmost_child_old_end, &rightmost_child_new_end); Point old_deletion_end = rightmost_child_old_end.Traverse( new_deletion_end.Traversal(rightmost_child_new_end)); @@ -710,7 +710,7 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, new_splice_start < lower_bound_new_end || (merges_adjacent_hunks && new_splice_start == lower_bound_new_end); - DeleteNode(&lower_bound->right); + delete_node(&lower_bound->right); if (overlaps_lower_bound) { lower_bound->old_extent = @@ -731,7 +731,7 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, Point old_splice_start = lower_bound_old_end.Traverse( new_splice_start.Traversal(lower_bound_new_end)); root = - BuildNode(lower_bound, nullptr, old_splice_start, new_splice_start, + build_node(lower_bound, nullptr, old_splice_start, new_splice_start, old_deletion_end.Traversal(old_splice_start), new_insertion_extent, move(old_text), move(inserted_text)); } @@ -748,7 +748,7 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, Point old_deletion_end; if (upper_bound->left) { Point rightmost_child_old_end, rightmost_child_new_end; - upper_bound->left->GetSubtreeEnd(&rightmost_child_old_end, + upper_bound->left->get_subtree_end(&rightmost_child_old_end, &rightmost_child_new_end); old_deletion_end = rightmost_child_old_end.Traverse( new_deletion_end.Traversal(rightmost_child_new_end)); @@ -756,7 +756,7 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, old_deletion_end = new_deletion_end; } - DeleteNode(&upper_bound->left); + delete_node(&upper_bound->left); if (overlaps_upper_bound) { upper_bound->old_distance_from_left_ancestor = new_splice_start; upper_bound->new_distance_from_left_ancestor = new_splice_start; @@ -778,7 +778,7 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, upper_bound->old_text = move(old_text); } else { root = - BuildNode(nullptr, upper_bound, new_splice_start, new_splice_start, + build_node(nullptr, upper_bound, new_splice_start, new_splice_start, old_deletion_end.Traversal(new_splice_start), new_insertion_extent, move(old_text), move(inserted_text)); Point distance_from_end_of_root_to_start_of_upper_bound = @@ -791,11 +791,11 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, } else { Point rightmost_child_old_end, rightmost_child_new_end; - root->GetSubtreeEnd(&rightmost_child_old_end, &rightmost_child_new_end); + root->get_subtree_end(&rightmost_child_old_end, &rightmost_child_new_end); Point old_deletion_end = rightmost_child_old_end.Traverse( new_deletion_end.Traversal(rightmost_child_new_end)); - DeleteNode(&root); - root = BuildNode(nullptr, nullptr, new_splice_start, new_splice_start, + delete_node(&root); + root = build_node(nullptr, nullptr, new_splice_start, new_splice_start, old_deletion_end.Traversal(new_splice_start), new_insertion_extent, move(old_text), move(inserted_text)); } @@ -803,9 +803,9 @@ bool Patch::Splice(Point new_splice_start, Point new_deletion_extent, return true; } -bool Patch::SpliceOld(Point old_splice_start, Point old_deletion_extent, +bool Patch::splice_old(Point old_splice_start, Point old_deletion_extent, Point old_insertion_extent) { - if (IsFrozen()) { + if (is_frozen()) { return false; } @@ -816,12 +816,12 @@ bool Patch::SpliceOld(Point old_splice_start, Point old_deletion_extent, Point old_deletion_end = old_splice_start.Traverse(old_deletion_extent); Point old_insertion_end = old_splice_start.Traverse(old_insertion_extent); - Node *lower_bound = SplayNodeEndingBefore(old_splice_start); - Node *upper_bound = SplayNodeStartingAfter(old_splice_start, + Node *lower_bound = splay_node_ending_before(old_splice_start); + Node *upper_bound = splay_node_starting_after(old_splice_start, old_deletion_end); if (!lower_bound && !upper_bound) { - DeleteNode(&root); + delete_node(&root); return true; } @@ -837,7 +837,7 @@ bool Patch::SpliceOld(Point old_splice_start, Point old_deletion_extent, if (upper_bound && lower_bound) { if (lower_bound != upper_bound->left) { - RotateNodeRight(lower_bound, upper_bound->left, upper_bound); + rotate_node_right(lower_bound, upper_bound->left, upper_bound); } } @@ -855,7 +855,7 @@ bool Patch::SpliceOld(Point old_splice_start, Point old_deletion_extent, new_insertion_end = lower_bound_new_end.Traverse( old_insertion_end.Traversal(lower_bound_old_end)); - DeleteNode(&lower_bound->right); + delete_node(&lower_bound->right); } else { new_deletion_end = old_deletion_end; new_insertion_end = old_insertion_end; @@ -883,20 +883,20 @@ bool Patch::SpliceOld(Point old_splice_start, Point old_deletion_extent, upper_bound->new_extent = lower_bound->new_extent.Traverse(upper_bound->new_extent); upper_bound->left = lower_bound->left; - DeleteNode(&lower_bound); + delete_node(&lower_bound); } } else { - DeleteNode(&upper_bound->left); + delete_node(&upper_bound->left); } } return true; } -Patch Patch::Copy() { +Patch Patch::copy() { Node *new_root = nullptr; if (root) { - new_root = root->Copy(); + new_root = root->copy(); node_stack.clear(); node_stack.push_back(new_root); @@ -904,11 +904,11 @@ Patch Patch::Copy() { Node *node = node_stack.back(); node_stack.pop_back(); if (node->left) { - node->left = node->left->Copy(); + node->left = node->left->copy(); node_stack.push_back(node->left); } if (node->right) { - node->right = node->right->Copy(); + node->right = node->right->copy(); node_stack.push_back(node->right); } } @@ -917,10 +917,10 @@ Patch Patch::Copy() { return Patch{new_root, hunk_count, merges_adjacent_hunks}; } -Patch Patch::Invert() { +Patch Patch::invert() { Node *inverted_root = nullptr; if (root) { - inverted_root = root->Invert(); + inverted_root = root->invert(); node_stack.clear(); node_stack.push_back(inverted_root); @@ -928,11 +928,11 @@ Patch Patch::Invert() { Node *node = node_stack.back(); node_stack.pop_back(); if (node->left) { - node->left = node->left->Invert(); + node->left = node->left->invert(); node_stack.push_back(node->left); } if (node->right) { - node->right = node->right->Invert(); + node->right = node->right->invert(); node_stack.push_back(node->right); } } @@ -941,7 +941,7 @@ Patch Patch::Invert() { return Patch{inverted_root, hunk_count, merges_adjacent_hunks}; } -void Patch::SplayNode(Node *node) { +void Patch::splay_node(Node *node) { while (!node_stack.empty()) { Node *parent = node_stack.back(); node_stack.pop_back(); @@ -959,23 +959,23 @@ void Patch::SplayNode(Node *node) { } if (grandparent->left == parent && parent->right == node) { - RotateNodeLeft(node, parent, grandparent); - RotateNodeRight(node, grandparent, great_grandparent); + rotate_node_left(node, parent, grandparent); + rotate_node_right(node, grandparent, great_grandparent); } else if (grandparent->right == parent && parent->left == node) { - RotateNodeRight(node, parent, grandparent); - RotateNodeLeft(node, grandparent, great_grandparent); + rotate_node_right(node, parent, grandparent); + rotate_node_left(node, grandparent, great_grandparent); } else if (grandparent->left == parent && parent->left == node) { - RotateNodeRight(parent, grandparent, great_grandparent); - RotateNodeRight(node, parent, great_grandparent); + rotate_node_right(parent, grandparent, great_grandparent); + rotate_node_right(node, parent, great_grandparent); } else if (grandparent->right == parent && parent->right == node) { - RotateNodeLeft(parent, grandparent, great_grandparent); - RotateNodeLeft(node, parent, great_grandparent); + rotate_node_left(parent, grandparent, great_grandparent); + rotate_node_left(node, parent, great_grandparent); } } else { if (parent->left == node) { - RotateNodeRight(node, parent, nullptr); + rotate_node_right(node, parent, nullptr); } else if (parent->right == node) { - RotateNodeLeft(node, parent, nullptr); + rotate_node_left(node, parent, nullptr); } else { assert(!"Unexpected state"); } @@ -983,7 +983,7 @@ void Patch::SplayNode(Node *node) { } } -void Patch::RotateNodeLeft(Node *pivot, Node *root, Node *root_parent) { +void Patch::rotate_node_left(Node *pivot, Node *root, Node *root_parent) { if (root_parent) { if (root_parent->left == root) { root_parent->left = pivot; @@ -1005,7 +1005,7 @@ void Patch::RotateNodeLeft(Node *pivot, Node *root, Node *root_parent) { .Traverse(pivot->new_distance_from_left_ancestor); } -void Patch::RotateNodeRight(Node *pivot, Node *root, Node *root_parent) { +void Patch::rotate_node_right(Node *pivot, Node *root, Node *root_parent) { if (root_parent) { if (root_parent->left == root) { root_parent->left = pivot; @@ -1027,43 +1027,43 @@ void Patch::RotateNodeRight(Node *pivot, Node *root, Node *root_parent) { pivot->new_distance_from_left_ancestor.Traverse(pivot->new_extent)); } -void Patch::DeleteRoot() { +void Patch::delete_root() { Node *node = root, *parent = nullptr; while (true) { if (node->left) { - RotateNodeRight(node->left, node, parent); + rotate_node_right(node->left, node, parent); } else if (node->right) { - RotateNodeLeft(node->right, node, parent); + rotate_node_left(node->right, node, parent); } else if (parent) { if (parent->left == node) { - DeleteNode(&parent->left); + delete_node(&parent->left); } else if (parent->right == node) { - DeleteNode(&parent->right); + delete_node(&parent->right); } } else { - DeleteNode(&root); + delete_node(&root); break; } } } -std::string Patch::GetDotGraph() const { +std::string Patch::get_dot_graph() const { std::stringstream result; result << "digraph patch {" << endl; - if (root) root->WriteDotGraph(result, Point::Zero(), Point::Zero()); + if (root) root->write_dot_graph(result, Point::Zero(), Point::Zero()); result << "}" << endl; return result.str(); } -std::string Patch::GetJSON() const { +std::string Patch::get_json() const { std::stringstream result; - if (root) root->WriteJSON(result, Point::Zero(), Point::Zero()); + if (root) root->write_json(result, Point::Zero(), Point::Zero()); return result.str(); } -size_t Patch::GetHunkCount() const { return hunk_count; } +size_t Patch::get_hunk_count() const { return hunk_count; } -void Patch::Rebalance() { +void Patch::rebalance() { if (!root) return; @@ -1073,7 +1073,7 @@ void Patch::Rebalance() { Node *left = pseudo_root->left; Node *right = pseudo_root->right; if (left) { - RotateNodeRight(left, pseudo_root, pseudo_root_parent); + rotate_node_right(left, pseudo_root, pseudo_root_parent); pseudo_root = left; } else { pseudo_root_parent = pseudo_root; @@ -1084,14 +1084,14 @@ void Patch::Rebalance() { // Transform vine to balanced tree uint32_t n = hunk_count; uint32_t m = std::pow(2, std::floor(std::log2(n + 1))) - 1; - PerformRebalancingRotations(n - m); + perform_rebalancing_rotations(n - m); while (m > 1) { m = m / 2; - PerformRebalancingRotations(m); + perform_rebalancing_rotations(m); } } -void Patch::PerformRebalancingRotations(uint32_t count) { +void Patch::perform_rebalancing_rotations(uint32_t count) { Node *pseudo_root = root, *pseudo_root_parent = nullptr; for (uint32_t i = 0; i < count; i++) { if (!pseudo_root) @@ -1099,13 +1099,13 @@ void Patch::PerformRebalancingRotations(uint32_t count) { Node *right_child = pseudo_root->right; if (!right_child) return; - RotateNodeLeft(right_child, pseudo_root, pseudo_root_parent); + rotate_node_left(right_child, pseudo_root, pseudo_root_parent); pseudo_root = right_child->right; pseudo_root_parent = right_child; } } -vector Patch::GetHunks() const { +vector Patch::get_hunks() const { vector result; if (!root) { return result; @@ -1162,23 +1162,23 @@ vector Patch::GetHunks() const { return result; } -vector Patch::GetHunksInOldRange(Point start, Point end) { - return GetHunksInRange(start, end); +vector Patch::get_hunks_in_old_range(Point start, Point end) { + return get_hunks_in_range(start, end); } -vector Patch::GetHunksInNewRange(Point start, Point end, bool inclusive) { - return GetHunksInRange(start, end, inclusive); +vector Patch::get_hunks_in_new_range(Point start, Point end, bool inclusive) { + return get_hunks_in_range(start, end, inclusive); } -optional Patch::HunkForOldPosition(Point target) { - return HunkForPosition(target); +optional Patch::hunk_for_old_position(Point target) { + return hunk_for_position(target); } -optional Patch::HunkForNewPosition(Point target) { - return HunkForPosition(target); +optional Patch::hunk_for_new_position(Point target) { + return hunk_for_position(target); } -unique_ptr Patch::ComputeOldText(unique_ptr deleted_text, +unique_ptr Patch::compute_old_text(unique_ptr deleted_text, Point new_splice_start, Point new_deletion_end) { if (!deleted_text.get()) @@ -1188,7 +1188,7 @@ unique_ptr Patch::ComputeOldText(unique_ptr deleted_text, Point range_start = new_splice_start, range_end = new_deletion_end; auto overlapping_hunks = - GetHunksInNewRange(range_start, range_end, merges_adjacent_hunks); + get_hunks_in_new_range(range_start, range_end, merges_adjacent_hunks); TextSlice deleted_text_slice = TextSlice(*deleted_text); Point deleted_text_slice_start = new_splice_start; @@ -1230,14 +1230,14 @@ template <> uint32_t network_to_host(uint32_t input) { return ntohl(input); } template <> uint32_t host_to_network(uint32_t input) { return htonl(input); } -template void AppendToBuffer(vector *output, T value) { +template void append_to_buffer(vector *output, T value) { value = host_to_network(value); const uint8_t *bytes = reinterpret_cast(&value); output->insert(output->end(), bytes, bytes + sizeof(T)); } template -T GetFromBuffer(const uint8_t **data, const uint8_t *end) { +T get_from_buffer(const uint8_t **data, const uint8_t *end) { const T *pointer = reinterpret_cast(*data); *data = *data + sizeof(T); if (*data <= end) { @@ -1247,36 +1247,36 @@ T GetFromBuffer(const uint8_t **data, const uint8_t *end) { } } -void GetPointFromBuffer(const uint8_t **data, const uint8_t *end, +void get_point_from_buffer(const uint8_t **data, const uint8_t *end, Point *point) { - point->row = GetFromBuffer(data, end); - point->column = GetFromBuffer(data, end); + point->row = get_from_buffer(data, end); + point->column = get_from_buffer(data, end); } -void AppendPointToBuffer(vector *output, const Point &point) { - AppendToBuffer(output, point.row); - AppendToBuffer(output, point.column); +void append_point_to_buffer(vector *output, const Point &point) { + append_to_buffer(output, point.row); + append_to_buffer(output, point.column); } -void AppendTextToBuffer(vector *output, const Text *text) { +void append_text_to_buffer(vector *output, const Text *text) { if (text) { - AppendToBuffer(output, 1); - AppendToBuffer(output, static_cast(text->size())); + append_to_buffer(output, 1); + append_to_buffer(output, static_cast(text->size())); for (uint16_t character : *text) { - AppendToBuffer(output, character); + append_to_buffer(output, character); } } else { - AppendToBuffer(output, 0); + append_to_buffer(output, 0); } } -unique_ptr GetTextFromBuffer(const uint8_t **data, const uint8_t *end) { - if (GetFromBuffer(data, end)) { - uint32_t length = GetFromBuffer(data, end); +unique_ptr get_text_from_buffer(const uint8_t **data, const uint8_t *end) { + if (get_from_buffer(data, end)) { + uint32_t length = get_from_buffer(data, end); unique_ptr result {new Text()}; result->reserve(length); for (uint32_t i = 0; i < length; i++) { - result->push_back(GetFromBuffer(data, end)); + result->push_back(get_from_buffer(data, end)); } return result; } else { @@ -1284,35 +1284,35 @@ unique_ptr GetTextFromBuffer(const uint8_t **data, const uint8_t *end) { } } -void GetNodeFromBuffer(const uint8_t **data, const uint8_t *end, Patch::Node *node) { - GetPointFromBuffer(data, end, &node->old_extent); - GetPointFromBuffer(data, end, &node->new_extent); - GetPointFromBuffer(data, end, &node->old_distance_from_left_ancestor); - GetPointFromBuffer(data, end, &node->new_distance_from_left_ancestor); - node->old_text = GetTextFromBuffer(data, end); - node->new_text = GetTextFromBuffer(data, end); +void get_node_from_buffer(const uint8_t **data, const uint8_t *end, Patch::Node *node) { + get_point_from_buffer(data, end, &node->old_extent); + get_point_from_buffer(data, end, &node->new_extent); + get_point_from_buffer(data, end, &node->old_distance_from_left_ancestor); + get_point_from_buffer(data, end, &node->new_distance_from_left_ancestor); + node->old_text = get_text_from_buffer(data, end); + node->new_text = get_text_from_buffer(data, end); node->left = nullptr; node->right = nullptr; } -void AppendNodeToBuffer(vector *output, const Patch::Node &node) { - AppendPointToBuffer(output, node.old_extent); - AppendPointToBuffer(output, node.new_extent); - AppendPointToBuffer(output, node.old_distance_from_left_ancestor); - AppendPointToBuffer(output, node.new_distance_from_left_ancestor); - AppendTextToBuffer(output, node.old_text.get()); - AppendTextToBuffer(output, node.new_text.get()); +void append_node_to_buffer(vector *output, const Patch::Node &node) { + append_point_to_buffer(output, node.old_extent); + append_point_to_buffer(output, node.new_extent); + append_point_to_buffer(output, node.old_distance_from_left_ancestor); + append_point_to_buffer(output, node.new_distance_from_left_ancestor); + append_text_to_buffer(output, node.old_text.get()); + append_text_to_buffer(output, node.new_text.get()); } -void Patch::Serialize(vector *output) const { +void Patch::serialize(vector *output) const { if (!root) return; - AppendToBuffer(output, SERIALIZATION_VERSION); + append_to_buffer(output, SERIALIZATION_VERSION); - AppendToBuffer(output, hunk_count); + append_to_buffer(output, hunk_count); - AppendNodeToBuffer(output, *root); + append_node_to_buffer(output, *root); Node *node = root; node_stack.clear(); @@ -1320,19 +1320,19 @@ void Patch::Serialize(vector *output) const { while (node) { if (node->left && previous_node_child_index < 0) { - AppendToBuffer(output, Left); - AppendNodeToBuffer(output, *node->left); + append_to_buffer(output, Left); + append_node_to_buffer(output, *node->left); node_stack.push_back(node); node = node->left; previous_node_child_index = -1; } else if (node->right && previous_node_child_index < 1) { - AppendToBuffer(output, Right); - AppendNodeToBuffer(output, *node->right); + append_to_buffer(output, Right); + append_node_to_buffer(output, *node->right); node_stack.push_back(node); node = node->right; previous_node_child_index = -1; } else if (!node_stack.empty()) { - AppendToBuffer(output, Up); + append_to_buffer(output, Up); Node *parent = node_stack.back(); node_stack.pop_back(); previous_node_child_index = (node == parent->left) ? 0 : 1; @@ -1343,7 +1343,7 @@ void Patch::Serialize(vector *output) const { } } -bool Patch::IsFrozen() const { return frozen_node_array != nullptr; } +bool Patch::is_frozen() const { return frozen_node_array != nullptr; } Patch::Patch(const vector &input) : root{nullptr}, frozen_node_array{nullptr}, merges_adjacent_hunks{true} { @@ -1351,12 +1351,12 @@ Patch::Patch(const vector &input) const uint8_t *data = begin; const uint8_t *end = data + input.size(); - uint32_t serialization_version = GetFromBuffer(&data, end); + uint32_t serialization_version = get_from_buffer(&data, end); if (serialization_version != SERIALIZATION_VERSION) { return; } - hunk_count = GetFromBuffer(&data, end); + hunk_count = get_from_buffer(&data, end); if (hunk_count == 0) { return; } @@ -1365,19 +1365,19 @@ Patch::Patch(const vector &input) frozen_node_array = static_cast(calloc(hunk_count, sizeof(Node))); root = frozen_node_array; Node *node = root, *next_node = root + 1; - GetNodeFromBuffer(&data, end, node); + get_node_from_buffer(&data, end, node); while (next_node < root + hunk_count) { - switch (GetFromBuffer(&data, end)) { + switch (get_from_buffer(&data, end)) { case Left: - GetNodeFromBuffer(&data, end, next_node); + get_node_from_buffer(&data, end, next_node); node->left = next_node; node_stack.push_back(node); node = next_node; next_node++; break; case Right: - GetNodeFromBuffer(&data, end, next_node); + get_node_from_buffer(&data, end, next_node); node->right = next_node; node_stack.push_back(node); node = next_node; diff --git a/src/core/patch.h b/src/core/patch.h index 70cbbc00..78bd4c85 100644 --- a/src/core/patch.h +++ b/src/core/patch.h @@ -35,53 +35,53 @@ class Patch { Patch(Node *root, uint32_t hunk_count, bool merges_adjacent_hunks); Patch(Patch &&); ~Patch(); - bool Splice(Point start, Point deletion_extent, Point insertion_extent, + bool splice(Point start, Point deletion_extent, Point insertion_extent, std::unique_ptr old_text, std::unique_ptr new_text); - bool SpliceOld(Point start, Point deletion_extent, Point insertion_extent); - Patch Copy(); - Patch Invert(); - std::vector GetHunks() const; - std::vector GetHunksInNewRange(Point start, Point end, + bool splice_old(Point start, Point deletion_extent, Point insertion_extent); + Patch copy(); + Patch invert(); + std::vector get_hunks() const; + std::vector get_hunks_in_new_range(Point start, Point end, bool inclusive = false); - std::vector GetHunksInOldRange(Point start, Point end); - optional HunkForOldPosition(Point position); - optional HunkForNewPosition(Point position); - void Serialize(std::vector *) const; - std::string GetDotGraph() const; - std::string GetJSON() const; - void Rebalance(); - size_t GetHunkCount() const; + std::vector get_hunks_in_old_range(Point start, Point end); + optional hunk_for_old_position(Point position); + optional hunk_for_new_position(Point position); + void serialize(std::vector *) const; + std::string get_dot_graph() const; + std::string get_json() const; + void rebalance(); + size_t get_hunk_count() const; private: template - std::vector GetHunksInRange(Point, Point, bool inclusive = false); + std::vector get_hunks_in_range(Point, Point, bool inclusive = false); - template Node *SplayNodeEndingBefore(Point); + template Node *splay_node_ending_before(Point); - template Node *SplayNodeStartingBefore(Point); + template Node *splay_node_starting_before(Point); - template Node *SplayNodeEndingAfter(Point, Point); + template Node *splay_node_ending_after(Point, Point); template - Node *SplayNodeStartingAfter(Point, Point); + Node *splay_node_starting_after(Point, Point); template - optional HunkForPosition(Point position); + optional hunk_for_position(Point position); - std::unique_ptr ComputeOldText(std::unique_ptr, Point, Point); + std::unique_ptr compute_old_text(std::unique_ptr, Point, Point); - void SplayNode(Node *); - void RotateNodeRight(Node *, Node *, Node *); - void RotateNodeLeft(Node *, Node *, Node *); - void DeleteRoot(); - void PerformRebalancingRotations(uint32_t); - Node *BuildNode(Node *, Node *, Point, Point, Point, Point, + void splay_node(Node *); + void rotate_node_right(Node *, Node *, Node *); + void rotate_node_left(Node *, Node *, Node *); + void delete_root(); + void perform_rebalancing_rotations(uint32_t); + Node *build_node(Node *, Node *, Point, Point, Point, Point, std::unique_ptr, std::unique_ptr); - void DeleteNode(Node **); - bool IsFrozen() const; + void delete_node(Node **); + bool is_frozen() const; - friend void GetNodeFromBuffer(const uint8_t **data, const uint8_t *end, Node *node); - friend void AppendNodeToBuffer(std::vector *output, const Node &node); + friend void get_node_from_buffer(const uint8_t **data, const uint8_t *end, Node *node); + friend void append_node_to_buffer(std::vector *output, const Node &node); }; std::ostream &operator<<(std::ostream &, const Patch::Hunk &); From ee6bf88855fc1e303ec83e9b0bcc148fca446583 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 15 Jan 2017 10:31:02 -0700 Subject: [PATCH 4/8] Convert Point to new naming convention --- benchmark/native/marker-index-benchmark.cc | 2 +- src/bindings/patch-wrapper.cc | 4 +- src/core/marker-index.cc | 34 +-- src/core/patch.cc | 268 ++++++++++----------- src/core/point.cc | 26 +- src/core/point.h | 13 +- 6 files changed, 171 insertions(+), 176 deletions(-) diff --git a/benchmark/native/marker-index-benchmark.cc b/benchmark/native/marker-index-benchmark.cc index 98503679..60fbdc16 100644 --- a/benchmark/native/marker-index-benchmark.cc +++ b/benchmark/native/marker-index-benchmark.cc @@ -14,7 +14,7 @@ Range GetRandomRange() { Point start(rand() % 100, rand() % 100); Point end = start; if (rand() % 10 < 5) { - end = end.Traverse(Point(rand() % 10, rand() % 10)); + end = end.traverse(Point(rand() % 10, rand() % 10)); } return Range{start, end}; } diff --git a/src/bindings/patch-wrapper.cc b/src/bindings/patch-wrapper.cc index a77a26fb..45a88ff6 100644 --- a/src/bindings/patch-wrapper.cc +++ b/src/bindings/patch-wrapper.cc @@ -102,12 +102,12 @@ class HunkWrapper : public Nan::ObjectWrap { static void get_old_extent(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; - info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.old_end.Traversal(hunk.old_start))); + info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.old_end.traversal(hunk.old_start))); } static void get_new_extent(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; - info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.new_end.Traversal(hunk.new_start))); + info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.new_end.traversal(hunk.new_start))); } static void to_string(const Nan::FunctionCallbackInfo &info) { diff --git a/src/core/marker-index.cc b/src/core/marker-index.cc index 6f59c2fb..5c652bcc 100644 --- a/src/core/marker-index.cc +++ b/src/core/marker-index.cc @@ -42,7 +42,7 @@ MarkerIndex::Node *MarkerIndex::Iterator::insert_marker_start(const MarkerId &id } while (true) { - switch (start_position.Compare(current_node_position)) { + switch (start_position.compare(current_node_position)) { case 0: mark_right(id, start_position, end_position); return current_node; @@ -79,7 +79,7 @@ MarkerIndex::Node *MarkerIndex::Iterator::insert_marker_end(const MarkerId &id, } while (true) { - switch (end_position.Compare(current_node_position)) { + switch (end_position.compare(current_node_position)) { case 0: mark_left(id, start_position, end_position); return current_node; @@ -112,7 +112,7 @@ MarkerIndex::Node *MarkerIndex::Iterator::insert_splice_boundary(const Point &po reset(); while (true) { - int comparison = position.Compare(current_node_position); + int comparison = position.compare(current_node_position); if (comparison == 0 && !is_insertion_end) { return current_node; } else if (comparison < 0) { @@ -266,7 +266,7 @@ void MarkerIndex::Iterator::descend_left() { right_ancestor_position = current_node_position; current_node = current_node->left; - current_node_position = left_ancestor_position.Traverse(current_node->left_extent); + current_node_position = left_ancestor_position.traverse(current_node->left_extent); } void MarkerIndex::Iterator::descend_right() { @@ -275,7 +275,7 @@ void MarkerIndex::Iterator::descend_right() { left_ancestor_position = current_node_position; current_node = current_node->right; - current_node_position = left_ancestor_position.Traverse(current_node->left_extent); + current_node_position = left_ancestor_position.traverse(current_node->left_extent); } void MarkerIndex::Iterator::move_to_successor() { @@ -326,17 +326,17 @@ void MarkerIndex::Iterator::mark_right(const MarkerId &id, const Point &start_po } void MarkerIndex::Iterator::mark_left(const MarkerId &id, const Point &start_position, const Point &end_position) { - if (!current_node_position.IsZero() && start_position <= left_ancestor_position && current_node_position <= end_position) { + if (!current_node_position.is_zero() && start_position <= left_ancestor_position && current_node_position <= end_position) { current_node->left_marker_ids.insert(id); } } MarkerIndex::Node *MarkerIndex::Iterator::insert_left_child(const Point &position) { - return current_node->left = new Node(current_node, position.Traversal(left_ancestor_position)); + return current_node->left = new Node(current_node, position.traversal(left_ancestor_position)); } MarkerIndex::Node *MarkerIndex::Iterator::insert_right_child(const Point &position) { - return current_node->right = new Node(current_node, position.Traversal(current_node_position)); + return current_node->right = new Node(current_node, position.traversal(current_node_position)); } void MarkerIndex::Iterator::check_intersection(const Point &start, const Point &end, MarkerIdSet *result) { @@ -440,11 +440,11 @@ MarkerIndex::SpliceResult MarkerIndex::splice(Point start, Point old_extent, Poi SpliceResult invalidated; - if (!root || (old_extent.IsZero() && new_extent.IsZero())) return invalidated; + if (!root || (old_extent.is_zero() && new_extent.is_zero())) return invalidated; - bool is_insertion = old_extent.IsZero(); + bool is_insertion = old_extent.is_zero(); Node *start_node = iterator.insert_splice_boundary(start, false); - Node *end_node = iterator.insert_splice_boundary(start.Traverse(old_extent), is_insertion); + Node *end_node = iterator.insert_splice_boundary(start.traverse(old_extent), is_insertion); start_node->priority = -1; bubble_node_up(start_node); @@ -522,7 +522,7 @@ MarkerIndex::SpliceResult MarkerIndex::splice(Point start, Point old_extent, Poi start_node->right = nullptr; } - end_node->left_extent = start.Traverse(new_extent); + end_node->left_extent = start.traverse(new_extent); if (start_node->left_extent == end_node->left_extent) { for (MarkerId id : end_node->start_marker_ids) { @@ -578,13 +578,13 @@ Range MarkerIndex::get_range(MarkerId id) const { } int MarkerIndex::compare(MarkerId id1, MarkerId id2) const { - switch (get_start(id1).Compare(get_start(id2))) { + switch (get_start(id1).compare(get_start(id2))) { case -1: return -1; case 1: return 1; default: - return get_end(id2).Compare(get_end(id1)); + return get_end(id2).compare(get_end(id1)); } } @@ -649,7 +649,7 @@ Point MarkerIndex::get_node_position(const Node *node) const { const Node *current_node = node; while (current_node->parent) { if (current_node->parent->right == current_node) { - position = current_node->parent->left_extent.Traverse(position); + position = current_node->parent->left_extent.traverse(position); } current_node = current_node->parent; @@ -733,7 +733,7 @@ void MarkerIndex::rotate_node_left(Node *rotation_pivot) { rotation_pivot->left = rotation_root; rotation_root->parent = rotation_pivot; - rotation_pivot->left_extent = rotation_root->left_extent.Traverse(rotation_pivot->left_extent); + rotation_pivot->left_extent = rotation_root->left_extent.traverse(rotation_pivot->left_extent); rotation_pivot->right_marker_ids.insert(rotation_root->right_marker_ids.begin(), rotation_root->right_marker_ids.end()); @@ -770,7 +770,7 @@ void MarkerIndex::rotate_node_right(Node *rotation_pivot) { rotation_pivot->right = rotation_root; rotation_root->parent = rotation_pivot; - rotation_root->left_extent = rotation_root->left_extent.Traversal(rotation_pivot->left_extent); + rotation_root->left_extent = rotation_root->left_extent.traversal(rotation_pivot->left_extent); for (auto it = rotation_root->left_marker_ids.begin(); it != rotation_root->left_marker_ids.end(); ++it) { if (!rotation_pivot->start_marker_ids.count(*it)) { diff --git a/src/core/patch.cc b/src/core/patch.cc index c2a182b2..50a86e8f 100644 --- a/src/core/patch.cc +++ b/src/core/patch.cc @@ -35,13 +35,13 @@ struct Patch::Node { void get_subtree_end(Point *old_end, Point *new_end) { Node *node = this; - *old_end = Point::Zero(); - *new_end = Point::Zero(); + *old_end = Point(); + *new_end = Point(); while (node) { - *old_end = old_end->Traverse(node->old_distance_from_left_ancestor) - .Traverse(node->old_extent); - *new_end = new_end->Traverse(node->new_distance_from_left_ancestor) - .Traverse(node->new_extent); + *old_end = old_end->traverse(node->old_distance_from_left_ancestor) + .traverse(node->old_extent); + *new_end = new_end->traverse(node->new_distance_from_left_ancestor) + .traverse(node->new_extent); node = node->right; } } @@ -73,10 +73,10 @@ struct Patch::Node { } void write_dot_graph(std::stringstream &result, Point left_ancestor_old_end, Point left_ancestor_new_end) { - Point node_old_start = left_ancestor_old_end.Traverse(old_distance_from_left_ancestor); - Point node_new_start = left_ancestor_new_end.Traverse(new_distance_from_left_ancestor); - Point node_old_end = node_old_start.Traverse(old_extent); - Point node_new_end = node_new_start.Traverse(new_extent); + Point node_old_start = left_ancestor_old_end.traverse(old_distance_from_left_ancestor); + Point node_new_start = left_ancestor_new_end.traverse(new_distance_from_left_ancestor); + Point node_old_end = node_old_start.traverse(old_extent); + Point node_new_end = node_new_start.traverse(new_extent); result << "node_" << this << " [" << "label=\"" @@ -106,10 +106,10 @@ struct Patch::Node { } void write_json(std::stringstream &result, Point left_ancestor_old_end, Point left_ancestor_new_end) { - Point node_old_start = left_ancestor_old_end.Traverse(old_distance_from_left_ancestor); - Point node_new_start = left_ancestor_new_end.Traverse(new_distance_from_left_ancestor); - Point node_old_end = node_old_start.Traverse(old_extent); - Point node_new_end = node_new_start.Traverse(new_extent); + Point node_old_start = left_ancestor_old_end.traverse(old_distance_from_left_ancestor); + Point node_new_start = left_ancestor_new_end.traverse(new_distance_from_left_ancestor); + Point node_old_end = node_old_start.traverse(old_extent); + Point node_new_end = node_new_start.traverse(new_extent); result << "{"; result << "\"id\": \"" << this << "\", "; @@ -185,16 +185,16 @@ Patch::Patch(const vector &patches_to_compose) : Patch() { if (left_to_right) { for (auto iter = hunks.begin(), end = hunks.end(); iter != end; ++iter) { - splice(iter->new_start, iter->old_end.Traversal(iter->old_start), - iter->new_end.Traversal(iter->new_start), + splice(iter->new_start, iter->old_end.traversal(iter->old_start), + iter->new_end.traversal(iter->new_start), iter->old_text ? unique_ptr{new Text(*iter->old_text)} : nullptr, iter->new_text ? unique_ptr{new Text(*iter->new_text)} : nullptr); } } else { for (auto iter = hunks.rbegin(), end = hunks.rend(); iter != end; ++iter) { - splice(iter->old_start, iter->old_end.Traversal(iter->old_start), - iter->new_end.Traversal(iter->new_start), + splice(iter->old_start, iter->old_end.traversal(iter->old_start), + iter->new_end.traversal(iter->new_start), iter->old_text ? unique_ptr{new Text(*iter->old_text)} : nullptr, iter->new_text ? unique_ptr{new Text(*iter->new_text)} : nullptr); } @@ -253,20 +253,20 @@ void Patch::delete_node(Node **node_to_delete) { template Patch::Node *Patch::splay_node_ending_before(Point target) { Node *splayed_node = nullptr; - Point left_ancestor_end = Point::Zero(); + Point left_ancestor_end = Point(); Node *node = root; node_stack.clear(); size_t splayed_node_ancestor_count = 0; while (node) { - Point node_start = left_ancestor_end.Traverse( + Point node_start = left_ancestor_end.traverse( CoordinateSpace::distance_from_left_ancestor(node)); - Point node_end = node_start.Traverse(CoordinateSpace::extent(node)); + Point node_end = node_start.traverse(CoordinateSpace::extent(node)); if (node_end <= target) { splayed_node = node; splayed_node_ancestor_count = node_stack.size(); if (node->right) { - left_ancestor_end = node_start.Traverse(CoordinateSpace::extent(node)); + left_ancestor_end = node_start.traverse(CoordinateSpace::extent(node)); node_stack.push_back(node); node = node->right; } else { @@ -293,15 +293,15 @@ Patch::Node *Patch::splay_node_ending_before(Point target) { template Patch::Node *Patch::splay_node_starting_before(Point target) { Node *splayed_node = nullptr; - Point left_ancestor_end = Point::Zero(); + Point left_ancestor_end = Point(); Node *node = root; node_stack.clear(); size_t splayed_node_ancestor_count = 0; while (node) { - Point node_start = left_ancestor_end.Traverse( + Point node_start = left_ancestor_end.traverse( CoordinateSpace::distance_from_left_ancestor(node)); - Point node_end = node_start.Traverse(CoordinateSpace::extent(node)); + Point node_end = node_start.traverse(CoordinateSpace::extent(node)); if (node_start <= target) { splayed_node = node; splayed_node_ancestor_count = node_stack.size(); @@ -333,15 +333,15 @@ Patch::Node *Patch::splay_node_starting_before(Point target) { template Patch::Node *Patch::splay_node_ending_after(Point splice_start, Point splice_end) { Node *splayed_node = nullptr; - Point left_ancestor_end = Point::Zero(); + Point left_ancestor_end = Point(); Node *node = root; node_stack.clear(); size_t splayed_node_ancestor_count = 0; while (node) { - Point node_start = left_ancestor_end.Traverse( + Point node_start = left_ancestor_end.traverse( CoordinateSpace::distance_from_left_ancestor(node)); - Point node_end = node_start.Traverse(CoordinateSpace::extent(node)); + Point node_end = node_start.traverse(CoordinateSpace::extent(node)); if (node_end >= splice_end && node_end > splice_start) { splayed_node = node; splayed_node_ancestor_count = node_stack.size(); @@ -373,15 +373,15 @@ Patch::Node *Patch::splay_node_ending_after(Point splice_start, Point splice_end template Patch::Node *Patch::splay_node_starting_after(Point splice_start, Point splice_end) { Node *splayed_node = nullptr; - Point left_ancestor_end = Point::Zero(); + Point left_ancestor_end = Point(); Node *node = root; node_stack.clear(); size_t splayed_node_ancestor_count = 0; while (node) { - Point node_start = left_ancestor_end.Traverse( + Point node_start = left_ancestor_end.traverse( CoordinateSpace::distance_from_left_ancestor(node)); - Point node_end = node_start.Traverse(CoordinateSpace::extent(node)); + Point node_end = node_start.traverse(CoordinateSpace::extent(node)); if (node_start >= splice_end && node_start > splice_start) { splayed_node = node; splayed_node_ancestor_count = node_stack.size(); @@ -420,7 +420,7 @@ vector Patch::get_hunks_in_range(Point start, Point end, bool inclusive) { node_stack.clear(); left_ancestor_stack.clear(); - left_ancestor_stack.push_back({Point::Zero(), Point::Zero()}); + left_ancestor_stack.push_back({Point(), Point()}); Node *node = root; if (!lower_bound) { @@ -433,12 +433,12 @@ vector Patch::get_hunks_in_range(Point start, Point end, bool inclusive) { while (node) { Patch::PositionStackEntry &left_ancestor_position = left_ancestor_stack.back(); - Point old_start = left_ancestor_position.old_end.Traverse( + Point old_start = left_ancestor_position.old_end.traverse( node->old_distance_from_left_ancestor); - Point new_start = left_ancestor_position.new_end.Traverse( + Point new_start = left_ancestor_position.new_end.traverse( node->new_distance_from_left_ancestor); - Point old_end = old_start.Traverse(node->old_extent); - Point new_end = new_start.Traverse(node->new_extent); + Point old_end = old_start.traverse(node->old_extent); + Point new_end = new_start.traverse(node->new_extent); Text *old_text = node->old_text.get(); Text *new_text = node->new_text.get(); Hunk hunk = {old_start, old_end, new_start, new_end, old_text, new_text}; @@ -496,8 +496,8 @@ optional Patch::hunk_for_position(Point target) { if (lower_bound) { Point old_start = lower_bound->old_distance_from_left_ancestor; Point new_start = lower_bound->new_distance_from_left_ancestor; - Point old_end = old_start.Traverse(lower_bound->old_extent); - Point new_end = new_start.Traverse(lower_bound->new_extent); + Point old_end = old_start.traverse(lower_bound->old_extent); + Point new_end = new_start.traverse(lower_bound->new_extent); Text *old_text = lower_bound->old_text.get(); Text *new_text = lower_bound->new_text.get(); return Hunk{old_start, old_end, new_start, new_end, old_text, new_text}; @@ -513,7 +513,7 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, return false; } - if (new_deletion_extent.IsZero() && new_insertion_extent.IsZero()) { + if (new_deletion_extent.is_zero() && new_insertion_extent.is_zero()) { return true; } @@ -524,8 +524,8 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, return true; } - Point new_deletion_end = new_splice_start.Traverse(new_deletion_extent); - Point new_insertion_end = new_splice_start.Traverse(new_insertion_extent); + Point new_deletion_end = new_splice_start.traverse(new_deletion_extent); + Point new_insertion_end = new_splice_start.traverse(new_insertion_extent); Node *lower_bound = splay_node_starting_before(new_splice_start); unique_ptr old_text = @@ -544,13 +544,13 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, Point upper_bound_old_start = upper_bound->old_distance_from_left_ancestor; Point upper_bound_new_start = upper_bound->new_distance_from_left_ancestor; Point lower_bound_old_end = - lower_bound_old_start.Traverse(lower_bound->old_extent); + lower_bound_old_start.traverse(lower_bound->old_extent); Point lower_bound_new_end = - lower_bound_new_start.Traverse(lower_bound->new_extent); + lower_bound_new_start.traverse(lower_bound->new_extent); Point upper_bound_old_end = - upper_bound_old_start.Traverse(upper_bound->old_extent); + upper_bound_old_start.traverse(upper_bound->old_extent); Point upper_bound_new_end = - upper_bound_new_start.Traverse(upper_bound->new_extent); + upper_bound_new_start.traverse(upper_bound->new_extent); bool overlaps_lower_bound, overlaps_upper_bound; if (merges_adjacent_hunks) { @@ -565,13 +565,13 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, if (overlaps_lower_bound && overlaps_upper_bound) { Point new_extent_prefix = - new_splice_start.Traversal(lower_bound_new_start); - Point new_extent_suffix = upper_bound_new_end.Traversal(new_deletion_end); + new_splice_start.traversal(lower_bound_new_start); + Point new_extent_suffix = upper_bound_new_end.traversal(new_deletion_end); upper_bound->old_extent = - upper_bound_old_end.Traversal(lower_bound_old_start); - upper_bound->new_extent = new_extent_prefix.Traverse(new_insertion_extent) - .Traverse(new_extent_suffix); + upper_bound_old_end.traversal(lower_bound_old_start); + upper_bound->new_extent = new_extent_prefix.traverse(new_insertion_extent) + .traverse(new_extent_suffix); upper_bound->old_distance_from_left_ancestor = lower_bound_old_start; upper_bound->new_distance_from_left_ancestor = lower_bound_new_start; @@ -579,7 +579,7 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, TextSlice new_text_prefix = TextSlice(*lower_bound->new_text).Prefix(new_extent_prefix); TextSlice new_text_suffix = TextSlice(*upper_bound->new_text).Suffix( - new_deletion_end.Traversal(upper_bound_new_start)); + new_deletion_end.traversal(upper_bound_new_start)); upper_bound->new_text = unique_ptr{new Text(TextSlice::Concat( new_text_prefix, TextSlice(*inserted_text), new_text_suffix))}; } else { @@ -589,7 +589,7 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, upper_bound->old_text = move(old_text); if (lower_bound == upper_bound) { - if (root->old_extent.IsZero() && root->new_extent.IsZero()) { + if (root->old_extent.is_zero() && root->new_extent.is_zero()) { delete_root(); } } else { @@ -599,19 +599,19 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, } } else if (overlaps_upper_bound) { - Point old_splice_start = lower_bound_old_end.Traverse( - new_splice_start.Traversal(lower_bound_new_end)); - Point new_extent_suffix = upper_bound_new_end.Traversal(new_deletion_end); + Point old_splice_start = lower_bound_old_end.traverse( + new_splice_start.traversal(lower_bound_new_end)); + Point new_extent_suffix = upper_bound_new_end.traversal(new_deletion_end); upper_bound->old_distance_from_left_ancestor = old_splice_start; upper_bound->new_distance_from_left_ancestor = new_splice_start; - upper_bound->old_extent = upper_bound_old_end.Traversal(old_splice_start); + upper_bound->old_extent = upper_bound_old_end.traversal(old_splice_start); upper_bound->new_extent = - new_insertion_extent.Traverse(new_extent_suffix); + new_insertion_extent.traverse(new_extent_suffix); if (inserted_text && upper_bound->new_text) { TextSlice new_text_suffix = TextSlice(*upper_bound->new_text).Suffix( - new_deletion_end.Traversal(upper_bound_new_start)); + new_deletion_end.traversal(upper_bound_new_start)); upper_bound->new_text = unique_ptr{new Text(TextSlice::Concat(TextSlice(*inserted_text), new_text_suffix))}; } else { @@ -629,17 +629,17 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, Point rightmost_child_old_end, rightmost_child_new_end; lower_bound->get_subtree_end(&rightmost_child_old_end, &rightmost_child_new_end); - Point old_deletion_end = rightmost_child_old_end.Traverse( - new_deletion_end.Traversal(rightmost_child_new_end)); + Point old_deletion_end = rightmost_child_old_end.traverse( + new_deletion_end.traversal(rightmost_child_new_end)); Point new_extent_prefix = - new_splice_start.Traversal(lower_bound_new_start); + new_splice_start.traversal(lower_bound_new_start); - upper_bound->new_distance_from_left_ancestor = new_insertion_end.Traverse( - upper_bound_new_start.Traversal(new_deletion_end)); + upper_bound->new_distance_from_left_ancestor = new_insertion_end.traverse( + upper_bound_new_start.traversal(new_deletion_end)); lower_bound->old_extent = - old_deletion_end.Traversal(lower_bound_old_start); + old_deletion_end.traversal(lower_bound_old_start); lower_bound->new_extent = - new_extent_prefix.Traverse(new_insertion_extent); + new_extent_prefix.traverse(new_insertion_extent); if (inserted_text && lower_bound->new_text) { TextSlice new_text_prefix = TextSlice(*lower_bound->new_text).Prefix(new_extent_prefix); @@ -660,37 +660,37 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, // that node with merges_adjacent_hunks set to false. if (lower_bound == upper_bound) { assert(!merges_adjacent_hunks); - assert(new_deletion_extent.IsZero()); + assert(new_deletion_extent.is_zero()); assert(new_splice_start == upper_bound_new_start); root = build_node(upper_bound->left, upper_bound, upper_bound_old_start, - upper_bound_new_start, Point::Zero(), + upper_bound_new_start, Point(), new_insertion_extent, move(old_text), move(inserted_text)); upper_bound->left = nullptr; - upper_bound->old_distance_from_left_ancestor = Point::Zero(); - upper_bound->new_distance_from_left_ancestor = Point::Zero(); + upper_bound->old_distance_from_left_ancestor = Point(); + upper_bound->new_distance_from_left_ancestor = Point(); } else { Point rightmost_child_old_end, rightmost_child_new_end; lower_bound->get_subtree_end(&rightmost_child_old_end, &rightmost_child_new_end); - Point old_splice_start = lower_bound_old_end.Traverse( - new_splice_start.Traversal(lower_bound_new_end)); - Point old_deletion_end = rightmost_child_old_end.Traverse( - new_deletion_end.Traversal(rightmost_child_new_end)); + Point old_splice_start = lower_bound_old_end.traverse( + new_splice_start.traversal(lower_bound_new_end)); + Point old_deletion_end = rightmost_child_old_end.traverse( + new_deletion_end.traversal(rightmost_child_new_end)); root = build_node( lower_bound, upper_bound, old_splice_start, new_splice_start, - old_deletion_end.Traversal(old_splice_start), new_insertion_extent, + old_deletion_end.traversal(old_splice_start), new_insertion_extent, move(old_text), move(inserted_text)); delete_node(&lower_bound->right); upper_bound->left = nullptr; upper_bound->old_distance_from_left_ancestor = - upper_bound_old_start.Traversal(old_deletion_end); + upper_bound_old_start.traversal(old_deletion_end); upper_bound->new_distance_from_left_ancestor = - upper_bound_new_start.Traversal(new_deletion_end); + upper_bound_new_start.traversal(new_deletion_end); } } @@ -698,14 +698,14 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, Point lower_bound_old_start = lower_bound->old_distance_from_left_ancestor; Point lower_bound_new_start = lower_bound->new_distance_from_left_ancestor; Point lower_bound_new_end = - lower_bound_new_start.Traverse(lower_bound->new_extent); + lower_bound_new_start.traverse(lower_bound->new_extent); Point lower_bound_old_end = - lower_bound_old_start.Traverse(lower_bound->old_extent); + lower_bound_old_start.traverse(lower_bound->old_extent); Point rightmost_child_old_end, rightmost_child_new_end; lower_bound->get_subtree_end(&rightmost_child_old_end, &rightmost_child_new_end); - Point old_deletion_end = rightmost_child_old_end.Traverse( - new_deletion_end.Traversal(rightmost_child_new_end)); + Point old_deletion_end = rightmost_child_old_end.traverse( + new_deletion_end.traversal(rightmost_child_new_end)); bool overlaps_lower_bound = new_splice_start < lower_bound_new_end || (merges_adjacent_hunks && new_splice_start == lower_bound_new_end); @@ -714,12 +714,12 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, if (overlaps_lower_bound) { lower_bound->old_extent = - old_deletion_end.Traversal(lower_bound_old_start); + old_deletion_end.traversal(lower_bound_old_start); lower_bound->new_extent = - new_insertion_end.Traversal(lower_bound_new_start); + new_insertion_end.traversal(lower_bound_new_start); if (inserted_text && lower_bound->new_text) { TextSlice new_text_prefix = TextSlice(*lower_bound->new_text).Prefix( - new_splice_start.Traversal(lower_bound_new_start)); + new_splice_start.traversal(lower_bound_new_start)); lower_bound->new_text = unique_ptr{new Text(TextSlice::Concat(new_text_prefix, TextSlice(*inserted_text)))}; } else { @@ -728,11 +728,11 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, lower_bound->old_text = move(old_text); } else { - Point old_splice_start = lower_bound_old_end.Traverse( - new_splice_start.Traversal(lower_bound_new_end)); + Point old_splice_start = lower_bound_old_end.traverse( + new_splice_start.traversal(lower_bound_new_end)); root = build_node(lower_bound, nullptr, old_splice_start, new_splice_start, - old_deletion_end.Traversal(old_splice_start), + old_deletion_end.traversal(old_splice_start), new_insertion_extent, move(old_text), move(inserted_text)); } @@ -740,7 +740,7 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, Point upper_bound_new_start = upper_bound->new_distance_from_left_ancestor; Point upper_bound_old_start = upper_bound->old_distance_from_left_ancestor; Point upper_bound_new_end = - upper_bound_new_start.Traverse(upper_bound->new_extent); + upper_bound_new_start.traverse(upper_bound->new_extent); bool overlaps_upper_bound = new_deletion_end > upper_bound_new_start || (merges_adjacent_hunks && new_deletion_end == upper_bound_new_start); @@ -750,8 +750,8 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, Point rightmost_child_old_end, rightmost_child_new_end; upper_bound->left->get_subtree_end(&rightmost_child_old_end, &rightmost_child_new_end); - old_deletion_end = rightmost_child_old_end.Traverse( - new_deletion_end.Traversal(rightmost_child_new_end)); + old_deletion_end = rightmost_child_old_end.traverse( + new_deletion_end.traversal(rightmost_child_new_end)); } else { old_deletion_end = new_deletion_end; } @@ -761,14 +761,14 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, upper_bound->old_distance_from_left_ancestor = new_splice_start; upper_bound->new_distance_from_left_ancestor = new_splice_start; upper_bound->old_extent = - upper_bound_old_start.Traversal(new_splice_start) - .Traverse(upper_bound->old_extent); - upper_bound->new_extent = new_insertion_extent.Traverse( - upper_bound_new_end.Traversal(new_deletion_end)); + upper_bound_old_start.traversal(new_splice_start) + .traverse(upper_bound->old_extent); + upper_bound->new_extent = new_insertion_extent.traverse( + upper_bound_new_end.traversal(new_deletion_end)); if (inserted_text && upper_bound->new_text) { TextSlice new_text_suffix = TextSlice(*upper_bound->new_text).Suffix( - new_deletion_end.Traversal(upper_bound_new_start)); + new_deletion_end.traversal(upper_bound_new_start)); upper_bound->new_text = unique_ptr{new Text(TextSlice::Concat(TextSlice(*inserted_text), new_text_suffix))}; } else { @@ -779,10 +779,10 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, } else { root = build_node(nullptr, upper_bound, new_splice_start, new_splice_start, - old_deletion_end.Traversal(new_splice_start), + old_deletion_end.traversal(new_splice_start), new_insertion_extent, move(old_text), move(inserted_text)); Point distance_from_end_of_root_to_start_of_upper_bound = - upper_bound_new_start.Traversal(new_deletion_end); + upper_bound_new_start.traversal(new_deletion_end); upper_bound->old_distance_from_left_ancestor = distance_from_end_of_root_to_start_of_upper_bound; upper_bound->new_distance_from_left_ancestor = @@ -792,11 +792,11 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, } else { Point rightmost_child_old_end, rightmost_child_new_end; root->get_subtree_end(&rightmost_child_old_end, &rightmost_child_new_end); - Point old_deletion_end = rightmost_child_old_end.Traverse( - new_deletion_end.Traversal(rightmost_child_new_end)); + Point old_deletion_end = rightmost_child_old_end.traverse( + new_deletion_end.traversal(rightmost_child_new_end)); delete_node(&root); root = build_node(nullptr, nullptr, new_splice_start, new_splice_start, - old_deletion_end.Traversal(new_splice_start), + old_deletion_end.traversal(new_splice_start), new_insertion_extent, move(old_text), move(inserted_text)); } @@ -813,8 +813,8 @@ bool Patch::splice_old(Point old_splice_start, Point old_deletion_extent, return true; } - Point old_deletion_end = old_splice_start.Traverse(old_deletion_extent); - Point old_insertion_end = old_splice_start.Traverse(old_insertion_extent); + Point old_deletion_end = old_splice_start.traverse(old_deletion_extent); + Point old_insertion_end = old_splice_start.traverse(old_insertion_extent); Node *lower_bound = splay_node_ending_before(old_splice_start); Node *upper_bound = splay_node_starting_after(old_splice_start, @@ -826,12 +826,12 @@ bool Patch::splice_old(Point old_splice_start, Point old_deletion_extent, } if (upper_bound == lower_bound) { - assert(upper_bound->old_extent.IsZero()); - assert(old_deletion_extent.IsZero()); + assert(upper_bound->old_extent.is_zero()); + assert(old_deletion_extent.is_zero()); root->old_distance_from_left_ancestor = - root->old_distance_from_left_ancestor.Traverse(old_insertion_extent); + root->old_distance_from_left_ancestor.traverse(old_insertion_extent); root->new_distance_from_left_ancestor = - root->new_distance_from_left_ancestor.Traverse(old_insertion_extent); + root->new_distance_from_left_ancestor.traverse(old_insertion_extent); return true; } @@ -847,13 +847,13 @@ bool Patch::splice_old(Point old_splice_start, Point old_deletion_extent, Point lower_bound_old_start = lower_bound->old_distance_from_left_ancestor; Point lower_bound_new_start = lower_bound->new_distance_from_left_ancestor; Point lower_bound_old_end = - lower_bound_old_start.Traverse(lower_bound->old_extent); + lower_bound_old_start.traverse(lower_bound->old_extent); Point lower_bound_new_end = - lower_bound_new_start.Traverse(lower_bound->new_extent); - new_deletion_end = lower_bound_new_end.Traverse( - old_deletion_end.Traversal(lower_bound_old_end)); - new_insertion_end = lower_bound_new_end.Traverse( - old_insertion_end.Traversal(lower_bound_old_end)); + lower_bound_new_start.traverse(lower_bound->new_extent); + new_deletion_end = lower_bound_new_end.traverse( + old_deletion_end.traversal(lower_bound_old_end)); + new_insertion_end = lower_bound_new_end.traverse( + old_insertion_end.traversal(lower_bound_old_end)); delete_node(&lower_bound->right); } else { @@ -863,15 +863,15 @@ bool Patch::splice_old(Point old_splice_start, Point old_deletion_extent, if (upper_bound) { Point distance_between_splice_and_upper_bound = - upper_bound->old_distance_from_left_ancestor.Traversal( + upper_bound->old_distance_from_left_ancestor.traversal( old_deletion_end); upper_bound->old_distance_from_left_ancestor = - old_insertion_end.Traverse(distance_between_splice_and_upper_bound); + old_insertion_end.traverse(distance_between_splice_and_upper_bound); upper_bound->new_distance_from_left_ancestor = - new_insertion_end.Traverse(distance_between_splice_and_upper_bound); + new_insertion_end.traverse(distance_between_splice_and_upper_bound); if (lower_bound) { - if (lower_bound->old_distance_from_left_ancestor.Traverse( + if (lower_bound->old_distance_from_left_ancestor.traverse( lower_bound->old_extent) == upper_bound->old_distance_from_left_ancestor) { upper_bound->old_distance_from_left_ancestor = @@ -879,9 +879,9 @@ bool Patch::splice_old(Point old_splice_start, Point old_deletion_extent, upper_bound->new_distance_from_left_ancestor = lower_bound->new_distance_from_left_ancestor; upper_bound->old_extent = - lower_bound->old_extent.Traverse(upper_bound->old_extent); + lower_bound->old_extent.traverse(upper_bound->old_extent); upper_bound->new_extent = - lower_bound->new_extent.Traverse(upper_bound->new_extent); + lower_bound->new_extent.traverse(upper_bound->new_extent); upper_bound->left = lower_bound->left; delete_node(&lower_bound); } @@ -998,11 +998,11 @@ void Patch::rotate_node_left(Node *pivot, Node *root, Node *root_parent) { pivot->left = root; pivot->old_distance_from_left_ancestor = - root->old_distance_from_left_ancestor.Traverse(root->old_extent) - .Traverse(pivot->old_distance_from_left_ancestor); + root->old_distance_from_left_ancestor.traverse(root->old_extent) + .traverse(pivot->old_distance_from_left_ancestor); pivot->new_distance_from_left_ancestor = - root->new_distance_from_left_ancestor.Traverse(root->new_extent) - .Traverse(pivot->new_distance_from_left_ancestor); + root->new_distance_from_left_ancestor.traverse(root->new_extent) + .traverse(pivot->new_distance_from_left_ancestor); } void Patch::rotate_node_right(Node *pivot, Node *root, Node *root_parent) { @@ -1020,11 +1020,11 @@ void Patch::rotate_node_right(Node *pivot, Node *root, Node *root_parent) { pivot->right = root; root->old_distance_from_left_ancestor = - root->old_distance_from_left_ancestor.Traversal( - pivot->old_distance_from_left_ancestor.Traverse(pivot->old_extent)); + root->old_distance_from_left_ancestor.traversal( + pivot->old_distance_from_left_ancestor.traverse(pivot->old_extent)); root->new_distance_from_left_ancestor = - root->new_distance_from_left_ancestor.Traversal( - pivot->new_distance_from_left_ancestor.Traverse(pivot->new_extent)); + root->new_distance_from_left_ancestor.traversal( + pivot->new_distance_from_left_ancestor.traverse(pivot->new_extent)); } void Patch::delete_root() { @@ -1050,14 +1050,14 @@ void Patch::delete_root() { std::string Patch::get_dot_graph() const { std::stringstream result; result << "digraph patch {" << endl; - if (root) root->write_dot_graph(result, Point::Zero(), Point::Zero()); + if (root) root->write_dot_graph(result, Point(), Point()); result << "}" << endl; return result.str(); } std::string Patch::get_json() const { std::stringstream result; - if (root) root->write_json(result, Point::Zero(), Point::Zero()); + if (root) root->write_json(result, Point(), Point()); return result.str(); } @@ -1114,7 +1114,7 @@ vector Patch::get_hunks() const { Node *node = root; node_stack.clear(); left_ancestor_stack.clear(); - left_ancestor_stack.push_back({Point::Zero(), Point::Zero()}); + left_ancestor_stack.push_back({Point(), Point()}); while (node->left) { node_stack.push_back(node); @@ -1123,12 +1123,12 @@ vector Patch::get_hunks() const { while (node) { PositionStackEntry &left_ancestor_position = left_ancestor_stack.back(); - Point old_start = left_ancestor_position.old_end.Traverse( + Point old_start = left_ancestor_position.old_end.traverse( node->old_distance_from_left_ancestor); - Point new_start = left_ancestor_position.new_end.Traverse( + Point new_start = left_ancestor_position.new_end.traverse( node->new_distance_from_left_ancestor); - Point old_end = old_start.Traverse(node->old_extent); - Point new_end = new_start.Traverse(node->new_extent); + Point old_end = old_start.traverse(node->old_extent); + Point new_end = new_start.traverse(node->new_extent); Text *old_text = node->old_text.get(); Text *new_text = node->new_text.get(); result.push_back( @@ -1198,7 +1198,7 @@ unique_ptr Patch::compute_old_text(unique_ptr deleted_text, if (hunk.new_start > deleted_text_slice_start) { auto split_result = deleted_text_slice.Split( - hunk.new_start.Traversal(deleted_text_slice_start)); + hunk.new_start.traversal(deleted_text_slice_start)); deleted_text_slice_start = hunk.new_start; deleted_text_slice = split_result.second; result->insert(result->end(), split_result.first.begin(), split_result.first.end()); @@ -1206,7 +1206,7 @@ unique_ptr Patch::compute_old_text(unique_ptr deleted_text, result->insert(result->end(), hunk.old_text->begin(), hunk.old_text->end()); deleted_text_slice = deleted_text_slice.Suffix( - hunk.new_end.Traversal(deleted_text_slice_start)); + hunk.new_end.traversal(deleted_text_slice_start)); deleted_text_slice_start = hunk.new_end; } diff --git a/src/core/point.cc b/src/core/point.cc index 71ab8b0b..392a894e 100644 --- a/src/core/point.cc +++ b/src/core/point.cc @@ -1,15 +1,11 @@ #include #include "point.h" -Point Point::Zero() { - return Point(0, 0); -} - -Point Point::Min(const Point &left, const Point &right) { +Point Point::min(const Point &left, const Point &right) { return left <= right ? left : right; } -Point Point::Max(const Point &left, const Point &right) { +Point Point::max(const Point &left, const Point &right) { return left >= right ? left : right; } @@ -17,7 +13,7 @@ Point::Point() : Point(0, 0) {} Point::Point(unsigned row, unsigned column) : row {row}, column {column} {} -int Point::Compare(const Point &other) const { +int Point::compare(const Point &other) const { if (row < other.row) return -1; if (row > other.row) return 1; if (column < other.column) return -1; @@ -25,11 +21,11 @@ int Point::Compare(const Point &other) const { return 0; } -bool Point::IsZero() const { +bool Point::is_zero() const { return row == 0 && column == 0; } -Point Point::Traverse(const Point &traversal) const { +Point Point::traverse(const Point &traversal) const { if (traversal.row == 0) { return Point(row , column + traversal.column); } else { @@ -37,7 +33,7 @@ Point Point::Traverse(const Point &traversal) const { } } -Point Point::Traversal(const Point &start) const { +Point Point::traversal(const Point &start) const { if (row == start.row) { return Point(0, column - start.column); } else { @@ -46,21 +42,21 @@ Point Point::Traversal(const Point &start) const { } bool Point::operator==(const Point &other) const { - return Compare(other) == 0; + return compare(other) == 0; } bool Point::operator<(const Point &other) const { - return Compare(other) < 0; + return compare(other) < 0; } bool Point::operator<=(const Point &other) const { - return Compare(other) <= 0; + return compare(other) <= 0; } bool Point::operator>(const Point &other) const { - return Compare(other) > 0; + return compare(other) > 0; } bool Point::operator>=(const Point &other) const { - return Compare(other) >= 0; + return compare(other) >= 0; } diff --git a/src/core/point.h b/src/core/point.h index 343f7cd1..1885a96d 100644 --- a/src/core/point.h +++ b/src/core/point.h @@ -7,17 +7,16 @@ struct Point { unsigned row; unsigned column; - static Point Zero(); - static Point Min(const Point &left, const Point &right); - static Point Max(const Point &left, const Point &right); + static Point min(const Point &left, const Point &right); + static Point max(const Point &left, const Point &right); Point(); Point(unsigned row, unsigned column); - int Compare(const Point &other) const; - bool IsZero() const; - Point Traverse(const Point &other) const; - Point Traversal(const Point &other) const; + int compare(const Point &other) const; + bool is_zero() const; + Point traverse(const Point &other) const; + Point traversal(const Point &other) const; bool operator==(const Point &other) const; bool operator<(const Point &other) const; From aecb8b590da7fca3baf898d2fb21694dd8a22f3a Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 15 Jan 2017 10:35:10 -0700 Subject: [PATCH 5/8] Convert Text/TextSlice to new naming convention --- src/core/patch.cc | 26 +++++++++++++------------- src/core/text.cc | 14 +++++++------- src/core/text.h | 10 +++++----- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/core/patch.cc b/src/core/patch.cc index 50a86e8f..562c5c73 100644 --- a/src/core/patch.cc +++ b/src/core/patch.cc @@ -577,10 +577,10 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, if (inserted_text && lower_bound->new_text && upper_bound->new_text) { TextSlice new_text_prefix = - TextSlice(*lower_bound->new_text).Prefix(new_extent_prefix); - TextSlice new_text_suffix = TextSlice(*upper_bound->new_text).Suffix( + TextSlice(*lower_bound->new_text).prefix(new_extent_prefix); + TextSlice new_text_suffix = TextSlice(*upper_bound->new_text).suffix( new_deletion_end.traversal(upper_bound_new_start)); - upper_bound->new_text = unique_ptr{new Text(TextSlice::Concat( + upper_bound->new_text = unique_ptr{new Text(TextSlice::concat( new_text_prefix, TextSlice(*inserted_text), new_text_suffix))}; } else { upper_bound->new_text = nullptr; @@ -610,10 +610,10 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, new_insertion_extent.traverse(new_extent_suffix); if (inserted_text && upper_bound->new_text) { - TextSlice new_text_suffix = TextSlice(*upper_bound->new_text).Suffix( + TextSlice new_text_suffix = TextSlice(*upper_bound->new_text).suffix( new_deletion_end.traversal(upper_bound_new_start)); upper_bound->new_text = - unique_ptr{new Text(TextSlice::Concat(TextSlice(*inserted_text), new_text_suffix))}; + unique_ptr{new Text(TextSlice::concat(TextSlice(*inserted_text), new_text_suffix))}; } else { upper_bound->new_text = nullptr; } @@ -642,9 +642,9 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, new_extent_prefix.traverse(new_insertion_extent); if (inserted_text && lower_bound->new_text) { TextSlice new_text_prefix = - TextSlice(*lower_bound->new_text).Prefix(new_extent_prefix); + TextSlice(*lower_bound->new_text).prefix(new_extent_prefix); lower_bound->new_text = - unique_ptr{new Text(TextSlice::Concat(new_text_prefix, TextSlice(*inserted_text)))}; + unique_ptr{new Text(TextSlice::concat(new_text_prefix, TextSlice(*inserted_text)))}; } else { lower_bound->new_text = nullptr; } @@ -718,10 +718,10 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, lower_bound->new_extent = new_insertion_end.traversal(lower_bound_new_start); if (inserted_text && lower_bound->new_text) { - TextSlice new_text_prefix = TextSlice(*lower_bound->new_text).Prefix( + TextSlice new_text_prefix = TextSlice(*lower_bound->new_text).prefix( new_splice_start.traversal(lower_bound_new_start)); lower_bound->new_text = - unique_ptr{new Text(TextSlice::Concat(new_text_prefix, TextSlice(*inserted_text)))}; + unique_ptr{new Text(TextSlice::concat(new_text_prefix, TextSlice(*inserted_text)))}; } else { lower_bound->new_text = nullptr; } @@ -767,10 +767,10 @@ bool Patch::splice(Point new_splice_start, Point new_deletion_extent, upper_bound_new_end.traversal(new_deletion_end)); if (inserted_text && upper_bound->new_text) { - TextSlice new_text_suffix = TextSlice(*upper_bound->new_text).Suffix( + TextSlice new_text_suffix = TextSlice(*upper_bound->new_text).suffix( new_deletion_end.traversal(upper_bound_new_start)); upper_bound->new_text = - unique_ptr{new Text(TextSlice::Concat(TextSlice(*inserted_text), new_text_suffix))}; + unique_ptr{new Text(TextSlice::concat(TextSlice(*inserted_text), new_text_suffix))}; } else { upper_bound->new_text = nullptr; } @@ -1197,7 +1197,7 @@ unique_ptr Patch::compute_old_text(unique_ptr deleted_text, return nullptr; if (hunk.new_start > deleted_text_slice_start) { - auto split_result = deleted_text_slice.Split( + auto split_result = deleted_text_slice.split( hunk.new_start.traversal(deleted_text_slice_start)); deleted_text_slice_start = hunk.new_start; deleted_text_slice = split_result.second; @@ -1205,7 +1205,7 @@ unique_ptr Patch::compute_old_text(unique_ptr deleted_text, } result->insert(result->end(), hunk.old_text->begin(), hunk.old_text->end()); - deleted_text_slice = deleted_text_slice.Suffix( + deleted_text_slice = deleted_text_slice.suffix( hunk.new_end.traversal(deleted_text_slice_start)); deleted_text_slice_start = hunk.new_end; } diff --git a/src/core/text.cc b/src/core/text.cc index 9832dec4..47d08084 100644 --- a/src/core/text.cc +++ b/src/core/text.cc @@ -25,7 +25,7 @@ Text::iterator TextSlice::end() { return text->begin() + end_index; } -Text TextSlice::Concat(TextSlice a, TextSlice b) { +Text TextSlice::concat(TextSlice a, TextSlice b) { Text result; result.reserve(a.size() + b.size()); result.insert( @@ -41,7 +41,7 @@ Text TextSlice::Concat(TextSlice a, TextSlice b) { return result; } -Text TextSlice::Concat(TextSlice a, TextSlice b, TextSlice c) { +Text TextSlice::concat(TextSlice a, TextSlice b, TextSlice c) { Text result; result.reserve(a.size() + b.size() + c.size()); result.insert( @@ -66,7 +66,7 @@ TextSlice::operator Text() const { return Text(text->begin() + start_index, text->begin() + end_index); } -std::pair TextSlice::Split(Point position) { +std::pair TextSlice::split(Point position) { size_t index = character_index_for_position(position); return { TextSlice{text, start_index, start_index + index}, @@ -74,12 +74,12 @@ std::pair TextSlice::Split(Point position) { }; } -TextSlice TextSlice::Suffix(Point suffix_start) { - return Split(suffix_start).second; +TextSlice TextSlice::suffix(Point suffix_start) { + return split(suffix_start).second; } -TextSlice TextSlice::Prefix(Point prefix_end) { - return Split(prefix_end).first; +TextSlice TextSlice::prefix(Point prefix_end) { + return split(prefix_end).first; } size_t TextSlice::character_index_for_position(Point target) { diff --git a/src/core/text.h b/src/core/text.h index ff9bb114..b9045ad3 100644 --- a/src/core/text.h +++ b/src/core/text.h @@ -13,8 +13,8 @@ struct TextSlice { size_t start_index; size_t end_index; - static Text Concat(TextSlice a, TextSlice b); - static Text Concat(TextSlice a, TextSlice b, TextSlice c); + static Text concat(TextSlice a, TextSlice b); + static Text concat(TextSlice a, TextSlice b, TextSlice c); TextSlice(Text &text); TextSlice(Text *text, size_t start_index, size_t end_index); @@ -24,9 +24,9 @@ struct TextSlice { Text::iterator begin(); Text::iterator end(); - std::pair Split(Point); - TextSlice Prefix(Point); - TextSlice Suffix(Point); + std::pair split(Point); + TextSlice prefix(Point); + TextSlice suffix(Point); size_t character_index_for_position(Point); }; From 9c9931418fb2273f31a1a124a30300630e7720d4 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 15 Jan 2017 10:39:06 -0700 Subject: [PATCH 6/8] Convert PointWrapper to new naming convention --- src/bindings/bindings.cc | 2 +- src/bindings/buffer-offset-index-wrapper.cc | 4 +- src/bindings/marker-index-wrapper.cc | 46 ++++++++++----------- src/bindings/patch-wrapper.cc | 36 ++++++++-------- src/bindings/point-wrapper.cc | 18 ++++---- src/bindings/point-wrapper.h | 12 +++--- 6 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/bindings/bindings.cc b/src/bindings/bindings.cc index 4ebbeca0..d27a217e 100644 --- a/src/bindings/bindings.cc +++ b/src/bindings/bindings.cc @@ -7,7 +7,7 @@ using namespace v8; void Init(Local exports) { - PointWrapper::Init(); + PointWrapper::init(); PatchWrapper::init(exports); MarkerIndexWrapper::init(exports); BufferOffsetIndexWrapper::init(exports); diff --git a/src/bindings/buffer-offset-index-wrapper.cc b/src/bindings/buffer-offset-index-wrapper.cc index fcb5d881..d6836169 100644 --- a/src/bindings/buffer-offset-index-wrapper.cc +++ b/src/bindings/buffer-offset-index-wrapper.cc @@ -35,7 +35,7 @@ void BufferOffsetIndexWrapper::splice(const Nan::FunctionCallbackInfo &in void BufferOffsetIndexWrapper::character_index_for_position(const Nan::FunctionCallbackInfo &info) { BufferOffsetIndex &buffer_offset_index = Nan::ObjectWrap::Unwrap(info.This())->buffer_offset_index; - auto position = PointWrapper::PointFromJS(info[0]); + auto position = PointWrapper::point_from_js(info[0]); if (position) { auto result = buffer_offset_index.character_index_for_position(*position); info.GetReturnValue().Set(Nan::New(result)); @@ -48,6 +48,6 @@ void BufferOffsetIndexWrapper::position_for_character_index(const Nan::FunctionC auto character_index = Nan::To(info[0]); if (character_index.IsJust()) { auto result = buffer_offset_index.position_for_character_index(character_index.FromJust()); - info.GetReturnValue().Set(PointWrapper::FromPoint(result)); + info.GetReturnValue().Set(PointWrapper::from_point(result)); } } diff --git a/src/bindings/marker-index-wrapper.cc b/src/bindings/marker-index-wrapper.cc index 8fd7b06d..9d693935 100644 --- a/src/bindings/marker-index-wrapper.cc +++ b/src/bindings/marker-index-wrapper.cc @@ -86,8 +86,8 @@ Local MarkerIndexWrapper::snapshot_to_js(const unordered_map result_object = Nan::New(); for (auto &pair : snapshot) { Local range = Nan::New(); - range->Set(Nan::New(start_string), PointWrapper::FromPoint(pair.second.start)); - range->Set(Nan::New(end_string), PointWrapper::FromPoint(pair.second.end)); + range->Set(Nan::New(start_string), PointWrapper::from_point(pair.second.start)); + range->Set(Nan::New(end_string), PointWrapper::from_point(pair.second.end)); result_object->Set(Nan::New(pair.first), range); } return result_object; @@ -126,8 +126,8 @@ void MarkerIndexWrapper::insert(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); optional id = marker_id_from_js(info[0]); - optional start = PointWrapper::PointFromJS(info[1]); - optional end = PointWrapper::PointFromJS(info[2]); + optional start = PointWrapper::point_from_js(info[1]); + optional end = PointWrapper::point_from_js(info[2]); if (id && start && end) { wrapper->marker_index.insert(*id, *start, *end); @@ -157,9 +157,9 @@ void MarkerIndexWrapper::delete_marker(const Nan::FunctionCallbackInfo &i void MarkerIndexWrapper::splice(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional start = PointWrapper::PointFromJS(info[0]); - optional old_extent = PointWrapper::PointFromJS(info[1]); - optional new_extent = PointWrapper::PointFromJS(info[2]); + optional start = PointWrapper::point_from_js(info[0]); + optional old_extent = PointWrapper::point_from_js(info[1]); + optional new_extent = PointWrapper::point_from_js(info[2]); if (start && old_extent && new_extent) { MarkerIndex::SpliceResult result = wrapper->marker_index.splice(*start, *old_extent, *new_extent); @@ -179,7 +179,7 @@ void MarkerIndexWrapper::get_start(const Nan::FunctionCallbackInfo &info) optional id = marker_id_from_js(info[0]); if (id) { Point result = wrapper->marker_index.get_start(*id); - info.GetReturnValue().Set(PointWrapper::FromPoint(result)); + info.GetReturnValue().Set(PointWrapper::from_point(result)); } } @@ -189,7 +189,7 @@ void MarkerIndexWrapper::get_end(const Nan::FunctionCallbackInfo &info) { optional id = marker_id_from_js(info[0]); if (id) { Point result = wrapper->marker_index.get_end(*id); - info.GetReturnValue().Set(PointWrapper::FromPoint(result)); + info.GetReturnValue().Set(PointWrapper::from_point(result)); } } @@ -200,8 +200,8 @@ void MarkerIndexWrapper::get_range(const Nan::FunctionCallbackInfo &info) if (id) { Range range = wrapper->marker_index.get_range(*id); auto result = Nan::New(2); - result->Set(0, PointWrapper::FromPoint(range.start)); - result->Set(1, PointWrapper::FromPoint(range.end)); + result->Set(0, PointWrapper::from_point(range.start)); + result->Set(1, PointWrapper::from_point(range.end)); info.GetReturnValue().Set(result); } } @@ -218,8 +218,8 @@ void MarkerIndexWrapper::compare(const Nan::FunctionCallbackInfo &info) { void MarkerIndexWrapper::find_intersecting(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional start = PointWrapper::PointFromJS(info[0]); - optional end = PointWrapper::PointFromJS(info[1]); + optional start = PointWrapper::point_from_js(info[0]); + optional end = PointWrapper::point_from_js(info[1]); if (start && end) { MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_intersecting(*start, *end); @@ -230,8 +230,8 @@ void MarkerIndexWrapper::find_intersecting(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional start = PointWrapper::PointFromJS(info[0]); - optional end = PointWrapper::PointFromJS(info[1]); + optional start = PointWrapper::point_from_js(info[0]); + optional end = PointWrapper::point_from_js(info[1]); if (start && end) { MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_containing(*start, *end); @@ -242,8 +242,8 @@ void MarkerIndexWrapper::find_containing(const Nan::FunctionCallbackInfo void MarkerIndexWrapper::find_contained_in(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional start = PointWrapper::PointFromJS(info[0]); - optional end = PointWrapper::PointFromJS(info[1]); + optional start = PointWrapper::point_from_js(info[0]); + optional end = PointWrapper::point_from_js(info[1]); if (start && end) { MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_contained_in(*start, *end); @@ -254,8 +254,8 @@ void MarkerIndexWrapper::find_contained_in(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional start = PointWrapper::PointFromJS(info[0]); - optional end = PointWrapper::PointFromJS(info[1]); + optional start = PointWrapper::point_from_js(info[0]); + optional end = PointWrapper::point_from_js(info[1]); if (start && end) { MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_starting_in(*start, *end); @@ -266,7 +266,7 @@ void MarkerIndexWrapper::find_starting_in(const Nan::FunctionCallbackInfo void MarkerIndexWrapper::find_starting_at(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional position = PointWrapper::PointFromJS(info[0]); + optional position = PointWrapper::point_from_js(info[0]); if (position) { MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_starting_at(*position); @@ -277,8 +277,8 @@ void MarkerIndexWrapper::find_starting_at(const Nan::FunctionCallbackInfo void MarkerIndexWrapper::find_ending_in(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional start = PointWrapper::PointFromJS(info[0]); - optional end = PointWrapper::PointFromJS(info[1]); + optional start = PointWrapper::point_from_js(info[0]); + optional end = PointWrapper::point_from_js(info[1]); if (start && end) { MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_ending_in(*start, *end); @@ -289,7 +289,7 @@ void MarkerIndexWrapper::find_ending_in(const Nan::FunctionCallbackInfo & void MarkerIndexWrapper::find_ending_at(const Nan::FunctionCallbackInfo &info) { MarkerIndexWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); - optional position = PointWrapper::PointFromJS(info[0]); + optional position = PointWrapper::point_from_js(info[0]); if (position) { MarkerIndex::MarkerIdSet result = wrapper->marker_index.find_ending_at(*position); diff --git a/src/bindings/patch-wrapper.cc b/src/bindings/patch-wrapper.cc index 45a88ff6..3a168004 100644 --- a/src/bindings/patch-wrapper.cc +++ b/src/bindings/patch-wrapper.cc @@ -82,32 +82,32 @@ class HunkWrapper : public Nan::ObjectWrap { static void get_old_start(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; - info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.old_start)); + info.GetReturnValue().Set(PointWrapper::from_point(hunk.old_start)); } static void get_new_start(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; - info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.new_start)); + info.GetReturnValue().Set(PointWrapper::from_point(hunk.new_start)); } static void get_old_end(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; - info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.old_end)); + info.GetReturnValue().Set(PointWrapper::from_point(hunk.old_end)); } static void get_new_end(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; - info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.new_end)); + info.GetReturnValue().Set(PointWrapper::from_point(hunk.new_end)); } static void get_old_extent(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; - info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.old_end.traversal(hunk.old_start))); + info.GetReturnValue().Set(PointWrapper::from_point(hunk.old_end.traversal(hunk.old_start))); } static void get_new_extent(v8::Local property, const Nan::PropertyCallbackInfo &info) { Patch::Hunk &hunk = Nan::ObjectWrap::Unwrap(info.This())->hunk; - info.GetReturnValue().Set(PointWrapper::FromPoint(hunk.new_end.traversal(hunk.new_start))); + info.GetReturnValue().Set(PointWrapper::from_point(hunk.new_end.traversal(hunk.new_start))); } static void to_string(const Nan::FunctionCallbackInfo &info) { @@ -172,9 +172,9 @@ void PatchWrapper::construct(const Nan::FunctionCallbackInfo &info) { void PatchWrapper::splice(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - optional start = PointWrapper::PointFromJS(info[0]); - optional deletion_extent = PointWrapper::PointFromJS(info[1]); - optional insertion_extent = PointWrapper::PointFromJS(info[2]); + optional start = PointWrapper::point_from_js(info[0]); + optional deletion_extent = PointWrapper::point_from_js(info[1]); + optional insertion_extent = PointWrapper::point_from_js(info[2]); if (start && deletion_extent && insertion_extent) { unique_ptr deleted_text; @@ -200,9 +200,9 @@ void PatchWrapper::splice(const Nan::FunctionCallbackInfo &info) { void PatchWrapper::splice_old(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - optional start = PointWrapper::PointFromJS(info[0]); - optional deletion_extent = PointWrapper::PointFromJS(info[1]); - optional insertion_extent = PointWrapper::PointFromJS(info[2]); + optional start = PointWrapper::point_from_js(info[0]); + optional deletion_extent = PointWrapper::point_from_js(info[1]); + optional insertion_extent = PointWrapper::point_from_js(info[2]); if (start && deletion_extent && insertion_extent) { if (!patch.splice_old(*start, *deletion_extent, *insertion_extent)) { @@ -247,8 +247,8 @@ void PatchWrapper::get_hunks(const Nan::FunctionCallbackInfo &info) { void PatchWrapper::get_hunks_in_old_range(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - optional start = PointWrapper::PointFromJS(info[0]); - optional end = PointWrapper::PointFromJS(info[1]); + optional start = PointWrapper::point_from_js(info[0]); + optional end = PointWrapper::point_from_js(info[1]); if (start && end) { Local js_result = Nan::New(); @@ -265,8 +265,8 @@ void PatchWrapper::get_hunks_in_old_range(const Nan::FunctionCallbackInfo void PatchWrapper::get_hunks_in_new_range(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - optional start = PointWrapper::PointFromJS(info[0]); - optional end = PointWrapper::PointFromJS(info[1]); + optional start = PointWrapper::point_from_js(info[0]); + optional end = PointWrapper::point_from_js(info[1]); if (start && end) { Local js_result = Nan::New(); @@ -282,7 +282,7 @@ void PatchWrapper::get_hunks_in_new_range(const Nan::FunctionCallbackInfo void PatchWrapper::hunk_for_old_position(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - optional start = PointWrapper::PointFromJS(info[0]); + optional start = PointWrapper::point_from_js(info[0]); if (start) { auto hunk = patch.hunk_for_old_position(*start); if (hunk) { @@ -295,7 +295,7 @@ void PatchWrapper::hunk_for_old_position(const Nan::FunctionCallbackInfo void PatchWrapper::hunk_for_new_position(const Nan::FunctionCallbackInfo &info) { Patch &patch = Nan::ObjectWrap::Unwrap(info.This())->patch; - optional start = PointWrapper::PointFromJS(info[0]); + optional start = PointWrapper::point_from_js(info[0]); if (start) { auto hunk = patch.hunk_for_new_position(*start); if (hunk) { diff --git a/src/bindings/point-wrapper.cc b/src/bindings/point-wrapper.cc index 34cb371b..bbd96121 100644 --- a/src/bindings/point-wrapper.cc +++ b/src/bindings/point-wrapper.cc @@ -8,7 +8,7 @@ static Nan::Persistent row_string; static Nan::Persistent column_string; static Nan::Persistent constructor; -optional PointWrapper::PointFromJS(Local value) { +optional PointWrapper::point_from_js(Local value) { Nan::MaybeLocal maybe_object = Nan::To(value); Local object; if (!maybe_object.ToLocal(&object)) { @@ -38,19 +38,19 @@ optional PointWrapper::PointFromJS(Local value) { ); } -void PointWrapper::Init() { +void PointWrapper::init() { row_string.Reset(Nan::Persistent(Nan::New("row").ToLocalChecked())); column_string.Reset(Nan::Persistent(Nan::New("column").ToLocalChecked())); - Local constructor_template = Nan::New(New); + Local constructor_template = Nan::New(construct); constructor_template->SetClassName(Nan::New("Point").ToLocalChecked()); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); - Nan::SetAccessor(constructor_template->InstanceTemplate(), Nan::New(row_string), GetRow); - Nan::SetAccessor(constructor_template->InstanceTemplate(), Nan::New(column_string), GetColumn); + Nan::SetAccessor(constructor_template->InstanceTemplate(), Nan::New(row_string), get_row); + Nan::SetAccessor(constructor_template->InstanceTemplate(), Nan::New(column_string), get_column); constructor.Reset(constructor_template->GetFunction()); } -Local PointWrapper::FromPoint(Point point) { +Local PointWrapper::from_point(Point point) { Local result; if (Nan::New(constructor)->NewInstance(Nan::GetCurrentContext()).ToLocal(&result)) { (new PointWrapper(point))->Wrap(result); @@ -62,15 +62,15 @@ Local PointWrapper::FromPoint(Point point) { PointWrapper::PointWrapper(Point point) : point(point) {} -void PointWrapper::New(const Nan::FunctionCallbackInfo &info) {} +void PointWrapper::construct(const Nan::FunctionCallbackInfo &info) {} -void PointWrapper::GetRow(v8::Local property, const Nan::PropertyCallbackInfo &info) { +void PointWrapper::get_row(v8::Local property, const Nan::PropertyCallbackInfo &info) { PointWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); Point &point = wrapper->point; info.GetReturnValue().Set(Nan::New(point.row)); } -void PointWrapper::GetColumn(v8::Local property, const Nan::PropertyCallbackInfo &info) { +void PointWrapper::get_column(v8::Local property, const Nan::PropertyCallbackInfo &info) { PointWrapper *wrapper = Nan::ObjectWrap::Unwrap(info.This()); Point &point = wrapper->point; info.GetReturnValue().Set(Nan::New(point.column)); diff --git a/src/bindings/point-wrapper.h b/src/bindings/point-wrapper.h index 112f4e18..fc06b263 100644 --- a/src/bindings/point-wrapper.h +++ b/src/bindings/point-wrapper.h @@ -7,19 +7,19 @@ class PointWrapper : public Nan::ObjectWrap { public: - static void Init(); - static v8::Local FromPoint(Point point); - static optional PointFromJS(v8::Local); + static void init(); + static v8::Local from_point(Point point); + static optional point_from_js(v8::Local); private: PointWrapper(Point point); - static void New(const Nan::FunctionCallbackInfo &info); + static void construct(const Nan::FunctionCallbackInfo &info); - static void GetRow(v8::Local property, + static void get_row(v8::Local property, const Nan::PropertyCallbackInfo &info); - static void GetColumn(v8::Local property, + static void get_column(v8::Local property, const Nan::PropertyCallbackInfo &info); Point point; From 1912645f273365d2a759fc9e87b193a5a8c3c93d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 15 Jan 2017 10:42:47 -0700 Subject: [PATCH 7/8] Convert tests and benchmarks to new naming convention --- benchmark/native/marker-index-benchmark.cc | 8 ++-- test/native/patch-test.cc | 54 +++++++++++----------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/benchmark/native/marker-index-benchmark.cc b/benchmark/native/marker-index-benchmark.cc index 60fbdc16..39f3a003 100644 --- a/benchmark/native/marker-index-benchmark.cc +++ b/benchmark/native/marker-index-benchmark.cc @@ -10,7 +10,7 @@ using namespace std::chrono; using std::vector; -Range GetRandomRange() { +Range get_random_range() { Point start(rand() % 100, rand() % 100); Point end = start; if (rand() % 10 < 5) { @@ -20,19 +20,19 @@ Range GetRandomRange() { } -TEST_CASE("MarkerIndex::Insert") { +TEST_CASE("MarkerIndex::insert") { srand(0); MarkerIndex marker_index; vector ranges; uint count = 20000; for (uint i = 0; i < count; i++) { - ranges.push_back(GetRandomRange()); + ranges.push_back(get_random_range()); } milliseconds start = duration_cast(system_clock::now().time_since_epoch()); for (uint i = 0; i < count; i++) { - marker_index.Insert(i, ranges[i].start, ranges[i].end); + marker_index.insert(i, ranges[i].start, ranges[i].end); } milliseconds end = duration_cast(system_clock::now().time_since_epoch()); std::cout << "Inserting " << (end - start).count(); diff --git a/test/native/patch-test.cc b/test/native/patch-test.cc index fcb52e44..ec5c846f 100644 --- a/test/native/patch-test.cc +++ b/test/native/patch-test.cc @@ -5,9 +5,9 @@ typedef Patch::Hunk Hunk; TEST_CASE("Records simple non-overlapping splices") { Patch patch; - patch.Splice(Point{0, 5}, Point{0, 3}, Point{0, 4}, nullptr, nullptr); - patch.Splice(Point{0, 10}, Point{0, 3}, Point{0, 4}, nullptr, nullptr); - REQUIRE(patch.GetHunks() == vector({ + patch.splice(Point{0, 5}, Point{0, 3}, Point{0, 4}, nullptr, nullptr); + patch.splice(Point{0, 10}, Point{0, 3}, Point{0, 4}, nullptr, nullptr); + REQUIRE(patch.get_hunks() == vector({ Hunk{ Point{0, 5}, Point{0, 8}, Point{0, 5}, Point{0, 9}, @@ -20,8 +20,8 @@ TEST_CASE("Records simple non-overlapping splices") { } })); - patch.Splice(Point{0, 2}, Point{0, 2}, Point{0, 1}, nullptr, nullptr); - REQUIRE(patch.GetHunks() == vector({ + patch.splice(Point{0, 2}, Point{0, 2}, Point{0, 1}, nullptr, nullptr); + REQUIRE(patch.get_hunks() == vector({ Hunk{ Point{0, 2}, Point{0, 4}, Point{0, 2}, Point{0, 3}, @@ -39,8 +39,8 @@ TEST_CASE("Records simple non-overlapping splices") { } })); - patch.Splice(Point{0, 0}, Point{0, 0}, Point{0, 10}, nullptr, nullptr); - REQUIRE(patch.GetHunks() == vector({ + patch.splice(Point{0, 0}, Point{0, 0}, Point{0, 10}, nullptr, nullptr); + REQUIRE(patch.get_hunks() == vector({ Hunk{ Point{0, 0}, Point{0, 0}, Point{0, 0}, Point{0, 10}, @@ -67,14 +67,14 @@ TEST_CASE("Records simple non-overlapping splices") { TEST_CASE("Records overlapping splices with text") { Patch patch; - patch.Splice( + patch.splice( Point{0, 5}, Point{0, 3}, Point{0, 4}, GetText("abc"), GetText("1234") ); - REQUIRE(patch.GetHunks() == vector({ + REQUIRE(patch.get_hunks() == vector({ Hunk{ Point{0, 5}, Point{0, 8}, Point{0, 5}, Point{0, 9}, @@ -84,14 +84,14 @@ TEST_CASE("Records overlapping splices with text") { })); // overlaps lower bound, has no upper bound. - patch.Splice( + patch.splice( Point{0, 7}, Point{0, 3}, Point{0, 4}, GetText("34d"), GetText("5678") ); - REQUIRE(patch.GetHunks() == vector({ + REQUIRE(patch.get_hunks() == vector({ Hunk{ Point{0, 5}, Point{0, 9}, Point{0, 5}, Point{0, 11}, @@ -101,15 +101,15 @@ TEST_CASE("Records overlapping splices with text") { })); // overlaps upper bound, has no lower bound. - patch.Splice( + patch.splice( Point{0, 3}, Point{0, 3}, Point{0, 4}, GetText("efa"), GetText("1234") ); - REQUIRE(patch.GetHunks() == vector({ - Hunk{ + REQUIRE(patch.get_hunks() == vector({ + { Point{0, 3}, Point{0, 9}, Point{0, 3}, Point{0, 12}, GetText("efabcd").get(), @@ -118,14 +118,14 @@ TEST_CASE("Records overlapping splices with text") { })); // doesn't overlap lower bound, has no upper bound - patch.Splice( + patch.splice( Point{0, 15}, Point{0, 3}, Point{0, 4}, GetText("ghi"), GetText("5678") ); - REQUIRE(patch.GetHunks() == vector({ + REQUIRE(patch.get_hunks() == vector({ Hunk{ Point{0, 3}, Point{0, 9}, Point{0, 3}, Point{0, 12}, @@ -141,14 +141,14 @@ TEST_CASE("Records overlapping splices with text") { })); // surrounds two hunks, has no lower or upper bound - patch.Splice( + patch.splice( Point{0, 1}, Point{0, 21}, Point{0, 5}, GetText("xx123425678yyy5678zzz"), GetText("99999") ); - REQUIRE(patch.GetHunks() == vector({ + REQUIRE(patch.get_hunks() == vector({ Hunk{ Point{0, 1}, Point{0, 18}, Point{0, 1}, Point{0, 6}, @@ -161,12 +161,12 @@ TEST_CASE("Records overlapping splices with text") { TEST_CASE("Serializes and deserializes") { Patch patch; - patch.Splice(Point{0, 5}, Point{0, 3}, Point{0, 4}, nullptr, nullptr); - patch.Splice(Point{0, 10}, Point{0, 3}, Point{0, 4}, nullptr, nullptr); - patch.Splice(Point{0, 2}, Point{0, 2}, Point{0, 1}, nullptr, nullptr); - patch.Splice(Point{0, 0}, Point{0, 0}, Point{0, 10}, nullptr, nullptr); - patch.HunkForOldPosition(Point{0, 5}); // splay the middle - REQUIRE(patch.GetHunks() == vector({ + patch.splice(Point{0, 5}, Point{0, 3}, Point{0, 4}, nullptr, nullptr); + patch.splice(Point{0, 10}, Point{0, 3}, Point{0, 4}, nullptr, nullptr); + patch.splice(Point{0, 2}, Point{0, 2}, Point{0, 1}, nullptr, nullptr); + patch.splice(Point{0, 0}, Point{0, 0}, Point{0, 10}, nullptr, nullptr); + patch.hunk_for_old_position(Point{0, 5}); // splay the middle + REQUIRE(patch.get_hunks() == vector({ Hunk{ Point{0, 0}, Point{0, 0}, Point{0, 0}, Point{0, 10}, @@ -190,9 +190,9 @@ TEST_CASE("Serializes and deserializes") { })); vector serialization_vector; - patch.Serialize(&serialization_vector); + patch.serialize(&serialization_vector); Patch patch_copy(serialization_vector); - REQUIRE(patch_copy.GetHunks() == vector({ + REQUIRE(patch_copy.get_hunks() == vector({ Hunk{ Point{0, 0}, Point{0, 0}, Point{0, 0}, Point{0, 10}, @@ -215,5 +215,5 @@ TEST_CASE("Serializes and deserializes") { } })); - REQUIRE(patch_copy.Splice(Point{0, 1}, Point{0, 1}, Point{0, 2}, nullptr, nullptr) == false); + REQUIRE(patch_copy.splice(Point{0, 1}, Point{0, 1}, Point{0, 2}, nullptr, nullptr) == false); } From cd048128ade33bd4fa0c79306c2c164236e1cff1 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 15 Jan 2017 10:42:52 -0700 Subject: [PATCH 8/8] Remove dead code --- src/point.h | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 src/point.h diff --git a/src/point.h b/src/point.h deleted file mode 100644 index 8a246a48..00000000 --- a/src/point.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef POINT_H_ -#define POINT_H_ - -struct Point { - unsigned row; - unsigned column; -}; - -#endif // POINT_H_