2013-12-06 22:29:25 +01:00
|
|
|
#ifndef UTILS_HDR
|
|
|
|
#define UTILS_HDR
|
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2014-05-15 22:20:31 +02:00
|
|
|
#include <boost/foreach.hpp>
|
2013-12-06 22:29:25 +01:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "concordia/common/config.hpp"
|
|
|
|
#include "concordia/concordia_exception.hpp"
|
2014-04-29 14:46:04 +02:00
|
|
|
#include <divsufsort.h>
|
2013-12-06 22:29:25 +01:00
|
|
|
|
|
|
|
class Utils {
|
|
|
|
public:
|
|
|
|
explicit Utils();
|
|
|
|
|
|
|
|
/*! Destructor.
|
|
|
|
*/
|
|
|
|
virtual ~Utils();
|
|
|
|
|
2015-04-15 14:14:10 +02:00
|
|
|
static void writeIndexCharacter(std::ofstream & file,
|
2013-12-06 22:29:25 +01:00
|
|
|
INDEX_CHARACTER_TYPE character);
|
|
|
|
|
2015-04-15 14:14:10 +02:00
|
|
|
static void writeMarker(std::ofstream & file,
|
2014-02-20 10:49:17 +01:00
|
|
|
SUFFIX_MARKER_TYPE marker);
|
|
|
|
|
2015-04-15 14:14:10 +02:00
|
|
|
static INDEX_CHARACTER_TYPE readIndexCharacter(std::ifstream & file);
|
2013-12-06 22:29:25 +01:00
|
|
|
|
2015-04-15 14:14:10 +02:00
|
|
|
static SUFFIX_MARKER_TYPE readMarker(std::ifstream & file);
|
2014-02-20 10:49:17 +01:00
|
|
|
|
2013-12-06 22:29:25 +01:00
|
|
|
static sauchar_t * indexVectorToSaucharArray(
|
2015-04-15 14:14:10 +02:00
|
|
|
const std::vector<INDEX_CHARACTER_TYPE> & input);
|
2013-12-06 22:29:25 +01:00
|
|
|
|
2015-04-15 10:55:26 +02:00
|
|
|
static std::vector<sauchar_t> indexVectorToSaucharVector(
|
2015-04-15 14:14:10 +02:00
|
|
|
const std::vector<INDEX_CHARACTER_TYPE> & input);
|
2014-06-24 18:23:46 +02:00
|
|
|
|
2013-12-14 15:23:17 +01:00
|
|
|
static void appendCharToSaucharVector(
|
|
|
|
boost::shared_ptr<std::vector<sauchar_t> > vector,
|
|
|
|
INDEX_CHARACTER_TYPE character);
|
2014-02-20 10:49:17 +01:00
|
|
|
|
2015-04-15 10:55:26 +02:00
|
|
|
static void appendCharToSaucharVector(
|
|
|
|
std::vector<sauchar_t> & vector,
|
|
|
|
INDEX_CHARACTER_TYPE character);
|
|
|
|
|
2014-05-15 22:20:31 +02:00
|
|
|
template <typename T>
|
2015-04-15 10:55:26 +02:00
|
|
|
static void printVector(const std::vector<T> & vector);
|
2014-05-15 22:20:31 +02:00
|
|
|
|
2015-04-09 22:17:19 +02:00
|
|
|
static SUFFIX_MARKER_TYPE getIdFromMarker(SUFFIX_MARKER_TYPE marker);
|
|
|
|
|
|
|
|
static SUFFIX_MARKER_TYPE getOffsetFromMarker(SUFFIX_MARKER_TYPE marker);
|
|
|
|
|
|
|
|
static SUFFIX_MARKER_TYPE getLengthFromMarker(SUFFIX_MARKER_TYPE marker);
|
|
|
|
|
|
|
|
static SUFFIX_MARKER_TYPE createMarker(SUFFIX_MARKER_TYPE id,
|
|
|
|
SUFFIX_MARKER_TYPE offset,
|
|
|
|
SUFFIX_MARKER_TYPE length);
|
|
|
|
|
|
|
|
static SUFFIX_MARKER_TYPE maxSentenceSize;
|
|
|
|
|
2013-12-06 22:29:25 +01:00
|
|
|
private:
|
2013-12-14 15:23:17 +01:00
|
|
|
static void _insertCharToSaucharArray(sauchar_t * array,
|
|
|
|
INDEX_CHARACTER_TYPE character, int pos);
|
2015-04-09 22:17:19 +02:00
|
|
|
|
|
|
|
static int _idBytes;
|
2013-12-06 22:29:25 +01:00
|
|
|
};
|
|
|
|
|
2014-05-15 22:20:31 +02:00
|
|
|
template <typename T>
|
2015-04-15 10:55:26 +02:00
|
|
|
void Utils::printVector(const std::vector<T> & vector) {
|
|
|
|
for (int i = 0; i < vector.size(); i++) {
|
2015-04-15 14:14:10 +02:00
|
|
|
std::cout << static_cast<int>(vector.at(i)) << " ";
|
2014-05-15 22:20:31 +02:00
|
|
|
}
|
2015-04-15 14:14:10 +02:00
|
|
|
std::cout << std::endl;
|
2014-05-15 22:20:31 +02:00
|
|
|
}
|
2013-12-06 22:29:25 +01:00
|
|
|
#endif
|