From 02099a01350a41a99ec400e9b29df08a01d88979 Mon Sep 17 00:00:00 2001 From: Paul Baltescu Date: Tue, 4 Jun 2013 23:17:57 +0100 Subject: Serialize data structures. --- extractor/suffix_array.h | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'extractor/suffix_array.h') 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 #include +#include +#include +#include namespace fs = boost::filesystem; using namespace std; @@ -20,6 +23,9 @@ class SuffixArray { // Creates a suffix array from a data array. SuffixArray(shared_ptr 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 void save(Archive& ar, unsigned int) const { + ar << *data_array; + ar << suffix_array; + ar << word_start; + } + + template void load(Archive& ar, unsigned int) { + data_array = make_shared(); + ar >> *data_array; + ar >> suffix_array; + ar >> word_start; + } + + BOOST_SERIALIZATION_SPLIT_MEMBER(); + shared_ptr data_array; vector suffix_array; vector word_start; -- cgit v1.2.3