Skip to content

Commit

Permalink
Add difference operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianwalenz committed Sep 12, 2017
1 parent a047c21 commit 1b39d4a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/meryl/meryl-args.C
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ merylArgs::merylArgs(int argc, char **argv) {
personality = PERSONALITY_ADD;
} else if (strcmp(argv[arg], "sub") == 0) {
personality = PERSONALITY_SUB;
} else if (strcmp(argv[arg], "difference") == 0) {
personality = PERSONALITY_DIFFERENCE;
} else if (strcmp(argv[arg], "abs") == 0) {
personality = PERSONALITY_ABS;
} else if (strcmp(argv[arg], "divide") == 0) {
Expand Down
38 changes: 38 additions & 0 deletions src/meryl/meryl-binaryOp.C
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ binaryOperations(merylArgs *args) {
exit(1);
}
if ((args->personality != PERSONALITY_SUB) &&
(args->personality != PERSONALITY_DIFFERENCE) &&
(args->personality != PERSONALITY_ABS) &&
(args->personality != PERSONALITY_DIVIDE)) {
fprintf(stderr, "ERROR - only personalities sub and abs\n");
Expand Down Expand Up @@ -146,6 +147,43 @@ binaryOperations(merylArgs *args) {
}
}
break;
case PERSONALITY_DIFFERENCE:
while (A->validMer() || B->validMer()) {
Amer = A->theFMer();
Acnt = A->theCount();
Bmer = B->theFMer();
Bcnt = B->theCount();

// If A stream is out of mers, do nothing but read the B stream.
if (A->validMer() == false) {
B->nextMer();
continue;
}

// If B stream is out of mers, output the A mer.
if (B->validMer() == false) {
W->addMer(Amer, Acnt);
A->nextMer();
continue;
}

// If the same mer, do nothing but read new mers.
if (Amer == Bmer) {
A->nextMer();
B->nextMer();
continue;
}

// If A is before B, output A and read a new one.
// Otherwise, do nothing and read a new one.
if (Amer < Bmer) {
W->addMer(Amer, Acnt);
A->nextMer();
} else {
B->nextMer();
}
}
break;
case PERSONALITY_ABS:
while (A->validMer() || B->validMer()) {
Amer = A->theFMer();
Expand Down
1 change: 1 addition & 0 deletions src/meryl/meryl.C
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ main(int argc, char **argv) {
break;

case PERSONALITY_SUB:
case PERSONALITY_DIFFERENCE:
case PERSONALITY_ABS:
case PERSONALITY_DIVIDE:
binaryOperations(args);
Expand Down
5 changes: 3 additions & 2 deletions src/meryl/meryl.H
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@
#define PERSONALITY_MAXEXIST 0x04
#define PERSONALITY_ADD 0x05
#define PERSONALITY_SUB 0x06
#define PERSONALITY_DIVIDE 0x07
#define PERSONALITY_ABS 0x08
#define PERSONALITY_DIFFERENCE 0x07
#define PERSONALITY_DIVIDE 0x08
#define PERSONALITY_ABS 0x09

#define PERSONALITY_AND 0x10
#define PERSONALITY_NAND 0x11
Expand Down

0 comments on commit 1b39d4a

Please sign in to comment.