diff options
author | Paul Baltescu <pauldb89@gmail.com> | 2013-06-04 23:17:57 +0100 |
---|---|---|
committer | Paul Baltescu <pauldb89@gmail.com> | 2013-06-04 23:17:57 +0100 |
commit | 02099a01350a41a99ec400e9b29df08a01d88979 (patch) | |
tree | b5af245aa6c7e00e3d4b088c9e7e3b893d080a26 /extractor/suffix_array.h | |
parent | 891502bdd646c21954684763f322b107568a072e (diff) |
Serialize data structures.
Diffstat (limited to 'extractor/suffix_array.h')
-rw-r--r-- | extractor/suffix_array.h | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/extractor/suffix_array.h b/extractor/suffix_array.h index bf731d79..8ee454ec 100644 --- a/extractor/suffix_array.h +++ b/extractor/suffix_array.h @@ -6,6 +6,9 @@ #include <vector> #include <boost/filesystem.hpp> +#include <boost/serialization/serialization.hpp> +#include <boost/serialization/split_member.hpp> +#include <boost/serialization/vector.hpp> namespace fs = boost::filesystem; using namespace std; @@ -20,6 +23,9 @@ class SuffixArray { // Creates a suffix array from a data array. SuffixArray(shared_ptr<DataArray> data_array); + // Creates empty suffix array. + SuffixArray(); + virtual ~SuffixArray(); // Returns the size of the suffix array. @@ -40,10 +46,7 @@ class SuffixArray { virtual PhraseLocation Lookup(int low, int high, const string& word, int offset) const; - void WriteBinary(const fs::path& filepath) const; - - protected: - SuffixArray(); + bool operator==(const SuffixArray& other) const; private: // Constructs the suffix array using the algorithm of Larsson and Sadakane @@ -65,6 +68,23 @@ class SuffixArray { // offset value is greater or equal to word_id. int LookupRangeStart(int low, int high, int word_id, int offset) const; + friend class boost::serialization::access; + + template<class Archive> void save(Archive& ar, unsigned int) const { + ar << *data_array; + ar << suffix_array; + ar << word_start; + } + + template<class Archive> void load(Archive& ar, unsigned int) { + data_array = make_shared<DataArray>(); + ar >> *data_array; + ar >> suffix_array; + ar >> word_start; + } + + BOOST_SERIALIZATION_SPLIT_MEMBER(); + shared_ptr<DataArray> data_array; vector<int> suffix_array; vector<int> word_start; |