-
Notifications
You must be signed in to change notification settings - Fork 0
/
marks.h
131 lines (118 loc) · 3.77 KB
/
marks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* (c) 30.07.2014 Martin Hünniger
*
* This file is part of DelDec.
*
* DelDec is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DelDec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef MARKS_H
#define MARKS_H
#include "ball.h"
#include <vector>
#include <algorithm>
#include <boost/dynamic_bitset.hpp>
namespace NAMESPACE {
struct Marks {
typedef boost::dynamic_bitset<> mark_type;
static mark_type compute(const std::vector<unsigned long> &vec, int max_size) {
std::vector<long> sorted_vec(vec.size());
std::copy(vec.begin(),
vec.end(),
sorted_vec.begin());
std::sort(sorted_vec.begin(),sorted_vec.end());
int log_max_size = 0;
int c = 1;
while(max_size-1 >= c) {
++log_max_size; c *= 2;
}
mark_type res(vec.size()*log_max_size);
for(auto i=0;i<sorted_vec.size();++i ) {
mark_type bits( log_max_size, sorted_vec[i] );
for( auto j=0;j<log_max_size;++j) {
res[log_max_size*i+j] = bits[j];
}
}
return res;
}
static mark_type compute_without_index(const std::vector<unsigned long> &vec, unsigned long index, int max_size) {
int log_max_size = 0;
int c = 1;
while(c <= max_size-1) {
++log_max_size; c *= 2;
}
#ifndef BLUBB
unsigned long sorted[vec.size()-1];
int i = 0;
for( unsigned long el : vec ) {
if(el != index) {
sorted[i] = el;
++i;
}
}
std::sort(sorted, sorted+vec.size()-1);
mark_type res(vec.size()*log_max_size);
for(auto k=0;k<vec.size()-1;++k ) {
mark_type bits( log_max_size, sorted[k] );
for( auto j=0;j<log_max_size;++j) {
res[log_max_size*k+j] = bits[j];
}
}
return res;
#else
std::vector<long> sorted_vec(0);
for( auto el : vec) {
if(el != index) {
sorted_vec.push_back(el);
}
}
std::sort(sorted_vec.begin(),sorted_vec.end());
mark_type res(vec.size()*log_max_size);
for(auto i=0;i<sorted_vec.size();++i ) {
mark_type bits( log_max_size, sorted_vec[i] );
for( auto j=0;j<log_max_size;++j) {
res[log_max_size*i+j] = bits[j];
}
}
return res;
#endif
}
static mark_type compute_exceptional(int dim, int max_size) {
int log_max_size = 0;
int c = 1;
while(max_size-1 >= log_max_size) {
++log_max_size; c *= 2;
}
mark_type res((dim+1)*log_max_size);
for(auto i=0;i<(dim+1)*log_max_size;++i ) {
res[i] = 1;
}
return res;
}
struct Cmp {
bool operator()( const mark_type& a,
const mark_type& b ) const
{
if( a.size() < b.size() ) return true;
else if( a.size() > b.size() ) return false;
for( int i = a.size()-1; i >= 0; --i ) {
if( a[i] < b[i] ) return true;
else if( a[i] > b[i] ) return false;
}
return false;
}
};
};
} // NAMESPACE
#endif // MARKS_H