Commit 884f61b4 authored by Joseph Mirabel's avatar Joseph Mirabel
Browse files

[Serialization] Add hitcount in compression.

parent 71b80e6b
......@@ -121,6 +121,9 @@ struct archive {
typedef Compare compare_type;
typedef ptr_less<Key, Compare> ptr_compare_type;
std::set<Key const*, ptr_compare_type > datas;
int hitcount;
archive() : hitcount(0) {}
};
typedef archive<::hpp::pinocchio::vector_t, eigen_compare<::hpp::pinocchio::vector_t> > vector_archive;
......@@ -151,6 +154,7 @@ inline void save_impl (Archive& ar,
template<class Archive, typename Key, typename Compare = std::less<Key>>
inline void save_impl (Archive& ar,
std::set<Key const*, ptr_less<Key,Compare> >& set,
int& hitcount,
const char* name,
const Key& key,
const unsigned int version)
......@@ -162,17 +166,19 @@ inline void save_impl (Archive& ar,
bool inserted = result.second;
Key const* k = (inserted ? &key : *result.first);
ar & boost::serialization::make_nvp(name, k);
if (!inserted) hitcount++;
}
template<class Archive, typename Key, typename Compare = std::less<Key>>
inline void serialize (Archive& ar,
std::set<Key const*, ptr_less<Key,Compare> >& set,
int& hitcount,
const char* name,
Key& key,
const unsigned int version)
{
if (Archive::is_saving::value) {
save_impl(ar, set, name, key, version);
save_impl(ar, set, hitcount, name, key, version);
} else {
load_or_save_no_remove_duplicate_check(ar, name, key, version);
}
......@@ -186,7 +192,8 @@ static inline void run (Archive& ar,
Key& key,
const unsigned int version)
{
serialize(ar, dynamic_cast<archive<Key, Compare>&>(ar).datas, name, key, version);
archive<Key, Compare>& rda = dynamic_cast<archive<Key, Compare>&>(ar);
serialize(ar, rda.datas, rda.hitcount, name, key, version);
}
template<typename Archive, typename Key, typename Compare = std::less<Key> >
static inline void save (Archive& ar,
......@@ -194,7 +201,8 @@ static inline void save (Archive& ar,
const Key& key,
const unsigned int version)
{
save_impl(ar, dynamic_cast<archive<Key, Compare>&>(ar).datas, name, key, version);
archive<Key, Compare>& rda = dynamic_cast<archive<Key, Compare>&>(ar);
save_impl(ar, rda.datas, rda.hitcount, name, key, version);
}
};
......
......@@ -476,9 +476,10 @@ namespace hpp {
{
(void) version;
ar & BOOST_SERIALIZATION_NVP(liegroupTypes_);
ar & BOOST_SERIALIZATION_NVP(nq_);
ar & BOOST_SERIALIZATION_NVP(nv_);
serialization::remove_duplicate::serialize_vector(ar, "neutral_", neutral_, version);
if (!Archive::is_saving::value) {
computeSize();
computeNeutral();
}
ar & BOOST_SERIALIZATION_NVP(weak_);
}
......
......@@ -85,4 +85,15 @@ BOOST_AUTO_TEST_CASE(check_remove_duplicate)
{
check_remove_duplicate_impl<boost::archive::xml_oarchive>();
check_remove_duplicate_impl<oarchive<boost::archive::xml_oarchive> >();
vector_t q (5);
for (int i = 0; i < 10; ++i) {
q.setRandom();
vector_t qq;
qq = q;
hpp::serialization::remove_duplicate::eigen_compare<vector_t> cmp;
BOOST_CHECK(!cmp(q, qq));
BOOST_CHECK(!cmp(qq, q));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment