File: PackedArray.cpp

package info (click to toggle)
rna-star 2.7.8a%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,076 kB
  • sloc: cpp: 20,429; awk: 483; ansic: 470; makefile: 181; sh: 31
file content (43 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (6)
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
40
41
42
43
# include "PackedArray.h"

PackedArray::PackedArray() {
    charArray=NULL;
    arrayAllocated=false;
};

void PackedArray::defineBits(uint Nbits, uint lengthIn){
    wordLength=Nbits;
    wordCompLength=sizeof(uint)*8LLU-wordLength;
    bitRecMask=(~0LLU)>>wordCompLength;
    length=lengthIn;
    lengthByte=(length-1)*wordLength/8LLU+sizeof(uint);
//     lengthByte=((lengthByte+sizeof(uint)-1LLU)/sizeof(uint))*sizeof(uint);
};

void PackedArray::writePacked( uint jj, uint x) {
   uint b=jj*wordLength;
   uint B=b/8LLU;
   uint S=b%8LLU;

   x = x << S;
   uint* a1 = (uint*) (charArray+B);
   *a1 = ( (*a1) & ~(bitRecMask<<S) ) | x;
};

void PackedArray::pointArray(char* pointerCharIn) {
    charArray=pointerCharIn;
};

void PackedArray::allocateArray() {
    charArray=new char[lengthByte];
    memset(charArray+lengthByte-sizeof(uint),0,sizeof(uint));//set the last 8 bytes to zero, since some of them may lnever be written
    arrayAllocated=true;
};

void PackedArray::deallocateArray() {
    if (arrayAllocated) {
        delete[] charArray;
        arrayAllocated=false;
    };
    charArray=NULL;
};