File: fastacc.c

package info (click to toggle)
r-cran-seqinr 3.4-5-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,876 kB
  • sloc: ansic: 1,987; makefile: 14
file content (39 lines) | stat: -rw-r--r-- 894 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <R.h>
#include <Rdefines.h>


SEXP fastacc(SEXP bits_in_char, SEXP target, SEXP database, SEXP noc, SEXP n){
  int i,j;
  SEXP res;
  int *pbits_in_char, *pnoc, *pn, *pres;
  unsigned char *ptarget, *pdatabase;
  int ires;

  PROTECT(bits_in_char = AS_INTEGER(bits_in_char));
  pbits_in_char = INTEGER_POINTER(bits_in_char);

  PROTECT(target = AS_RAW(target));
  ptarget = RAW_POINTER(target);

  PROTECT(database = AS_RAW(database));
  pdatabase = RAW_POINTER(database);

  PROTECT(noc = AS_INTEGER(noc));
  pnoc = INTEGER_POINTER(noc);

  PROTECT(n = AS_INTEGER(n));
  pn = INTEGER_POINTER(n);

  PROTECT(res = NEW_INTEGER(*pn));
  pres = INTEGER_POINTER(res);

  for(ires = i = 0 ; i < *pn * *pnoc; i += *pnoc, ires++){
    pres[ires] = 0;
    for(j = 0; j < *pnoc ; j++){
      pres[ires] += pbits_in_char[pdatabase[i+j] & ptarget[j]];
    }
  }

  UNPROTECT(6);
  return(res);
}