diff options
author | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-05-14 17:00:45 +0200 |
---|---|---|
committer | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-05-14 17:00:45 +0200 |
commit | fb42639b433d2fc0c68f300666be1192dc3b4f59 (patch) | |
tree | bbce7fffa8c28ade217cf331e357ba65e64235b3 /utils/fast_sparse_vector.h | |
parent | 670a8f984fc6d8342180c59ae9e96b0b76f34d3d (diff) | |
parent | 0f1e696690b18259acd79c3469d00a72aca00161 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'utils/fast_sparse_vector.h')
-rw-r--r-- | utils/fast_sparse_vector.h | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/utils/fast_sparse_vector.h b/utils/fast_sparse_vector.h index af832950..68caa704 100644 --- a/utils/fast_sparse_vector.h +++ b/utils/fast_sparse_vector.h @@ -7,8 +7,6 @@ // important: indexes are integers // important: iterators may return elements in any order -#include "config.h" - #include <cmath> #include <cstring> #include <climits> @@ -16,8 +14,9 @@ #include <cassert> #include <vector> -#include <boost/static_assert.hpp> +#include "config.h" +#include <boost/static_assert.hpp> #if HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP #include <boost/serialization/map.hpp> #endif @@ -119,6 +118,17 @@ class FastSparseVector { std::memcpy(this, &other, sizeof(FastSparseVector)); if (is_remote_) data_.rbmap = new std::map<int, T>(*data_.rbmap); } + FastSparseVector(std::pair<int, T>* first, std::pair<int, T>* last) { + const ptrdiff_t n = last - first; + if (n <= LOCAL_MAX) { + is_remote_ = false; + local_size_ = n; + std::memcpy(data_.local, first, sizeof(std::pair<int, T>) * n); + } else { + is_remote_ = true; + data_.rbmap = new std::map<int, T>(first, last); + } + } void erase(int k) { if (is_remote_) { data_.rbmap->erase(k); |