summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-05-14 17:00:45 +0200
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-05-14 17:00:45 +0200
commit7c344de97edac0aa2a6a90c2de9bcf60f15ac000 (patch)
treef61bf6ca09d1d0ec6398dd0e8ec7c8e85a5598e7 /utils
parentd94373453c69c6cfec952a0f7b427cacc78654d8 (diff)
parent824c96f038b0447ce83ae92cad112a5be49e3330 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'utils')
-rw-r--r--utils/fast_sparse_vector.h16
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);