src
range.cc
Go to the documentation of this file.
1 #include "src/util/range.h"
2 
3 namespace re2c
4 {
5 
6 free_list<Range*> Range::vFreeList;
7 
8 void Range::append_overlapping (Range * & head, Range * & tail, const Range * r)
9 {
10  if (!head)
11  {
12  head = Range::ran (r->lb, r->ub);
13  tail = head;
14  }
15  else if (tail->ub < r->lb)
16  {
17  tail->nx = Range::ran (r->lb, r->ub);
18  tail = tail->nx;
19  }
20  else if (tail->ub < r->ub)
21  {
22  tail->ub = r->ub;
23  }
24 }
25 
26 Range * Range::add (const Range * r1, const Range * r2)
27 {
28  Range * head = NULL;
29  Range * tail = NULL;
30  for (; r1 && r2;)
31  {
32  if (r1->lb < r2->lb)
33  {
34  append_overlapping (head, tail, r1);
35  r1 = r1->nx;
36  }
37  else
38  {
39  append_overlapping (head, tail, r2);
40  r2 = r2->nx;
41  }
42  }
43  for (; r1; r1 = r1->nx)
44  {
45  append_overlapping (head, tail, r1);
46  }
47  for (; r2; r2 = r2->nx)
48  {
49  append_overlapping (head, tail, r2);
50  }
51  return head;
52 }
53 
54 void Range::append (Range ** & ptail, uint32_t l, uint32_t u)
55 {
56  Range * & tail = * ptail;
57  tail = Range::ran (l, u);
58  ptail = &tail->nx;
59 }
60 
61 Range * Range::sub (const Range * r1, const Range * r2)
62 {
63  Range * head = NULL;
64  Range ** ptail = &head;
65  while (r1)
66  {
67  if (!r2 || r2->lb >= r1->ub)
68  {
69  append (ptail, r1->lb, r1->ub);
70  r1 = r1->nx;
71  }
72  else if (r2->ub <= r1->lb)
73  {
74  r2 = r2->nx;
75  }
76  else
77  {
78  if (r1->lb < r2->lb)
79  {
80  append (ptail, r1->lb, r2->lb);
81  }
82  while (r2 && r2->ub < r1->ub)
83  {
84  const uint32_t lb = r2->ub;
85  r2 = r2->nx;
86  const uint32_t ub = r2 && r2->lb < r1->ub
87  ? r2->lb
88  : r1->ub;
89  append (ptail, lb, ub);
90  }
91  r1 = r1->nx;
92  }
93  }
94  return head;
95 }
96 
97 } // namespace re2c
static Range * sub(const Range *r1, const Range *r2)
Definition: range.cc:61
static Range * ran(uint32_t l, uint32_t u)
Definition: range.h:31
static free_list< Range * > vFreeList
Definition: range.h:18
Definition: bitmap.cc:10
static Range * add(const Range *r1, const Range *r2)
Definition: range.cc:26