MCPcopy Create free account
hub / github.com/Gecode/gecode / normalize

Method normalize

gecode/int/int-set.cpp:90–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88 }
89
90 void
91 IntSet::normalize(Range* r, int n) {
92 if (n > 0) {
93 // Sort ranges
94 {
95 MinInc lt_mi;
96 Support::quicksort<Range>(r, n, lt_mi);
97 }
98 // Conjoin continuous ranges
99 {
100 int min = r[0].min;
101 int max = r[0].max;
102 int i = 1;
103 int j = 0;
104 while (i < n) {
105 if (max+1 < r[i].min) {
106 r[j].min = min; r[j].max = max; j++;
107 min = r[i].min; max = r[i].max; i++;
108 } else {
109 max = std::max(max,r[i].max); i++;
110 }
111 }
112 r[j].min = min; r[j].max = max;
113 n=j+1;
114 }
115 IntSetObject* o = IntSetObject::allocate(n);
116 unsigned int s = 0;
117 for (int i=0; i<n; i++) {
118 s += static_cast<unsigned int>(r[i].max-r[i].min+1);
119 o->r[i]=r[i];
120 }
121 o->size = s;
122 object(o);
123 }
124 }
125
126 void
127 IntSet::init(const int r[], int n) {

Callers

nothing calls this directly

Calls 1

maxFunction · 0.70

Tested by

no test coverage detected