aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2013-09-14 12:58:13 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2013-09-14 12:58:13 -0400
commit8d1e990611a128d123e47f8a068ff9b045794db4 (patch)
tree3a7154e0bee1809c0e29fd7df646e64491b3c28a
parent4ae5cfe9e627429ee4d27390da9eb07a410f8831 (diff)
improve performance of convert_kmer_to_index by using a bitwise OR to convert our characters to lowercare: str[i] | Ox20, and reduce the number of switches as a result
-rw-r--r--kmer_total_count.c3
-rw-r--r--kmer_utils.c14
2 files changed, 7 insertions, 10 deletions
diff --git a/kmer_total_count.c b/kmer_total_count.c
index 23ca512..6d07e13 100644
--- a/kmer_total_count.c
+++ b/kmer_total_count.c
@@ -13,8 +13,9 @@ int main(int argc, char **argv) {
char *line = NULL;
size_t len = 0;
ssize_t read;
+ long i = 0;
+
unsigned int kmer = 0;
- unsigned long i = 0;
unsigned long width = 0;
unsigned long long *counts;
diff --git a/kmer_utils.c b/kmer_utils.c
index e737346..c0441e2 100644
--- a/kmer_utils.c
+++ b/kmer_utils.c
@@ -16,27 +16,23 @@
// long kmer - how long of a index value you want to return
// long error_pos - what index to return for a non ACGT character
//
-inline long convert_kmer_to_index(const char *str, long kmer, long error_pos) {
+inline long convert_kmer_to_index(const char *str, int kmer, long error_pos) {
- long i = 0;
- long out = 0;
- long multiply = 1;
+ int i = 0;
+ unsigned long out = 0;
+ unsigned long multiply = 1;
for(i = kmer - 1; i >= 0; i--){
- switch(str[i]) {
+ switch(str[i] | 0x20 ) {
case 'a':
- case 'A':
break;
case 'c':
- case 'C':
out += 1 * multiply;
break;
case 'g':
- case 'G':
out += 2 * multiply;
break;
case 't':
- case 'T':
out += 3 * multiply;
break;
default: