From 96b37241bd3981313e496c92511c9068f8c7d4e6 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Sat, 5 Dec 2015 16:52:18 -0800 Subject: [PATCH] feat(util/list): add is_suffix_eqp --- src/util/list.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/util/list.h b/src/util/list.h index c4adba7f0..003bd78a0 100644 --- a/src/util/list.h +++ b/src/util/list.h @@ -100,6 +100,17 @@ public: friend bool is_eqp(list const & l1, list const & l2) { return l1.m_ptr == l2.m_ptr; } friend bool is_eqp(list const & l1, cell const * l2) { return l1.m_ptr == l2; } + /** \brief Return true iff l_2 is of the form [a_1, ..., a_n, l_1] for n >= 0 */ + friend bool is_suffix_eqp(list const & l_1, list const & l_2) { + list const * it = &l_2; + while (!empty(*it)) { + if (is_eqp(*it, l_1)) + return true; + it = &tail(*it); + } + return is_eqp(*it, l_1); + } + template void emplace_front(Args&&... args) { cell * new_ptr = new (get_allocator().allocate()) cell(true, *this, args...);