summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-01-02 22:26:08 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-01-02 22:26:08 +0100
commit325d580a4db4d19e64b3a7af047d09d0a2843f56 (patch)
tree3405fda808be8037750f7a48eb766efe45fb632d
parent39982975eb660d2d9760c54159cfb96f729302a0 (diff)
feat: rope impl improvements, bumping to release as well.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--include/ocl/tproc/detail/rope_fwd.hpp4
-rw-r--r--include/ocl/tproc/detail/rope_fwd.inl27
-rw-r--r--include/ocl/tproc/rope.hpp24
-rw-r--r--test/rope_test/crope.pred.test.cpp18
4 files changed, 62 insertions, 11 deletions
diff --git a/include/ocl/tproc/detail/rope_fwd.hpp b/include/ocl/tproc/detail/rope_fwd.hpp
index 0ce0457..7541795 100644
--- a/include/ocl/tproc/detail/rope_fwd.hpp
+++ b/include/ocl/tproc/detail/rope_fwd.hpp
@@ -28,7 +28,7 @@ namespace ocl::tproc
using reference = CharT&;
using const_reference = const CharT&;
using pointer = std::allocator_traits<Allocator>::pointer;
- using const_pointer = std::allocator_traits<Allocator>::pointer;
+ using const_pointer = const std::allocator_traits<Allocator>::pointer;
using iterator_type = basic_rope<CharT, Traits, Allocator>*;
iterator_type rbegin();
@@ -75,6 +75,8 @@ namespace ocl::tproc
bool operator!=(const boost::core::basic_string_view<CharT>&);
bool operator==(const boost::core::basic_string_view<CharT>&);
+ iterator_type concat(iterator_type right);
+
public:
static constexpr size_type npos = (size_type)(-1);
diff --git a/include/ocl/tproc/detail/rope_fwd.inl b/include/ocl/tproc/detail/rope_fwd.inl
index 81a7f5c..01e5bbe 100644
--- a/include/ocl/tproc/detail/rope_fwd.inl
+++ b/include/ocl/tproc/detail/rope_fwd.inl
@@ -60,11 +60,11 @@ namespace ocl::tproc
{
std::allocator_traits<Allocator>::deallocate(alloc_, blob_, capacity_);
}
-
+
delete left_;
delete right_;
- left_ = nullptr;
+ left_ = nullptr;
right_ = nullptr;
}
@@ -91,6 +91,7 @@ namespace ocl::tproc
{
throw std::out_of_range("rope index out of range");
}
+
return blob_[pos];
}
@@ -109,6 +110,7 @@ namespace ocl::tproc
}
}
+ public:
static rope_ptr concat(rope_ptr left, rope_ptr right, Allocator alloc = Allocator())
{
if (!left)
@@ -116,8 +118,14 @@ namespace ocl::tproc
if (!right)
return left;
- auto* new_rope = new basic_rope<CharT, Traits, Allocator>();
- new_rope->impl_ = new tree_impl(left, right, alloc);
+ auto res = std::basic_string<CharT>(left->data().data(), left->data().size());
+ res += std::basic_string<CharT>(right->data().data(), right->data().size());
+
+ auto* new_rope = new basic_rope<CharT, Traits, Allocator>(res);
+
+ new_rope->impl_->left_ = left;
+ new_rope->impl_->right_ = right;
+
return new_rope;
}
@@ -401,13 +409,14 @@ namespace ocl::tproc
return npos;
size_type rope_size = impl_->size();
+
if (needle.size() > rope_size)
return npos;
- // Brute force search
for (size_type i = 0; i <= rope_size - needle.size(); ++i)
{
bool match = true;
+
for (size_type j = 0; j < needle.size(); ++j)
{
if (impl_->at(i + j) != needle[j])
@@ -416,9 +425,11 @@ namespace ocl::tproc
break;
}
}
+
if (match)
return i;
}
+
return npos;
}
@@ -526,6 +537,12 @@ namespace ocl::tproc
return !(*this == str);
}
+ template <class CharT, class Traits, class Allocator>
+ basic_rope<CharT, Traits, Allocator>* basic_rope<CharT, Traits, Allocator>::concat(basic_rope<CharT, Traits, Allocator>* right)
+ {
+ return impl_->concat(this, right);
+ }
+
} // namespace ocl::tproc
#endif \ No newline at end of file
diff --git a/include/ocl/tproc/rope.hpp b/include/ocl/tproc/rope.hpp
index 26729b0..21277f2 100644
--- a/include/ocl/tproc/rope.hpp
+++ b/include/ocl/tproc/rope.hpp
@@ -35,6 +35,30 @@ namespace ocl::tproc::rope
}
};
+ /// \brief ends with pred type.
+ template <typename It>
+ class ends_with_pred final
+ {
+ It cond_;
+
+ public:
+ ends_with_pred(const boost::core::basic_string_view<typename It::value_type>& cond)
+ : cond_(cond)
+ {
+ }
+
+ It* operator()(It* begin, It* end)
+ {
+ for (auto beg{begin}; beg != end; ++beg)
+ {
+ if (beg->ends_with(cond_.data()))
+ return beg;
+ }
+
+ return end;
+ }
+ };
+
template <typename It>
class uppercase_pred final
{
diff --git a/test/rope_test/crope.pred.test.cpp b/test/rope_test/crope.pred.test.cpp
index 2d0ddae..b1cc59d 100644
--- a/test/rope_test/crope.pred.test.cpp
+++ b/test/rope_test/crope.pred.test.cpp
@@ -12,8 +12,8 @@
BOOST_AUTO_TEST_CASE(rope_should_succeed_in_find_pred)
{
- auto rope = ocl::tproc::crope("foo");
- auto it = ocl::tproc::rope::exact_pred<ocl::tproc::crope>{"foo"}(rope.cbegin(), rope.cend());
+ auto rope = ocl::tproc::crope("Exact Sentence");
+ auto it = ocl::tproc::rope::exact_pred<ocl::tproc::crope>{"Exact Sentence"}(rope.cbegin(), rope.cend());
BOOST_TEST(it != rope.cend());
@@ -22,12 +22,20 @@ BOOST_AUTO_TEST_CASE(rope_should_succeed_in_find_pred)
BOOST_AUTO_TEST_CASE(rope_should_succeed_in_starts_with)
{
- auto rope = ocl::tproc::crope("foobar");
-
+ auto rope = ocl::tproc::crope("The Quick Brown Fox Jumps Over The Lazy Dog");
// find the leaf with the starting value 'foo'
- auto it = ocl::tproc::rope::starts_with_pred<ocl::tproc::crope>{"foo"}(rope.cbegin(), rope.cend());
+ auto it = ocl::tproc::rope::starts_with_pred<ocl::tproc::crope>{"The Quick"}(rope.cbegin(), rope.cend());
BOOST_TEST(it != rope.cend());
+ auto it_end = ocl::tproc::rope::ends_with_pred<ocl::tproc::crope>{"Lazy Dog"}(rope.cbegin(), rope.cend());
+
+ BOOST_TEST(it_end != rope.cend());
+
+ ocl::io::println(it_end->data());
ocl::io::println(it->data());
+
+ auto new_elem = ocl::tproc::crope(", and Jumps again.");
+
+ ocl::io::println(rope.concat(&new_elem)->data());
}