From 25b9a123b60f769506a829542d05f38b1e95d51b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Jul 2007 09:32:49 +0000 Subject: Add const find interface to Raul::Table, fix bugs. Use Raul::Table on Ingen client side instead of std::map for objects, plugins. Work on renaming (still broken). git-svn-id: http://svn.drobilla.net/lad/raul@634 a436a847-0d15-0410-975c-d299462d15a1 --- raul/TableImpl.hpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'raul/TableImpl.hpp') diff --git a/raul/TableImpl.hpp b/raul/TableImpl.hpp index 8fcba0b..5b4946e 100644 --- a/raul/TableImpl.hpp +++ b/raul/TableImpl.hpp @@ -15,6 +15,9 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef RAUL_TABLE_IMPL_HPP +#define RAUL_TABLE_IMPL_HPP + #include #include #include @@ -44,6 +47,15 @@ Table::is_sorted() const #endif +/** Binary search (O(log(n))) */ +template +typename Table::const_iterator +Table::find(const K& key) const +{ + return ((Table*)this)->find(key); +} + + /** Binary search (O(log(n))) */ template typename Table::iterator @@ -90,11 +102,11 @@ Table::insert(const std::pair& entry) if (size() == 0 || size() == 1 && key > _entries[0].first) { _entries.push_back(entry); - return make_pair(iterator(*this, size()-1), true); + return std::make_pair(iterator(*this, size()-1), true); } else if (size() == 1) { _entries.push_back(_entries[0]); _entries[0] = entry; - return make_pair(begin(), true); + return std::make_pair(begin(), true); } size_t lower = 0; @@ -114,7 +126,7 @@ Table::insert(const std::pair& entry) if (elem.first == key) { elem.second = value; - return make_pair(iterator(*this, i), false); + return std::make_pair(iterator(*this, i), false); } else if (elem.first > key) { if (i == 0 || _entries[i-1].first < key) break; @@ -128,17 +140,17 @@ Table::insert(const std::pair& entry) if (i < size() && _entries[i].first <= key) ++i; - _entries.resize(size() + 1); + _entries.push_back(_entries.back()); // Shift everything beyond i right - for (size_t j = size()-1; j > i; --j) + for (size_t j = size()-2; j > i; --j) _entries[j] = _entries[j-1]; _entries[i] = entry; assert(is_sorted()); - return make_pair(iterator(*this, i), true); + return std::make_pair(iterator(*this, i), true); } @@ -230,3 +242,5 @@ Table::erase(size_t first_index, size_t last_index) } // namespace Raul +#endif // RAUL_TABLE_IMLP_HPP + -- cgit v1.2.1