concordia-library/concordia/interval.hpp

79 lines
2.0 KiB
C++
Raw Normal View History

#ifndef INTERVAL_HDR
#define INTERVAL_HDR
#include "concordia/common/config.hpp"
2015-06-22 13:52:56 +02:00
#include <iostream>
/*!
2015-06-22 13:52:56 +02:00
Class representing interval of a sentence, i.e. a sequence of words or chars
2015-05-01 14:52:53 +02:00
coming from that sentence. An interval only has its start and end indexes,
where the start index is inclusive and end index is exclusive. For example,
2015-06-22 13:52:56 +02:00
an interval [2,5] of words of the sentence "This is just for
testing purposes" is: "just for testing".
*/
class Interval {
public:
2015-05-01 14:52:53 +02:00
/*! Constructor.
\param start start index of the interval (0-based)
\param end end index of the interval (0-based)
*/
explicit Interval(const SUFFIX_MARKER_TYPE start,
const SUFFIX_MARKER_TYPE end);
/*! Destructor.
*/
virtual ~Interval();
2015-05-01 14:52:53 +02:00
/*! Checks if this interval intersects another.
\param interval another interval
\returns true if the two intervals intersect
*/
bool intersects(Interval & interval);
2018-12-12 21:45:07 +01:00
/*! Checks if this interval contains another.
\param interval another interval
\returns true if this interval contains the other
*/
bool contains(Interval & interval);
2015-05-01 14:52:53 +02:00
/*! Getter for interval length.
\returns end - start
*/
SUFFIX_MARKER_TYPE getLength();
2015-05-01 14:52:53 +02:00
/*! Getter for interval start.
\returns start
*/
SUFFIX_MARKER_TYPE getStart() const {
return _start;
}
2015-05-01 14:52:53 +02:00
/*! Getter for interval end.
\returns end
*/
SUFFIX_MARKER_TYPE getEnd() const {
return _end;
}
2015-06-27 12:40:24 +02:00
friend std::ostream & operator << (std::ostream & o,
const Interval & interval) {
return o << "[" << interval.getStart()
<< "," << interval.getEnd() << ")";
2015-06-22 13:52:56 +02:00
}
2015-06-27 12:40:24 +02:00
protected:
SUFFIX_MARKER_TYPE _start;
SUFFIX_MARKER_TYPE _end;
};
struct intervalEndComparator {
inline bool operator() (const Interval & lhs, const Interval & rhs) {
return (lhs.getEnd() < rhs.getEnd());
}
};
#endif