Skip to content

Commit

Permalink
Miscellaneous cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdrake committed Jun 9, 2015
1 parent 5020dcf commit 8d28926
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 26 deletions.
7 changes: 7 additions & 0 deletions extension/boolexpr/boolexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ struct BoolExprVector {
};


struct BoolExprDictItem {
struct BoolExpr *key;
struct BoolExpr *val;
struct BoolExprDictItem *tail;
};


struct BoolExprDict {
size_t _pridx;

Expand Down
7 changes: 0 additions & 7 deletions extension/boolexpr/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,5 @@
#define MAX_IDX 30


struct BoolExprDictItem {
struct BoolExpr *key;
struct BoolExpr *val;
struct BoolExprDictItem *tail;
};


#endif /* DICT_H */

8 changes: 4 additions & 4 deletions extension/boolexpr/flatten.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ _to_dnf(struct BoolExpr *nnf)
/* a | b & c */
if (IS_OR(ex)) {
temp = ex;
CHECK_NULL_1(ex, _absorb(temp), temp);
ex = _absorb(temp);
BoolExpr_DecRef(temp);
return ex;
}
Expand All @@ -275,7 +275,7 @@ _to_dnf(struct BoolExpr *nnf)
return ex;

temp = ex;
CHECK_NULL_1(ex, _absorb(temp), temp);
ex = _absorb(temp);
BoolExpr_DecRef(temp);
return ex;
}
Expand All @@ -302,7 +302,7 @@ _to_cnf(struct BoolExpr *nnf)
/* a & (b | c) */
if (IS_AND(ex)) {
temp = ex;
CHECK_NULL_1(ex, _absorb(temp), temp);
ex = _absorb(temp);
BoolExpr_DecRef(temp);
return ex;
}
Expand All @@ -317,7 +317,7 @@ _to_cnf(struct BoolExpr *nnf)
return ex;

temp = ex;
CHECK_NULL_1(ex, _absorb(temp), temp);
ex = _absorb(temp);
BoolExpr_DecRef(temp);
return ex;
}
Expand Down
8 changes: 2 additions & 6 deletions extension/boolexpr/nnf.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,13 @@ _eq_nnfify(struct BoolExpr *op)

xns = malloc(length * sizeof(struct BoolExpr *));
if (xns == NULL)
return NULL;
return NULL; // LCOV_EXCL_LINE

/* Equal(x0, x1, x2) <=> ~x0 & ~x1 & ~x2 | x0 & x1 & x2 */
for (size_t i = 0; i < length; ++i)
CHECK_NULL_N(xns[i], Not(xs[i]), i, xns);

all0 = And(length, xns);
if (all0 == NULL) {
_free_exs(length, xns);
return NULL;
}
CHECK_NULL_N(all0, And(length, xns), length, xns);

_free_exs(length, xns);

Expand Down
18 changes: 9 additions & 9 deletions extension/boolexpr/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ _orand_simplify(struct BoolExpr *op)

flat = malloc(n * sizeof(struct BoolExpr *));
if (flat == NULL)
return NULL;
return NULL; // LCOV_EXCL_LINE

/* 1. Flatten arguments, and eliminate {0, 1} */
for (size_t i = 0; i < op->data.xs->length; ++i) {
Expand Down Expand Up @@ -149,8 +149,8 @@ _orand_simplify(struct BoolExpr *op)

uniq = malloc(flat_len * sizeof(struct BoolExpr *));
if (uniq == NULL) {
free(flat);
return NULL;
free(flat); // LCOV_EXCL_LINE
return NULL; // LCOV_EXCL_LINE
}

/* 3. Apply: Or(~x, x) <=> 1, Or(x, x) <=> x */
Expand Down Expand Up @@ -217,7 +217,7 @@ _xor_simplify(struct BoolExpr *op)

flat = malloc(n * sizeof(struct BoolExpr *));
if (flat == NULL)
return NULL;
return NULL; // LCOV_EXCL_LINE

/* 1. Flatten arguments, and eliminate {0, 1} */
for (size_t i = 0; i < op->data.xs->length; ++i) {
Expand Down Expand Up @@ -256,8 +256,8 @@ _xor_simplify(struct BoolExpr *op)

uniq = malloc(flat_len * sizeof(struct BoolExpr *));
if (uniq == NULL) {
free(flat);
return NULL;
free(flat); // LCOV_EXCL_LINE
return NULL; // LCOV_EXCL_LINE
}

/* 3. Apply: Xor(~x, x) <=> 1, Xor(x, x) <=> 0 */
Expand Down Expand Up @@ -308,7 +308,7 @@ _eq_simplify(struct BoolExpr *op)

flat = malloc(length * sizeof(struct BoolExpr *));
if (flat == NULL)
return NULL;
return NULL; // LCOV_EXCL_LINE

/* 1. Eliminate {0, 1} */
for (size_t i = 0; i < length; ++i) {
Expand All @@ -332,8 +332,8 @@ _eq_simplify(struct BoolExpr *op)

uniq = malloc(flat_len * sizeof(struct BoolExpr *));
if (uniq == NULL) {
free(flat);
return NULL;
free(flat); // LCOV_EXCL_LINE
return NULL; // LCOV_EXCL_LINE
}

/* 3. Apply: Equal(~x, x) <=> 0, Equal(x0, x0, x1) <=> Equal(x0, x1) */
Expand Down
11 changes: 11 additions & 0 deletions extension/boolexpr/test/test_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ TEST_F(BoolExprTest, Iterate)
EXPECT_EQ(it->item, exp2[count]);
BoolExprIter_Next(it);
}

EXPECT_EQ(it->item, (struct BoolExpr *) NULL);

/* Should have no effect */
BoolExprIter_Next(it);
BoolExprIter_Next(it);
BoolExprIter_Next(it);
BoolExprIter_Next(it);

EXPECT_EQ(it->item, (struct BoolExpr *) NULL);

BoolExprIter_Del(it);

EXPECT_EQ(count, 18);
Expand Down

0 comments on commit 8d28926

Please sign in to comment.