Navigation Menu

Skip to content

Commit

Permalink
Change the behavior of GRN_RSET_SUBRECS_CMP().
Browse files Browse the repository at this point in the history
  • Loading branch information
daijiro committed Jun 21, 2013
1 parent 0d94576 commit 46ad383
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions lib/db.c
Expand Up @@ -1867,7 +1867,7 @@ subrecs_push(byte *subrecs, int size, int n_subrecs, int score, void *body, int
while (n) {
n2 = (n - 1) >> 1;
c2 = GRN_RSET_SUBRECS_NTH(subrecs,size,n2);
if (GRN_RSET_SUBRECS_CMP(score, *c2, dir)) { break; }
if (GRN_RSET_SUBRECS_CMP(score, *c2, dir) > 0) { break; }
GRN_RSET_SUBRECS_COPY(subrecs,size,n,c2);
n = n2;
}
Expand All @@ -1886,18 +1886,18 @@ subrecs_replace_min(byte *subrecs, int size, int n_subrecs, int score, void *bod
n2 = n1 + 1;
c1 = n1 < n_subrecs ? GRN_RSET_SUBRECS_NTH(subrecs,size,n1) : NULL;
c2 = n2 < n_subrecs ? GRN_RSET_SUBRECS_NTH(subrecs,size,n2) : NULL;
if (c1 && GRN_RSET_SUBRECS_CMP(score, *c1, dir)) {
if (c1 && GRN_RSET_SUBRECS_CMP(score, *c1, dir) > 0) {
if (c2 &&
GRN_RSET_SUBRECS_CMP(score, *c2, dir) &&
GRN_RSET_SUBRECS_CMP(*c1, *c2, dir)) {
GRN_RSET_SUBRECS_CMP(score, *c2, dir) > 0 &&
GRN_RSET_SUBRECS_CMP(*c1, *c2, dir) > 0) {
GRN_RSET_SUBRECS_COPY(subrecs,size,n,c2);
n = n2;
} else {
GRN_RSET_SUBRECS_COPY(subrecs,size,n,c1);
n = n1;
}
} else {
if (c2 && GRN_RSET_SUBRECS_CMP(score, *c2, dir)) {
if (c2 && GRN_RSET_SUBRECS_CMP(score, *c2, dir) > 0) {
GRN_RSET_SUBRECS_COPY(subrecs,size,n,c2);
n = n2;
} else {
Expand All @@ -1924,7 +1924,7 @@ grn_table_add_subrec_inline(grn_obj *table, grn_rset_recinfo *ri, int score,
if (pi) {
byte *body = (byte *)pi + DB_OBJ(table)->subrec_offset;
if (limit < n_subrecs) {
if (GRN_RSET_SUBRECS_CMP(score, *ri->subrecs, dir)) {
if (GRN_RSET_SUBRECS_CMP(score, *ri->subrecs, dir) > 0) {
subrecs_replace_min((byte *)ri->subrecs, subrec_size, limit, score, body, dir);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/db.h
Expand Up @@ -56,7 +56,7 @@ typedef struct {

#define GRN_RSET_N_SUBRECS(ri) ((ri)->n_subrecs & ~GRN_RSET_UTIL_BIT)

#define GRN_RSET_SUBRECS_CMP(a,b,dir) (((a) - (b))*(dir) > 0)
#define GRN_RSET_SUBRECS_CMP(a,b,dir) (((a) - (b))*(dir))
#define GRN_RSET_SUBRECS_NTH(subrecs,size,n) \
((int *)((byte *)subrecs + n * (size + GRN_RSET_SCORE_SIZE)))
#define GRN_RSET_SUBRECS_COPY(subrecs,size,n,src) \
Expand Down
12 changes: 6 additions & 6 deletions lib/hash.c
Expand Up @@ -3146,7 +3146,7 @@ subrecs_push(byte *subrecs, int size, int n_subrecs, int score, void *body, int
while (n) {
n2 = (n - 1) >> 1;
c2 = GRN_RSET_SUBRECS_NTH(subrecs,size,n2);
if (GRN_RSET_SUBRECS_CMP(score, *c2, dir)) { break; }
if (GRN_RSET_SUBRECS_CMP(score, *c2, dir) > 0) { break; }
GRN_RSET_SUBRECS_COPY(subrecs,size,n,c2);
n = n2;
}
Expand All @@ -3165,18 +3165,18 @@ subrecs_replace_min(byte *subrecs, int size, int n_subrecs, int score, void *bod
n2 = n1 + 1;
c1 = n1 < n_subrecs ? GRN_RSET_SUBRECS_NTH(subrecs,size,n1) : NULL;
c2 = n2 < n_subrecs ? GRN_RSET_SUBRECS_NTH(subrecs,size,n2) : NULL;
if (c1 && GRN_RSET_SUBRECS_CMP(score, *c1, dir)) {
if (c1 && GRN_RSET_SUBRECS_CMP(score, *c1, dir) > 0) {
if (c2 &&
GRN_RSET_SUBRECS_CMP(score, *c2, dir) &&
GRN_RSET_SUBRECS_CMP(*c1, *c2, dir)) {
GRN_RSET_SUBRECS_CMP(score, *c2, dir) > 0 &&
GRN_RSET_SUBRECS_CMP(*c1, *c2, dir) > 0) {
GRN_RSET_SUBRECS_COPY(subrecs,size,n,c2);
n = n2;
} else {
GRN_RSET_SUBRECS_COPY(subrecs,size,n,c1);
n = n1;
}
} else {
if (c2 && GRN_RSET_SUBRECS_CMP(score, *c2, dir)) {
if (c2 && GRN_RSET_SUBRECS_CMP(score, *c2, dir) > 0) {
GRN_RSET_SUBRECS_COPY(subrecs,size,n,c2);
n = n2;
} else {
Expand All @@ -3199,7 +3199,7 @@ grn_rhash_add_subrec(grn_hash *s, grn_rset_recinfo *ri, int score, void *body, i
int ssize = s->subrec_size;
int n_subrecs = GRN_RSET_N_SUBRECS(ri);
if (limit < n_subrecs) {
if (GRN_RSET_SUBRECS_CMP(score, *ri->subrecs, dir)) {
if (GRN_RSET_SUBRECS_CMP(score, *ri->subrecs, dir) > 0) {
subrecs_replace_min(ri->subrecs, ssize, limit, score, body, dir);
}
} else {
Expand Down

0 comments on commit 46ad383

Please sign in to comment.