1 #ifndef ROSE_Combinatorics_H
2 #define ROSE_Combinatorics_H
13 namespace Combinatorics {
22 T next = retval * n--;
40 permute(std::vector<T> &values, uint64_t pn,
size_t sz=(
size_t)(-1))
44 assert(sz<=values.size());
46 for (
size_t i=0; i<sz; ++i) {
47 uint64_t radix = sz - i;
48 uint64_t idx = pn % radix;
65 nitems = std::min(nitems, vector.size());
66 limit = std::min(limit, nitems);
68 for (
size_t i=0; i<limit; ++i)
69 std::swap(vector[i], vector[lcg->next()%nitems]);
76 std::vector<uint8_t>
sha1_digest(
const uint8_t *data,
size_t size);
77 std::vector<uint8_t>
sha1_digest(
const std::vector<uint8_t> &data);
78 std::vector<uint8_t>
sha1_digest(
const std::string &data);
107 for (
typename KeyValList::iterator pi=
pairs.begin(); pi!=
pairs.end(); ++pi) {
115 for (
typename KeyValList::iterator pi=
pairs.begin(); pi!=
pairs.end(); ++pi) {
119 assert(!
"not found");
131 if (src.empty() || tgt.empty())
132 return std::max(src.size(), tgt.size());
134 const size_t x = src.size();
135 const size_t y = tgt.size();
136 std::vector<std::vector<size_t> > score(x+2, std::vector<size_t>(y+2, 0));
137 size_t score_ceil = x + y;
138 score[0][0] = score_ceil;
139 for (
size_t i=0; i<=x; ++i) {
141 score[i+1][0] = score_ceil;
143 for (
size_t j=0; j<=y; ++j) {
145 score[0][j+1] = score_ceil;
149 for (
size_t i=0; i<x; ++i)
151 for (
size_t j=0; j<y; ++j)
154 for (
size_t i=1; i<=x; ++i) {
156 for (
size_t j=1; j<=y; ++j) {
157 size_t i1 = dict[tgt[j-1]];
159 if (src[i-1]==tgt[j-1]) {
160 score[i+1][j+1] = score[i][j];
163 score[i+1][j+1] = std::min(score[i][j], std::min(score[i+1][j], score[i][j+1])) + 1;
166 score[i+1][j+1] = std::min(score[i+1][j+1], score[i1][j1] + (i-i1-1) + 1 + (j-j1-1));
171 return score[x+1][y+1];
180 if (src.empty() || tgt.empty())
181 return std::max(src.size(), tgt.size());
183 const size_t x = src.size();
184 const size_t y = tgt.size();
185 std::vector<std::vector<size_t> > score(x+2, std::vector<size_t>(y+2, 0));
186 size_t score_ceil = x + y;
187 score[0][0] = score_ceil;
188 for (
size_t i=0; i<=x; ++i) {
190 score[i+1][0] = score_ceil;
192 for (
size_t j=0; j<=y; ++j) {
194 score[0][j+1] = score_ceil;
198 for (
size_t i=0; i<x; ++i)
200 for (
size_t j=0; j<y; ++j)
203 for (
size_t i=1; i<=x; ++i) {
205 for (
size_t j=1; j<=y; ++j) {
206 if (src[i-1]==tgt[j-1]) {
207 score[i+1][j+1] = score[i][j];
210 score[i+1][j+1] = std::min(score[i][j], std::min(score[i+1][j], score[i][j+1])) + 1;
216 return score[x+1][y+1];