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

Method unique

gecode/kernel/data/array.hpp:1416–1446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1414
1415 template<class View>
1416 void
1417 ViewArray<View>::unique(void) {
1418 if (n < 2)
1419 return;
1420 Region r;
1421 Kernel::ViewOcc<View>* o = r.alloc<Kernel::ViewOcc<View>>(n);
1422 for (int i=0; i<n; i++) {
1423 o[i].x = x[i]; o[i].i = i;
1424 }
1425 Support::quicksort<Kernel::ViewOcc<View>>(o,n);
1426 // Assign bucket numbers
1427 int* bkt = r.alloc<int>(n);
1428 int b = 0;
1429 bkt[o[0].i] = b;
1430 for (int i=1; i<n; i++) {
1431 if (o[i-1].x != o[i].x)
1432 b++;
1433 bkt[o[i].i] = b;
1434 }
1435 // Eliminate duplicate elements
1436 Support::BitSet<Region> seen(r,static_cast<unsigned int>(b+1));
1437 int j=0;
1438 for (int i=0; i<n; i++)
1439 if (!seen.get(static_cast<unsigned int>(bkt[i]))) {
1440 x[j++]=x[i]; seen.set(static_cast<unsigned int>(bkt[i]));
1441 } else {
1442 x[j]=x[i];
1443 }
1444 assert(j == b+1);
1445 n = j;
1446 }
1447
1448
1449 /*

Callers 15

postMethod · 0.45
postMethod · 0.45
postMethod · 0.45
relFunction · 0.45
clauseFunction · 0.45
postMethod · 0.45
postMethod · 0.45
postMethod · 0.45
postMethod · 0.45
postMethod · 0.45
postMethod · 0.45
postMethod · 0.45

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected