LocARNA-2.0.0
infty_int.hh
1 #ifndef LOCARNA_INFTY_INT_HH
2 #define LOCARNA_INFTY_INT_HH
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <algorithm>
9 #include <iosfwd>
10 #include <assert.h>
11 
12 namespace LocARNA {
13 
14  class FiniteInt;
15  class InftyInt;
16 
57  public:
59  typedef long int base_type;
60 
61  protected:
63 
65  static const base_type min_finity;
66 
68  static const base_type max_finity;
69 
72 
75 
76  public:
80  TaintedInftyInt() : val(0) {}
81 
86  explicit
87  TaintedInftyInt(const base_type &x) : val(x) {}
88 
94  static base_type
96  return min_finity;
97  }
98 
104  static base_type
106  return max_finity;
107  }
108 
114  bool
115  is_neg_infty() const {
116  return val < min_finity;
117  }
118 
124  bool
125  is_pos_infty() const {
126  return val > max_finity;
127  }
128 
134  bool
135  is_finite() const {
136  return min_finity <= val && val <= max_finity;
137  }
138 
144  bool
145  is_normal() const {
147  }
148 
155  base_type
156  finite_value() const {
157  assert(is_finite());
158  return val;
159  }
160 
169  operator=(const FiniteInt &x);
170 
179  friend bool
180  operator==(const TaintedInftyInt &x, const TaintedInftyInt &y);
181 
190  friend TaintedInftyInt
191  operator+(const TaintedInftyInt &x, const FiniteInt &y);
192 
201  friend TaintedInftyInt
202  operator-(const TaintedInftyInt &x, const FiniteInt &y);
203 
212  friend TaintedInftyInt
213  operator+(const InftyInt &x, const InftyInt &y);
214 
223  friend TaintedInftyInt
224  operator-(const InftyInt &x, const InftyInt &y);
225 
234  friend TaintedInftyInt
235  min(const TaintedInftyInt &x, const TaintedInftyInt &y);
236 
245  friend TaintedInftyInt
246  max(const TaintedInftyInt &x, const TaintedInftyInt &y);
247 
259  friend bool
260  operator>(const TaintedInftyInt &x, const TaintedInftyInt &y);
261 
273  friend bool
274  operator<(const TaintedInftyInt &x, const TaintedInftyInt &y);
275 
287  friend bool
288  operator>=(const TaintedInftyInt &x, const TaintedInftyInt &y);
289 
301  friend bool
302  operator<=(const TaintedInftyInt &x, const TaintedInftyInt &y);
303 
304  friend class InftyInt;
305 
314  friend std::ostream &
315  operator<<(std::ostream &out, const TaintedInftyInt &x);
316  };
317 
325  class InftyInt : public TaintedInftyInt {
326  public:
328  static const InftyInt neg_infty;
330  static const InftyInt pos_infty;
331 
332  private:
333  void
334  normalize() {
335  // std::cout << "NORMALIZE" <<std::endl;
336  if (is_neg_infty()) {
337  val = neg_infty.val;
338  } else if (is_pos_infty()) {
339  val = pos_infty.val;
340  }
341  }
342 
343  public:
349 
355  explicit
357  assert(is_normal());
358  }
359 
365  explicit
366  InftyInt(const FiniteInt &x);
367 
374  InftyInt(const TaintedInftyInt &x) : TaintedInftyInt(x) { normalize(); }
375 
383  InftyInt &
385  val = x.val;
386  normalize();
387  return *this;
388  }
389 
397  InftyInt &
398  operator+=(const FiniteInt &x);
399 
407  InftyInt &
408  operator-=(const FiniteInt &x);
409 
418  friend InftyInt
419  operator+(const InftyInt &x, const FiniteInt &y);
420 
429  friend InftyInt
430  operator-(const InftyInt &x, const FiniteInt &y);
431  };
432 
437  class FiniteInt : public InftyInt {
438  public:
443 
449  FiniteInt(base_type x) : InftyInt(x) { assert(is_finite()); }
450 
456  const base_type &
457  finite_value() const {
458  return val;
459  }
460 
468  friend FiniteInt
469  operator+(const FiniteInt &x, const FiniteInt &y);
470 
478  friend FiniteInt
479  operator-(const FiniteInt &x, const FiniteInt &y);
480  };
481 
482  inline TaintedInftyInt
483  operator+(const TaintedInftyInt &x, const FiniteInt &y) {
484  TaintedInftyInt res(x);
485  res.val += y.val;
486  return res;
487  }
488 
489  inline TaintedInftyInt
490  operator-(const TaintedInftyInt &x, const FiniteInt &y) {
491  TaintedInftyInt res(x);
492  res.val -= y.val;
493  return res;
494  }
495 
496  inline TaintedInftyInt
497  operator+(const InftyInt &x, const InftyInt &y) {
498  TaintedInftyInt res(x);
499  res.val += y.val;
500  return res;
501  }
502 
503  inline TaintedInftyInt
504  operator-(const InftyInt &x, const InftyInt &y) {
505  TaintedInftyInt res(x);
506  res.val -= y.val;
507  return res;
508  }
509 
510  inline InftyInt &
512  val += x.val;
513  return *this;
514  }
515 
516  inline InftyInt &
518  val -= x.val;
519  return *this;
520  }
521 
522  inline InftyInt
523  operator+(const InftyInt &x, const FiniteInt &y) {
524  InftyInt res(x);
525  res.val += y.val;
526  return res;
527  }
528 
529  inline InftyInt
530  operator-(const InftyInt &x, const FiniteInt &y) {
531  InftyInt res(x);
532  res.val -= y.val;
533  return res;
534  }
535 
536  inline FiniteInt
537  operator+(const FiniteInt &x, const FiniteInt &y) {
538  FiniteInt res(x);
539  res.val += y.val;
540  return res;
541  }
542 
543  inline FiniteInt
544  operator-(const FiniteInt &x, const FiniteInt &y) {
545  FiniteInt res(x);
546  res.val -= y.val;
547  return res;
548  }
549 
550  inline bool
552  return x.val == y.val;
553  }
554 
555  inline TaintedInftyInt &
557  val = x.val;
558  return *this;
559  }
560 
561  inline TaintedInftyInt
562  min(const TaintedInftyInt &x, const TaintedInftyInt &y) {
563  return TaintedInftyInt(std::min(x.val, y.val));
564  }
565 
566  inline TaintedInftyInt
567  max(const TaintedInftyInt &x, const TaintedInftyInt &y) {
568  return TaintedInftyInt(std::max(x.val, y.val));
569  }
570 
572 
573  inline bool
575  return x.val > y.val;
576  }
577 
578  inline bool
579  operator<(const TaintedInftyInt &x, const TaintedInftyInt &y) {
580  return x.val < y.val;
581  }
582 
583  inline bool
585  return x.val >= y.val;
586  }
587 
588  inline bool
589  operator<=(const TaintedInftyInt &x, const TaintedInftyInt &y) {
590  return x.val <= y.val;
591  }
592 
593 } // end namespace LocARNA
594 
595 #endif
Definition: infty_int.hh:437
const base_type & finite_value() const
Access finite value.
Definition: infty_int.hh:457
friend FiniteInt operator+(const FiniteInt &x, const FiniteInt &y)
Add.
Definition: infty_int.hh:537
FiniteInt(base_type x)
Construct from base type value.
Definition: infty_int.hh:449
FiniteInt()
Construct empty.
Definition: infty_int.hh:442
friend FiniteInt operator-(const FiniteInt &x, const FiniteInt &y)
Subtract.
Definition: infty_int.hh:544
Definition: infty_int.hh:325
InftyInt()
Construct empty.
Definition: infty_int.hh:348
friend InftyInt operator-(const InftyInt &x, const FiniteInt &y)
Definition: infty_int.hh:530
static const InftyInt neg_infty
normalized negative infinity
Definition: infty_int.hh:328
static const InftyInt pos_infty
normalized positive infinity
Definition: infty_int.hh:330
InftyInt(const base_type &x)
Construct from base type.
Definition: infty_int.hh:356
friend InftyInt operator+(const InftyInt &x, const FiniteInt &y)
Definition: infty_int.hh:523
InftyInt & operator-=(const FiniteInt &x)
Definition: infty_int.hh:517
InftyInt & operator=(TaintedInftyInt &x)
Assignment from potentially tainted infty int.
Definition: infty_int.hh:384
InftyInt(const TaintedInftyInt &x)
Construct from potentially tainted.
Definition: infty_int.hh:374
InftyInt & operator+=(const FiniteInt &x)
Definition: infty_int.hh:511
Definition: infty_int.hh:56
friend bool operator>(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:574
TaintedInftyInt()
Construct empty.
Definition: infty_int.hh:80
static const base_type min_normal_neg_infty
minimum normal infinite value
Definition: infty_int.hh:71
static const base_type max_normal_pos_infty
maximum normal infinite value
Definition: infty_int.hh:74
friend bool operator==(const TaintedInftyInt &x, const TaintedInftyInt &y)
Equality test.
Definition: infty_int.hh:551
static const base_type max_finity
maximum finite value
Definition: infty_int.hh:68
static base_type min_finite()
minimum finite value
Definition: infty_int.hh:95
friend TaintedInftyInt operator+(const TaintedInftyInt &x, const FiniteInt &y)
Add.
Definition: infty_int.hh:483
TaintedInftyInt(const base_type &x)
Construct from base type.
Definition: infty_int.hh:87
friend bool operator<(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:579
long int base_type
the base type
Definition: infty_int.hh:59
bool is_neg_infty() const
Definition: infty_int.hh:115
bool is_normal() const
Definition: infty_int.hh:145
friend bool operator<=(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:589
static base_type max_finite()
maximum finite value
Definition: infty_int.hh:105
static const base_type min_finity
minimum finite value
Definition: infty_int.hh:65
friend TaintedInftyInt operator-(const TaintedInftyInt &x, const FiniteInt &y)
Subtract.
Definition: infty_int.hh:490
friend TaintedInftyInt max(const TaintedInftyInt &x, const TaintedInftyInt &y)
Maximum.
Definition: infty_int.hh:567
bool is_finite() const
Definition: infty_int.hh:135
TaintedInftyInt & operator=(const FiniteInt &x)
Assignment.
Definition: infty_int.hh:556
friend bool operator>=(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:584
base_type finite_value() const
Convert finite value to base type.
Definition: infty_int.hh:156
base_type val
value
Definition: infty_int.hh:62
bool is_pos_infty() const
Definition: infty_int.hh:125
friend TaintedInftyInt min(const TaintedInftyInt &x, const TaintedInftyInt &y)
Minimum.
Definition: infty_int.hh:562
friend std::ostream & operator<<(std::ostream &out, const TaintedInftyInt &x)
Definition: infty_int.cc:34
Definition: aligner.cc:15
bool operator>=(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:584
bool operator==(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:551
TaintedInftyInt min(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:562
TaintedInftyInt operator+(const TaintedInftyInt &x, const FiniteInt &y)
Definition: infty_int.hh:483
bool operator>(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:574
TaintedInftyInt max(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:567
bool operator<=(const TaintedInftyInt &x, const TaintedInftyInt &y)
Definition: infty_int.hh:589
bool operator<(const EPM &epm1, const EPM &epm2)
Definition: exact_matcher.hh:1254
TaintedInftyInt operator-(const TaintedInftyInt &x, const FiniteInt &y)
Definition: infty_int.hh:490