summaryrefslogtreecommitdiffstats
path: root/raul/TableImpl.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-07-26 09:32:49 +0000
committerDavid Robillard <d@drobilla.net>2007-07-26 09:32:49 +0000
commit25b9a123b60f769506a829542d05f38b1e95d51b (patch)
tree2359d360eb14a7419d52e6e800fcafdd9329fc0d /raul/TableImpl.hpp
parent9867aa08b2566800f81c8b2cdeff7372b2bb8c5b (diff)
downloadraul-25b9a123b60f769506a829542d05f38b1e95d51b.tar.gz
raul-25b9a123b60f769506a829542d05f38b1e95d51b.tar.bz2
raul-25b9a123b60f769506a829542d05f38b1e95d51b.zip
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
Diffstat (limited to 'raul/TableImpl.hpp')
-rw-r--r--raul/TableImpl.hpp26
1 files changed, 20 insertions, 6 deletions
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 <cassert>
#include <stdexcept>
#include <algorithm>
@@ -46,6 +49,15 @@ Table<K,T>::is_sorted() const
/** Binary search (O(log(n))) */
template <typename K, typename T>
+typename Table<K,T>::const_iterator
+Table<K,T>::find(const K& key) const
+{
+ return ((Table<K,T>*)this)->find(key);
+}
+
+
+/** Binary search (O(log(n))) */
+template <typename K, typename T>
typename Table<K,T>::iterator
Table<K,T>::find(const K& key)
{
@@ -90,11 +102,11 @@ Table<K,T>::insert(const std::pair<K, T>& 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<K,T>::insert(const std::pair<K, T>& 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<K,T>::insert(const std::pair<K, T>& 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<K,T>::erase(size_t first_index, size_t last_index)
} // namespace Raul
+#endif // RAUL_TABLE_IMLP_HPP
+