concordia-library/concordia/interval.hpp

73 lines
1.8 KiB
C++

#ifndef INTERVAL_HDR
#define INTERVAL_HDR
#include "concordia/common/config.hpp"
#include <iostream>
/*!
Class representing interval of a sentence, i.e. a sequence of words or chars
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,
an interval [2,5] of words of the sentence "This is just for
testing purposes" is: "just for testing".
*/
class Interval {
public:
/*! 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();
/*! Checks if this interval intersects another.
\param interval another interval
\returns true if the two intervals intersect
*/
bool intersects(Interval & interval);
/*! Getter for interval length.
\returns end - start
*/
SUFFIX_MARKER_TYPE getLength();
/*! Getter for interval start.
\returns start
*/
SUFFIX_MARKER_TYPE getStart() const {
return _start;
}
/*! Getter for interval end.
\returns end
*/
SUFFIX_MARKER_TYPE getEnd() const {
return _end;
}
friend std::ostream & operator << (std::ostream & o,
const Interval & interval) {
return o << "[" << interval.getStart()
<< "," << interval.getEnd() << ")";
}
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