Navigation Menu

Skip to content

Commit

Permalink
grn_ts: add grn_ts_op_logical_not_bool()
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Oct 9, 2015
1 parent d47254c commit 109cbb1
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions lib/ts.c
Expand Up @@ -801,6 +801,12 @@ grn_ts_op_get_precedence(grn_ts_op_type op_type) {

/* FIXME: The following implementation assumes that NaN values don't appear. */

/* grn_ts_op_logical_not_bool() returns !arg. */
inline static grn_ts_bool
grn_ts_op_logical_not_bool(grn_ts_bool arg) {
return !arg;
}

/* grn_ts_op_equal_bool() returns lhs == rhs. */
inline static grn_ts_bool
grn_ts_op_equal_bool(grn_ts_bool lhs, grn_ts_bool rhs) {
Expand Down Expand Up @@ -3203,19 +3209,25 @@ grn_ts_op_minus_check_args(grn_ctx *ctx, grn_ts_expr_op_node *node) {
static grn_rc
grn_ts_expr_op_node_check_args(grn_ctx *ctx, grn_ts_expr_op_node *node) {
switch (node->op_type) {
case GRN_TS_OP_LOGICAL_AND:
case GRN_TS_OP_LOGICAL_OR: {
if (node->args[1]->data_kind != GRN_TS_BOOL) {
case GRN_TS_OP_LOGICAL_NOT: {
if (node->args[0]->data_kind != GRN_TS_BOOL) {
GRN_TS_ERR_RETURN(GRN_INVALID_ARGUMENT, "invalid data kind: %d",
node->args[1]->data_kind);
node->args[0]->data_kind);
}
/* Fall through. */
node->data_kind = GRN_TS_BOOL;
node->data_type = GRN_DB_BOOL;
return GRN_SUCCESS;
}
case GRN_TS_OP_LOGICAL_NOT: {
case GRN_TS_OP_LOGICAL_AND:
case GRN_TS_OP_LOGICAL_OR: {
if (node->args[0]->data_kind != GRN_TS_BOOL) {
GRN_TS_ERR_RETURN(GRN_INVALID_ARGUMENT, "invalid data kind: %d",
node->args[0]->data_kind);
}
if (node->args[1]->data_kind != GRN_TS_BOOL) {
GRN_TS_ERR_RETURN(GRN_INVALID_ARGUMENT, "invalid data kind: %d",
node->args[1]->data_kind);
}
node->data_kind = GRN_TS_BOOL;
node->data_type = GRN_DB_BOOL;
return GRN_SUCCESS;
Expand Down Expand Up @@ -3358,7 +3370,7 @@ grn_ts_op_logical_not_evaluate(grn_ctx *ctx, grn_ts_expr_op_node *node,
return rc;
}
for (i = 0; i < n_in; i++) {
out_ptr[i] = !out_ptr[i];
out_ptr[i] = grn_ts_op_logical_not_bool(out_ptr[i]);
}
return GRN_SUCCESS;
}
Expand Down Expand Up @@ -3895,7 +3907,7 @@ grn_ts_op_logical_not_filter(grn_ctx *ctx, grn_ts_expr_op_node *node,
return rc;
}
for (i = 0, count = 0; i < n_in; i++) {
if (!buf_ptr[i]) {
if (grn_ts_op_logical_not_bool(buf_ptr[i])) {
out[count++] = in[i];
}
}
Expand Down

0 comments on commit 109cbb1

Please sign in to comment.