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

Method finalize

gecode/int/extensional/tuple-set.cpp:102–245  ·  view source on GitHub ↗

* Tuple set data * */

Source from the content-addressed store, hash-verified

100 *
101 */
102 void
103 TupleSet::Data::finalize(void) {
104 using namespace Int::Extensional;
105 assert(!finalized());
106 // Mark as finalized
107 n_free = -1;
108
109 // Initialization
110 if (n_tuples == 0) {
111 heap.rfree(td);
112 td=nullptr;
113 return;
114 }
115
116 // Compact and copy data
117 Region r;
118 // Set up tuple pointers
119 Tuple* tuple = r.alloc<Tuple>(n_tuples);
120 {
121 for (int t=0; t<n_tuples; t++)
122 tuple[t] = td + t*arity;
123 TupleCompare tc(arity);
124 Support::quicksort(tuple, n_tuples, tc);
125 // Remove duplicates
126 int j=1;
127 for (int t=1; t<n_tuples; t++) {
128 for (int a=0; a<arity; a++)
129 if (tuple[t-1][a] != tuple[t][a])
130 goto notsame;
131 goto same;
132 notsame: ;
133 tuple[j++] = tuple[t];
134 same: ;
135 }
136 assert(j <= n_tuples);
137 n_tuples=j;
138 // Initialize hash key
139 key = static_cast<std::size_t>(n_tuples);
140 cmb_hash(key, arity);
141 // Copy into now possibly smaller area
142 int* new_td = heap.alloc<int>(n_tuples*arity);
143 for (int t=0; t<n_tuples; t++) {
144 for (int a=0; a<arity; a++) {
145 new_td[t*arity+a] = tuple[t][a];
146 cmb_hash(key,tuple[t][a]);
147 }
148 tuple[t] = new_td + t*arity;
149 }
150 heap.rfree(td);
151 td = new_td;
152 }
153
154 // Only now compute how many tuples are needed!
155 n_words = BitSetData::data(static_cast<unsigned int>(n_tuples));
156
157 // Compute range information
158 {
159 /*

Callers

nothing calls this directly

Calls 8

quicksortFunction · 0.85
cmb_hashFunction · 0.85
minFunction · 0.50
maxFunction · 0.50
rfreeMethod · 0.45
initMethod · 0.45
widthMethod · 0.45
supportsMethod · 0.45

Tested by

no test coverage detected