Permalink
Browse files

Use flags instead of boolean parameters.

  • Loading branch information...
1 parent 9b545e6 commit dd329e96ce62e0433c3267f9a0e53b4f9f9cbcae @jjwhitney committed Jan 13, 2012
Showing with 28 additions and 23 deletions.
  1. +15 −17 src/bdelta.cpp
  2. +9 −2 src/bdelta.h
  3. +4 −4 src/libbdelta.cpp
View
@@ -25,9 +25,9 @@ void *f_read(void *f, void *buf, unsigned place, unsigned num) {
return buf;
}
-void my_pass(BDelta_Instance *b, unsigned blocksize, unsigned minMatchSize, bool local) {
- bdelta_pass(b, blocksize, minMatchSize, local);
- bdelta_clean_matches(b, true);
+void my_pass(BDelta_Instance *b, unsigned blocksize, unsigned minMatchSize, unsigned flags) {
+ bdelta_pass(b, blocksize, minMatchSize, flags);
+ bdelta_clean_matches(b, BDELTA_REMOVE_OVERLAP);
}
int main(int argc, char **argv) {
@@ -62,20 +62,18 @@ int main(int argc, char **argv) {
// 161-180 947 953 967 971 977 983 991 997
int seq[] = {503, 127, 31, 7, 5, 3, -31, 31, 7, 5, 3, -7, 2};
- my_pass(b, 997, 1994, true);
- my_pass(b, 503, 1006, true);
- my_pass(b, 127, 254, true);
- my_pass(b, 31, 62, true);
- my_pass(b, 7, 14, true);
- my_pass(b, 5, 10, true);
- my_pass(b, 3, 6, true);
- my_pass(b, 13, 26, false);
- my_pass(b, 7, 14, true);
- my_pass(b, 5, 10, true);
-
- bdelta_clean_matches(b, true);
-
- nummatches = bdelta_nummatches(b);
+ my_pass(b, 997, 1994, BDELTA_LOCAL);
+ my_pass(b, 503, 1006, BDELTA_LOCAL);
+ my_pass(b, 127, 254, BDELTA_LOCAL);
+ my_pass(b, 31, 62, BDELTA_LOCAL);
+ my_pass(b, 7, 14, BDELTA_LOCAL);
+ my_pass(b, 5, 10, BDELTA_LOCAL);
+ my_pass(b, 3, 6, BDELTA_LOCAL);
+ my_pass(b, 13, 26, 0);
+ my_pass(b, 7, 14, BDELTA_LOCAL);
+ my_pass(b, 5, 10, BDELTA_LOCAL);
+
+ nummatches = bdelta_numMatches(b);
unsigned * copyloc1 = new unsigned[nummatches + 1];
unsigned * copyloc2 = new unsigned[nummatches + 1];
View
@@ -29,10 +29,10 @@ BDelta_Instance *bdelta_init_alg(unsigned data1_size, unsigned data2_size,
unsigned tokenSize);
void bdelta_done_alg(BDelta_Instance *b);
-void bdelta_pass(BDelta_Instance *b, unsigned blockSize, unsigned minMatchSize, int local);
+void bdelta_pass(BDelta_Instance *b, unsigned blockSize, unsigned minMatchSize, unsigned flags);
void bdelta_swap_inputs(BDelta_Instance *b);
-void bdelta_clean_matches(BDelta_Instance *b, int removeOverlap);
+void bdelta_clean_matches(BDelta_Instance *b, unsigned flags);
unsigned bdelta_numMatches(BDelta_Instance *b);
@@ -42,6 +42,13 @@ void bdelta_getMatch(BDelta_Instance *b, unsigned matchNum,
int bdelta_getError(BDelta_Instance *b);
void bdelta_showMatches(BDelta_Instance *b);
+// Flags for bdelta_pass()
+#define BDELTA_LOCAL 1
+#define BDELTA_SIDES_ORDERED 2
+
+// Flags for bdelta_clean_matches()
+#define BDELTA_REMOVE_OVERLAP 1
+
enum BDELTA_RESULT {
BDELTA_OK = 0,
BDELTA_MEM_ERROR = -1,
View
@@ -348,7 +348,7 @@ void bdelta_swap_inputs(BDelta_Instance *b) {
b->matches.sort(compareMatchP2);
}
-void bdelta_clean_matches(BDelta_Instance *b, int removeOverlap) {
+void bdelta_clean_matches(BDelta_Instance *b, unsigned flags) {
// TODO: delete worse match when there's a conflict.
std::list<Match>::iterator place = b->matches.begin();
while (true) {
@@ -358,7 +358,7 @@ void bdelta_clean_matches(BDelta_Instance *b, int removeOverlap) {
if (place == b->matches.end())
break;
- if (removeOverlap)
+ if (flags & BDELTA_REMOVE_OVERLAP)
if (place != b->matches.begin() && prior(place)->p2 + prior(place)->num > place->p2) {
prior(place)->num = place->p2 - prior(place)->p2;
if (! prior(place)->num)
@@ -390,7 +390,7 @@ void get_unused_blocks(UnusedRange *unused, unsigned *numunusedptr) {
}
}
-void bdelta_pass(BDelta_Instance *b, unsigned blocksize, unsigned minMatchSize, int local) {
+void bdelta_pass(BDelta_Instance *b, unsigned blocksize, unsigned minMatchSize, unsigned flags) {
// Trick for including the free range at the end.
b->matches.push_back(Match(b->data1_size, b->data2_size, 0));
@@ -410,7 +410,7 @@ void bdelta_pass(BDelta_Instance *b, unsigned blocksize, unsigned minMatchSize,
get_unused_blocks(unused2, &numunused2);
//std::sort(unused2, unused2 + numunused2, comparemrp2);
- if (local) {
+ if (flags & BDELTA_LOCAL) {
std::sort(unused, unused + numunused, comparemrp2);
for (unsigned i = 0; i < numunused; ++i)
if (unused[i].num >= blocksize && unused2[i].num >= blocksize)

0 comments on commit dd329e9

Please sign in to comment.