diff --git a/.cproject b/.cproject
index fed8aa1f5..46d6f3844 100644
--- a/.cproject
+++ b/.cproject
@@ -1787,6 +1787,14 @@
true
true
+
+ make
+ -j5
+ testDSFVector.run
+ true
+ true
+ true
+
make
-j5
diff --git a/gtsam/base/DSFVector.cpp b/gtsam/base/DSFVector.cpp
index 2bf18916d..929835cfa 100644
--- a/gtsam/base/DSFVector.cpp
+++ b/gtsam/base/DSFVector.cpp
@@ -16,38 +16,50 @@
* @brief a faster implementation for DSF, which uses vector rather than btree.
*/
+#include
#include
#include
-#include
+#include
using namespace std;
namespace gtsam {
/* ************************************************************************* */
-DSFVector::DSFVector (const size_t numNodes) {
- v_ = boost::make_shared(numNodes);
+DSFVector::DSFVector(const size_t numNodes) {
+ v_ = boost::make_shared < V > (numNodes);
int index = 0;
keys_.reserve(numNodes);
- for(V::iterator it = v_->begin(); it!=v_->end(); it++, index++) {
+ for (V::iterator it = v_->begin(); it != v_->end(); it++, index++) {
*it = index;
keys_.push_back(index);
}
}
/* ************************************************************************* */
-DSFVector::DSFVector(const boost::shared_ptr& v_in, const std::vector& keys) : keys_(keys) {
+DSFVector::DSFVector(const std::vector& keys) :
+ keys_(keys) {
+ size_t maxKey = *(std::max_element(keys.begin(), keys.end()));
+ v_ = boost::make_shared < V > (maxKey + 1);
+ BOOST_FOREACH(const size_t key, keys)
+ (*v_)[key] = key;
+}
+
+/* ************************************************************************* */
+DSFVector::DSFVector(const boost::shared_ptr& v_in,
+ const std::vector& keys) :
+ keys_(keys) {
+ assert(*(std::max_element(keys.begin(), keys.end()))size());
v_ = v_in;
BOOST_FOREACH(const size_t key, keys)
(*v_)[key] = key;
}
/* ************************************************************************* */
-bool DSFVector::isSingleton(const Label& label) const {
+bool DSFVector::isSingleton(const size_t& label) const {
bool result = false;
- V::const_iterator it = keys_.begin();
- for (; it != keys_.end(); ++it) {
- if(findSet(*it) == label) {
+ BOOST_FOREACH(size_t key,keys_) {
+ if (findSet(key) == label) {
if (!result) // find the first occurrence
result = true;
else
@@ -58,38 +70,32 @@ bool DSFVector::isSingleton(const Label& label) const {
}
/* ************************************************************************* */
-std::set DSFVector::set(const Label& label) const {
- std::set set;
- V::const_iterator it = keys_.begin();
- for (; it != keys_.end(); it++) {
- if (findSet(*it) == label)
- set.insert(*it);
- }
+std::set DSFVector::set(const size_t& label) const {
+ std::set < size_t > set;
+ BOOST_FOREACH(size_t key,keys_)
+ if (findSet(key) == label)
+ set.insert(key);
return set;
}
/* ************************************************************************* */
-std::map > DSFVector::sets() const {
- std::map