Concordia
utils.hpp
1 #ifndef UTILS_HDR
2 #define UTILS_HDR
3 
4 #include <boost/shared_ptr.hpp>
5 #include <boost/foreach.hpp>
6 #include <fstream>
7 #include <iostream>
8 #include <vector>
9 
10 #include "concordia/common/config.hpp"
11 #include "concordia/concordia_exception.hpp"
12 #include "concordia/interval.hpp"
13 #include "concordia/matched_pattern_fragment.hpp"
14 #include <divsufsort.h>
15 
21 class Utils {
22 public:
25  explicit Utils();
26 
29  virtual ~Utils();
30 
37  static void writeIndexCharacter(std::ofstream & file,
38  INDEX_CHARACTER_TYPE character);
39 
46  static void writeMarker(std::ofstream & file,
47  SUFFIX_MARKER_TYPE marker);
48 
55  static INDEX_CHARACTER_TYPE readIndexCharacter(std::ifstream & file);
56 
63  static SUFFIX_MARKER_TYPE readMarker(std::ifstream & file);
64 
69  static sauchar_t * indexVectorToSaucharArray(
70  const std::vector<INDEX_CHARACTER_TYPE> & input);
71 
76  static std::vector<sauchar_t> indexVectorToSaucharVector(
77  const std::vector<INDEX_CHARACTER_TYPE> & input);
78 
83  static void appendCharToSaucharVector(
84  boost::shared_ptr<std::vector<sauchar_t> > vector,
85  INDEX_CHARACTER_TYPE character);
86 
91  static void appendCharToSaucharVector(
92  std::vector<sauchar_t> & vector,
93  INDEX_CHARACTER_TYPE character);
94 
98  template <typename T>
99  static void printVector(const std::vector<T> & vector);
100 
105  static SUFFIX_MARKER_TYPE getIdFromMarker(SUFFIX_MARKER_TYPE marker);
106 
111  static SUFFIX_MARKER_TYPE getOffsetFromMarker(SUFFIX_MARKER_TYPE marker);
112 
117  static SUFFIX_MARKER_TYPE getLengthFromMarker(SUFFIX_MARKER_TYPE marker);
118 
125  static SUFFIX_MARKER_TYPE createMarker(SUFFIX_MARKER_TYPE id,
126  SUFFIX_MARKER_TYPE offset,
127  SUFFIX_MARKER_TYPE length);
128 
135  static double getLogarithmicOverlay(
136  const std::vector<Interval> & intervalList,
137  SUFFIX_MARKER_TYPE sentenceSize,
138  double k);
139 
146  static double getLogarithmicOverlay(
147  const std::vector<MatchedPatternFragment> & fragmentList,
148  SUFFIX_MARKER_TYPE patternSize,
149  double k);
150 
153  static SUFFIX_MARKER_TYPE maxSentenceSize;
154 
155 private:
156  static void _insertCharToSaucharArray(sauchar_t * array,
157  INDEX_CHARACTER_TYPE character, int pos);
158 
159  static int _idBytes;
160 };
161 
162 template <typename T>
163 void Utils::printVector(const std::vector<T> & vector) {
164  for (int i = 0; i < vector.size(); i++) {
165  std::cout << static_cast<int>(vector.at(i)) << " ";
166  }
167  std::cout << std::endl;
168 }
169 #endif
static SUFFIX_MARKER_TYPE getLengthFromMarker(SUFFIX_MARKER_TYPE marker)
Definition: utils.cpp:96
static sauchar_t * indexVectorToSaucharArray(const std::vector< INDEX_CHARACTER_TYPE > &input)
Definition: utils.cpp:32
static SUFFIX_MARKER_TYPE readMarker(std::ifstream &file)
Definition: utils.cpp:26
virtual ~Utils()
Definition: utils.cpp:7
static void printVector(const std::vector< T > &vector)
Definition: utils.hpp:163
Utils()
Definition: utils.cpp:4
static SUFFIX_MARKER_TYPE getIdFromMarker(SUFFIX_MARKER_TYPE marker)
Definition: utils.cpp:83
static INDEX_CHARACTER_TYPE readIndexCharacter(std::ifstream &file)
Definition: utils.cpp:20
static SUFFIX_MARKER_TYPE getOffsetFromMarker(SUFFIX_MARKER_TYPE marker)
Definition: utils.cpp:88
static SUFFIX_MARKER_TYPE maxSentenceSize
Definition: utils.hpp:153
static double getLogarithmicOverlay(const std::vector< Interval > &intervalList, SUFFIX_MARKER_TYPE sentenceSize, double k)
Definition: utils.cpp:117
static SUFFIX_MARKER_TYPE createMarker(SUFFIX_MARKER_TYPE id, SUFFIX_MARKER_TYPE offset, SUFFIX_MARKER_TYPE length)
Definition: utils.cpp:104
static void writeMarker(std::ofstream &file, SUFFIX_MARKER_TYPE marker)
Definition: utils.cpp:15
static void appendCharToSaucharVector(boost::shared_ptr< std::vector< sauchar_t > > vector, INDEX_CHARACTER_TYPE character)
Definition: utils.cpp:66
static std::vector< sauchar_t > indexVectorToSaucharVector(const std::vector< INDEX_CHARACTER_TYPE > &input)
Definition: utils.cpp:46
static void writeIndexCharacter(std::ofstream &file, INDEX_CHARACTER_TYPE character)
Definition: utils.cpp:10
Definition: utils.hpp:21