Guest User

Untitled

a guest
Jan 24th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.81 KB | None | 0 0
  1. #include "bwt.h"
  2.  
  3. void devoidBWT(){
  4. if(isBWTused){
  5.  
  6. }
  7. }
  8.  
  9. void printSA(char* msg,int16_t *sa,int n){
  10. printf("%sn",msg);
  11. for(int i=0; i<n; i++){
  12. printf("%4d -- %dn",i,sa[i]);
  13. }
  14. }
  15.  
  16. void printArray(char* msg,Array ar,int n){
  17. printf("%sn",msg);
  18. for(int i=0; i<n; i++){
  19. printf("%4d -- %dn",ARRAY_INDEX(ar,i),ARRAY_GET(ar,i));
  20. }
  21. }
  22.  
  23. void initFreqTable(Array buffer, Array freqTable, uint16_t symbolCount, int16_t k){
  24. printf("getCounts: n %d k %d buffer at %p freqTable %pn",symbolCount,k,buffer.arr,freqTable.arr);
  25. for(register uint16_t i=0; i < k; i++){
  26. ARRAY_SET(freqTable,i,0);
  27. }
  28. for(register uint16_t i=0; i < symbolCount; i++){
  29. ARRAY_UPDATE(freqTable,ARRAY_GET(buffer,i),1);
  30. }
  31. }
  32.  
  33.  
  34. void initBuckets(Array freqTable, Array suffixArrayHead, int16_t charset, bool isFront){
  35. uint32_t sum=0;
  36. printf("getBuckets: k %d isFront %d freqTable at %p suffixArrayHead %pn",charset,isFront,freqTable.arr,suffixArrayHead.arr);
  37. if(isFront){
  38. for(register uint16_t i=0; i < charset; i++){
  39. sum = sum + ARRAY_GET(freqTable,i);
  40. ARRAY_SET(suffixArrayHead,i,sum - ARRAY_GET(freqTable,i) );
  41. }
  42. }else{
  43. for(register uint16_t i=0; i < charset; i++){
  44. sum = sum + ARRAY_GET(freqTable,i);
  45. ARRAY_SET(suffixArrayHead,i,sum);
  46.  
  47. }
  48. }
  49. }
  50.  
  51. void lmsSort(Array buffer, Array freqTable, Array suffixArrayHead, uint16_t symbolCount, int16_t k){
  52. printf("lmsSort: n %d k %dn",symbolCount,k);
  53. int16_t index = symbolCount-1;
  54. int16_t c0,c1;
  55. int16_t bIndex;
  56.  
  57. // Compute L suffixes
  58. if( freqTable.arr == suffixArrayHead.arr){
  59. initFreqTable(buffer,freqTable,symbolCount,k);
  60. }
  61.  
  62. initBuckets(freqTable,suffixArrayHead,k,true);
  63.  
  64. c1 = ARRAY_GET(buffer,index);
  65. bIndex = ARRAY_GET(suffixArrayHead,c1);
  66. index--;
  67. suffixArray[bIndex++] = ( (ARRAY_GET(buffer,index) < c1 ) ? ~index : index);
  68.  
  69. for(register int16_t i=0; i<symbolCount; i++){
  70. index = suffixArray[i];
  71. if(index > 0){
  72. c0=ARRAY_GET(buffer,index);
  73. if( c0 != c1 ){
  74. ARRAY_SET(suffixArrayHead,c1,bIndex);
  75. c1 = c0;
  76. bIndex = ARRAY_GET(suffixArrayHead,c1);
  77. }
  78. index--;
  79. suffixArray[bIndex++] = ( (ARRAY_GET(buffer,index) < c1) ? ~index : index);
  80. suffixArray[i]=0;
  81. }else if (index < 0){
  82. suffixArray[i] = ~index;
  83. }
  84. }
  85.  
  86. // Compute S suffixes
  87. if( freqTable.arr == suffixArrayHead.arr){
  88. initFreqTable(buffer,freqTable,symbolCount,k);
  89. }
  90. //printSA("lmsSort:head:before getCounts",freqTable.arr,k);
  91. initBuckets(freqTable,suffixArrayHead,k,false);
  92.  
  93. //printSA("lmsSort:head:after getBuckets",suffixArrayHead.arr,k);
  94. //printSA("lmsSort:suffixArray",suffixArray,symbolCount);
  95. //mark
  96. c1=0; c0=0;
  97. bIndex = ARRAY_GET(suffixArrayHead,c1);
  98. for(register int16_t i=symbolCount-1; i >=0 ; i--){
  99. index = suffixArray[i];
  100. if(index > 0){
  101. c0 = ARRAY_GET(buffer,index);
  102. //printf("lmsSort:s: j %d c0 %c c1 %c b %dn",index,c0,c1,bIndex);
  103. if(c0 != c1){
  104. ARRAY_SET(suffixArrayHead,c1,bIndex);
  105. c1=c0;
  106. bIndex = ARRAY_GET(suffixArrayHead,c1);
  107. }
  108. index--;
  109. bIndex--;
  110. suffixArray[bIndex] = ( ( ARRAY_GET(buffer,index) > c1) ? ~(index+1) : index);
  111. suffixArray[i] = 0;
  112. }
  113. }
  114. //printSA("lmsSort:lastline:suffixArray",suffixArray,symbolCount);
  115. }
  116.  
  117. int16_t lmsPost(Array buffer, uint16_t symbolCount, int16_t m){
  118. int16_t i, j, p, q, plen, qlen, name;
  119. uint8_t c0,c1;
  120. bool same;
  121. printf("lmsPost: n %d m %dn",symbolCount,m);
  122. // printSA("lmsPost:start",suffixArray,symbolCount);
  123.  
  124.  
  125. // Compact all sorted substrings
  126. for( i=0; (p = suffixArray[i]) < 0; i++ ){
  127. suffixArray[i] = ~p;
  128. }
  129. if(i < m){
  130. for(j=i, ++i;;i++){
  131. p = suffixArray[i];
  132. if( p < 0 ){
  133. suffixArray[j++] = ~p;
  134. suffixArray[i] = 0;
  135. if ( j == m ){
  136. break;
  137. }
  138. }
  139. }
  140. }
  141.  
  142. // Store the length of all substrings
  143. i = symbolCount -1;
  144. j = symbolCount -1;
  145. c0 = ARRAY_GET(buffer,i);
  146. do{
  147. c1 = c0;
  148. }while((--i >= 0) && ((c0 = ARRAY_GET(buffer,i)) >= c1));
  149. for(; i >= 0; ){
  150. do {
  151. c1 = c0;
  152. }while((--i >= 0) && ((c0 = ARRAY_GET(buffer,i)) <= c1));
  153. if(i >= 0){
  154. suffixArray[m + ((i+1) >> 1)] = j - i;
  155. j = i+1;
  156. do {
  157. c1 = c0;
  158. }while( (--i >= 0) && ((c0 = ARRAY_GET(buffer,i)) >= c1));
  159. }
  160. }
  161.  
  162. // Find the lexicographic names of all substrings
  163. for(i=0, name = 0, q = symbolCount, qlen=0; i < m; i++){
  164. p = suffixArray[i];
  165. plen = suffixArray[m + (p >> 1)];
  166. same=false;
  167. if((plen == qlen) && ((q + plen) < symbolCount)){
  168. for(j=0; (j < plen) && ( ARRAY_GET(buffer,p + j) == ARRAY_GET(buffer,q + j)); j++){}
  169. if(j == plen) {
  170. same = true;
  171. }
  172. }
  173. if(!same){
  174. ++name;
  175. q = p;
  176. qlen = plen;
  177. }
  178. suffixArray[m + (p >> 1)] = name;
  179. }
  180. //printf("lmsPost last line name = %dn",name);
  181.  
  182. return name;
  183. }
  184.  
  185. void induceSA(Array buffer, Array freqTable, Array suffixArrayHead, uint16_t symbolCount, int16_t k){
  186. int16_t bIndex, i, index;
  187. uint8_t c0,c1;
  188. printf("induceSA: n %d k %dn",symbolCount,k);
  189. // Compute L suffixes
  190. if( freqTable.arr == suffixArrayHead.arr){
  191. initFreqTable(buffer,freqTable,symbolCount,k);
  192. }
  193. initBuckets(freqTable,suffixArrayHead,k,true);
  194. index = symbolCount -1;
  195. c1 = ARRAY_GET(buffer,index);
  196. bIndex = ARRAY_GET(suffixArrayHead,c1);
  197.  
  198. suffixArray[bIndex++] = ( (index > 0) && (ARRAY_GET(buffer,index -1) < c1) ) ? ~index : index;
  199. for(i=0; i<symbolCount; i++){
  200. index = suffixArray[i];
  201. suffixArray[i] = ~index;
  202. if(index > 0){
  203. c0 = ARRAY_GET(buffer,--index);
  204. if(c0 != c1){
  205. ARRAY_SET(suffixArrayHead,c1,bIndex);
  206. c1 = c0;
  207. bIndex = ARRAY_GET(suffixArrayHead,c1);
  208. }
  209. suffixArray[bIndex++] = ( (index > 0) && (ARRAY_GET(buffer,index-1) < c1) ) ? ~index : index;
  210. }
  211. }
  212.  
  213. // Compute S suffixes
  214. if( freqTable.arr == suffixArrayHead.arr){
  215. initFreqTable(buffer,freqTable,symbolCount,k);
  216. }
  217. initBuckets(freqTable,suffixArrayHead,k,false);
  218. c1=0;
  219. bIndex = ARRAY_GET(suffixArrayHead,c1);
  220. for(i=symbolCount-1; i >= 0; i--){
  221. index = suffixArray[i];
  222. if( index > 0 ){
  223. c0 = ARRAY_GET(buffer,--index);
  224. if(c0 != c1){
  225. ARRAY_SET(suffixArrayHead,c1,bIndex);
  226. c1 = c0;
  227. bIndex = ARRAY_GET(suffixArrayHead,c1);
  228. }
  229. suffixArray[--bIndex] = ( (index == 0) || (ARRAY_GET(buffer,index-1) > c1 )) ? ~index : index;
  230. }else{
  231. suffixArray[i] = ~index;
  232. }
  233. }
  234. }
  235.  
  236. int16_t sais(Array buffer, int16_t fs, uint16_t symbolCount, int16_t k){
  237. Array freqTable, suffixArrayHead, t_sa;
  238. register int16_t i, j, b, c, m, p, q, name, newfs;
  239. uint8_t c0, c1;
  240. int8_t flag=0;
  241. printf("sais: fs %d k %d n %dn",fs,k,symbolCount);
  242. if( k <= MAX_SYMBOLS){
  243.  
  244. ALLOCATE_ARRAY(freqTable,k);
  245.  
  246. if( k <= fs ){
  247. flag = 1;
  248. ARRAY_INIT_NEW(suffixArrayHead,symbolCount,symbolCount + fs - k,suffixArray);
  249. }else{
  250. flag = 3;
  251. ALLOCATE_ARRAY(suffixArrayHead,k);
  252. }
  253. }else if( k <= fs ){
  254. ARRAY_INIT_NEW(freqTable,symbolCount,symbolCount + fs - k,suffixArray);
  255.  
  256. if( k <= (fs-k) ){
  257. flag = 0;
  258. ARRAY_INIT_NEW(suffixArrayHead,symbolCount,symbolCount + fs - k*2,suffixArray);
  259. }else if( k <= 1024 ){
  260. flag = 2;
  261. ALLOCATE_ARRAY(suffixArrayHead,k);
  262. }else {
  263. ARRAY_EQU(suffixArrayHead,freqTable);
  264. flag = 8;
  265. }
  266. }else{
  267. flag = 4 | 8;
  268. ALLOCATE_ARRAY(freqTable,k);
  269. ALLOCATE_ARRAY(suffixArrayHead,k);
  270. }
  271.  
  272. // Sort all LMS substrings
  273. initFreqTable(buffer,freqTable,symbolCount,k);
  274. initBuckets(freqTable,suffixArrayHead,k,false);
  275.  
  276.  
  277. for(i=0; i<symbolCount; i++){
  278. suffixArray[i]=0;
  279. }
  280. b = -1 ;
  281. i = symbolCount - 1;
  282. j = symbolCount;
  283. m = 0;
  284. c0 = ARRAY_GET(buffer,i);
  285. do {
  286. c1 = c0;
  287. }while( (--i >= 0) && ( (c0 = ARRAY_GET(buffer,i)) >= c1));
  288. for(; i >= 0; ){
  289. do {
  290. c1 = c0;
  291. }while( ( --i >= 0 ) && ( (c0 = ARRAY_GET(buffer,i)) <= c1) );
  292.  
  293. if (i >= 0){
  294. if (b >= 0){
  295. suffixArray[b] = j;
  296. }
  297. b = ARRAY_UPDATE(suffixArrayHead,c1,-1);
  298. j = i;
  299. m++;
  300. do {
  301. c1 = c0;
  302. }while ( (--i >= 0) && ( (c0 = ARRAY_GET(buffer,i)) >= c1) );
  303. }
  304. }
  305. //printf("m is %d flag is %dn",m,flag);
  306. // marking
  307.  
  308. if (m > 1){
  309. lmsSort(buffer,freqTable,suffixArrayHead,symbolCount,k);
  310. name = lmsPost(buffer,symbolCount,m);
  311. }else if(m == 1){
  312. suffixArray[b] = j+1;
  313. name = 1;
  314. } else {
  315. name = 0;
  316. }
  317. // Solve the reduced problem, recurse if names are same
  318. if(name < m){
  319. //printf("sais:name < m flag=%d: freqTable %p sah %p sa %p flag %dn",flag,freqTable.arr,suffixArrayHead.arr,suffixArray,flag);
  320. if ( (flag & 4) != 0 ){
  321. FREE_ARRAY(freqTable)
  322. FREE_ARRAY(suffixArrayHead)
  323. }
  324. if ( (flag & 2) != 0 ){
  325. FREE_ARRAY(suffixArrayHead)
  326. }
  327. newfs = (symbolCount + fs) - (m * 2);
  328. if( (flag & (1 | 4 | 8) ) == 0 ){
  329. if( (k + name) <= newfs ){
  330. newfs = newfs - k;
  331. } else {
  332. flag = flag | 8;
  333. }
  334. }
  335. //mark
  336. for(i = m + (symbolCount >> 1) - 1, j = m * 2 + newfs - 1; m <= i; i--){
  337. if(suffixArray[i] != 0){
  338. suffixArray[j--] = suffixArray[i] - 1;
  339. }
  340. }
  341. //mark
  342. //printf("sais: before t_sa alloc sa %p sah %p freqTable %p t_sa %pn",suffixArray,suffixArrayHead.arr,freqTable.arr,t_sa.arr);
  343. ARRAY_INIT_NEW(t_sa,symbolCount,(m + newfs),suffixArray);
  344.  
  345. // printf("sais: after t_sa alloc sa %p sah %p freqTable %p t_sa %pn",suffixArray,suffixArrayHead.arr,freqTable.arr,t_sa.arr);
  346. printf("Printing new buffer curr = %dn",*(t_sa.index));
  347.  
  348. // before sais suffixArray is fine
  349. sais(t_sa,newfs,m,name);
  350.  
  351. // printf("sais: before t_sa free .arr %p .index %pn",t_sa.arr,t_sa.index);
  352.  
  353. FREE_ARRAY(t_sa)
  354. //printSA("sais:after recurse:suffixArray",suffixArray,symbolCount);
  355. //fail
  356. //puts("sais: after t_sa freen");
  357.  
  358. i = symbolCount - 1;
  359. j = m * 2 - 1;
  360. c0 = ARRAY_GET(buffer,i);
  361. do {
  362. c1 = c0;
  363. }while( ( --i >= 0 ) && ( (c0 = ARRAY_GET(buffer,i)) >= c1) );
  364. for(; i >= 0; ){
  365. do {
  366. c1 = c0;
  367. }while( (--i >= 0) && ( (c0 = ARRAY_GET(buffer,i)) <= c1) );
  368. if( i >= 0 ){
  369. suffixArray[j--] = i+1;
  370. do {
  371. c1 = c0;
  372. }while ( (--i <= 0) && ( (c0 = ARRAY_GET(buffer,i)) >= c1) );
  373. }
  374. }
  375.  
  376. for (i = 0 ; i < m; i++){
  377. suffixArray[i] = suffixArray[m + suffixArray[i]];
  378. }
  379. if( (flag & 4) != 0) {
  380. ALLOCATE_ARRAY(freqTable,k);
  381. ARRAY_EQU(suffixArrayHead,freqTable);
  382. }
  383. if( (flag & 2) != 0){
  384. ALLOCATE_ARRAY(suffixArrayHead,k);
  385. }
  386. }
  387.  
  388. // induce the result for the original problem
  389. if( (flag & 8) != 0 ) {
  390. initFreqTable(buffer,freqTable,symbolCount,k);
  391. }
  392. // Put all S* characters into their buckets
  393. if (m > 1){
  394. initBuckets(freqTable,suffixArrayHead,k,false);
  395. i = m - 1;
  396. j = symbolCount;
  397. p = suffixArray[i];
  398. c1 = ARRAY_GET(buffer,p);
  399. do {
  400. c0 = c1;
  401. q = ARRAY_GET(suffixArrayHead,c0);
  402. while( q < j ){
  403. suffixArray[--j] = 0;
  404. }
  405. do {
  406. suffixArray[--j] = p;
  407. if( --i < 0 ){
  408. break;
  409. }
  410. p = suffixArray[i];
  411. } while( (c1 = ARRAY_GET(buffer,p)) == c0);
  412. }while( i >= 0 );
  413. while ( j > 0) {
  414. suffixArray[--j] = 0;
  415. }
  416. induceSA(buffer,freqTable,suffixArrayHead,symbolCount,k);
  417.  
  418. FREE_ARRAY(freqTable)
  419. FREE_ARRAY(suffixArrayHead)
  420.  
  421. }
  422. return 0;
  423. }
  424.  
  425. int main(int argc, char* argv[]){
  426.  
  427. FILE* in=fopen(argv[1],"rb");
  428. uint8_t* buffer = (uint8_t*)malloc(sizeof(uint8_t)*BUFFER_SIZE);
  429. int symbolCount = fread(buffer,sizeof(uint8_t),BUFFER_SIZE,in);
  430.  
  431.  
  432.  
  433. suffixArray = calloc(symbolCount,sizeof(int16_t));
  434.  
  435.  
  436.  
  437. if( (buffer == NULL) || (suffixArray == NULL) )
  438. return NULL;
  439.  
  440. isBWTused=true;
  441. Array bufferArray;
  442.  
  443. ALLOCATE_ARRAY(bufferArray,symbolCount);
  444.  
  445. for(register int16_t i=0; i<symbolCount; i++){
  446. bufferArray.arr[i]=buffer[i];
  447. }
  448.  
  449. sais(bufferArray,0,symbolCount,MAX_SYMBOLS);
  450.  
  451. puts("Printing suffix array and BWTn");
  452. int key = -99;
  453. for(register int i=0; i<symbolCount; i++){
  454. int index=suffixArray[i]-1;
  455.  
  456. if(index<0){
  457. key=i;
  458. index=index+symbolCount;
  459. }
  460. printf("%4d %cn",suffixArray[i],buffer[index]);
  461. }
  462. printf("Key is %dn",key);
  463. fclose(in);
  464. }
  465.  
  466. #ifndef BWT_H
  467. #define BWT_H
  468.  
  469. #include<stdio.h>
  470. #include<stdlib.h>
  471. #include<stdbool.h>
  472. #include<inttypes.h>
  473.  
  474. #define MAX_SYMBOLS 256
  475. #define BUFFER_SIZE 2048
  476.  
  477.  
  478. typedef struct {
  479. int16_t *index;
  480. int16_t *arr;
  481. }Array;
  482.  
  483. #define ALLOCATE_ARRAY(A,size) A.arr = calloc(size,sizeof(int16_t));
  484. printf("ALLOCATE_ARRAY %s at %pn",#A,A.arr);
  485. A.index = calloc(1,sizeof(int16_t))
  486.  
  487. #define FREE_ARRAY(A) if( A.arr ) { printf("FREE_ARRAY %s at %pn",#A,A.arr); free(A.arr); A.arr = NULL;}
  488. if( A.index ) { free(A.index); A.index = NULL;}
  489.  
  490. #define ARRAY_INIT(A,ptr,i) A.arr = ptr;
  491. A.index = calloc(1,sizeof(int16_t));
  492. *(A.index) = i
  493.  
  494. #define ARRAY_INIT_NEW(A,size,i,ptr) ALLOCATE_ARRAY(A,size);
  495. *(A.index) = i;
  496. for(uint16_t x=0; x<size; x++){
  497. A.arr[x] = ptr[x];
  498. }
  499.  
  500. #define ARRAY_EQU(A,B) A.arr = B.arr;
  501. *(A.index) = *(B.index)
  502.  
  503. #define ARRAY_GET(A,i) A.arr[*(A.index) + i]
  504. #define ARRAY_INDEX(A,i) *(A.index) + i
  505. #define ARRAY_SET(A,i,val) A.arr[*(A.index) + i] = val
  506. #define ARRAY_UPDATE(A,i,val) A.arr[*(A.index) + i] = A.arr[*(A.index) + i] + val
  507.  
  508. bool isBWTused;
  509. int16_t *suffixArray;
  510. uint16_t totalUniqueSymbols;
  511. //pivan
  512. #endif
  513.  
  514. ACCCGAGATCGGGTAGGTAGTCGTGCAACTTTCGGAGTGTGGTACACCACAGAGCGCCGGGGGCCGGTAAGCTCGGTATCGACCGTTGAGCTCAGGCCCGTCGCCAAAGAAGAATAAGCGGTAGGAGACCGCGTACCCCGAGCAATAGTTGAGCTTCTCGGAATTACGGATGAGGGAATGAGAATTTACCACGACATGAGGAGAGTACGATGCAACCTAAGGGGACAAGTCCCGGCTTGACCGGCTTTAAGGTTGGGCTCCGACCTGGTAAGACAGACGCCTCAATACTCGCCACTCTAACACATGCGCCGCTTAGGAAAGGTTAACTCACGTCCATAAATTGCGTTGACCTCCCTCGTCCCGGTTGGTGGTTTCGGATTTTCCGCCGTTTATCGACAAGTACAACCGGGTGGATGACTGGTTAACTCCACGTCAAGGCGGGATCTGGAATTCCTGGGTTAGTTGATACACTGTTCCACCCGAGGGGTAGATGTCCCATC
  515.  
  516. import java.lang.String;
  517.  
  518. public class sais {
  519. private static interface BaseArray {
  520. public int get(int i);
  521. public void set(int i, int val);
  522. public int update(int i, int val);
  523. }
  524. private static class ByteArray implements BaseArray {
  525. private byte[] m_A = null;
  526. private int m_pos = 0;
  527. ByteArray(byte[] A, int pos) { m_A = A; m_pos = pos; }
  528. public int get(int i) { return m_A[m_pos + i] & 0xff; }
  529. public void set(int i, int val) { m_A[m_pos + i] = (byte)(val & 0xff); }
  530. public int update(int i, int val) { return m_A[m_pos + i] += val & 0xff; }
  531. }
  532. private static class CharArray implements BaseArray {
  533. private char[] m_A = null;
  534. private int m_pos = 0;
  535. CharArray(char[] A, int pos) { m_A = A; m_pos = pos; }
  536. public int get(int i) { return m_A[m_pos + i] & 0xffff; }
  537. public void set(int i, int val) { m_A[m_pos + i] = (char)(val & 0xffff); }
  538. public int update(int i, int val) { return m_A[m_pos + i] += val & 0xffff; }
  539. }
  540. private static class ShortArray implements BaseArray {
  541. private short[] m_A = null;
  542. private int m_pos = 0;
  543. ShortArray(short[] A, int pos) { m_A = A; m_pos = pos; }
  544. public int get(int i) { return m_A[m_pos + i] & 0xffff; }
  545. public void set(int i, int val) { m_A[m_pos + i] = (short)(val & 0xffff); }
  546. public int update(int i, int val) { return m_A[m_pos + i] += val & 0xffff; }
  547. }
  548. private static class IntArray implements BaseArray {
  549. public int[] m_A = null;
  550. public int m_pos = 0;
  551. IntArray(int[] A, int pos) { m_A = A; m_pos = pos; }
  552. public int get(int i) { return m_A[m_pos + i]; }
  553. public void set(int i, int val) { m_A[m_pos + i] = val; }
  554. public int update(int i, int val) { return m_A[m_pos + i] += val; }
  555. }
  556. private static class StringArray implements BaseArray {
  557. private String m_A = null;
  558. private int m_pos = 0;
  559. StringArray(String A, int pos) { m_A = A; m_pos = pos; }
  560. public int get(int i) { return (int)(m_A.charAt(m_pos + i) & 0xffff); }
  561. public void set(int i, int val) { }
  562. public int update(int i, int val) { return 0; }
  563. }
  564.  
  565. private static void printSA(String msg,int[] SA,int n){
  566. System.out.println(msg);
  567. for(int z=0;z<n; z++){
  568. System.out.printf("%4d -- %dn",z,SA[z]);
  569. }
  570. }
  571. /* find the start or end of each bucket */
  572. private static
  573. void
  574. getCounts(BaseArray T, BaseArray C, int n, int k) {
  575. System.out.printf("getCounts: n %d k %dn",n,k);
  576. int i;
  577. for(i = 0; i < k; ++i) { C.set(i, 0); }
  578. for(i = 0; i < n; ++i) { C.update(T.get(i), 1); }
  579. }
  580. private static
  581. void
  582. getBuckets(BaseArray C, BaseArray B, int k, boolean end) {
  583. int i, sum = 0;
  584. System.out.printf("getBuckets: k %d front %bn",k,!end);
  585. if(end != false) {
  586. for(i = 0; i < k; ++i) {
  587. sum += C.get(i); B.set(i, sum);
  588. } }
  589. else {
  590. for(i = 0; i < k; ++i) {
  591. sum += C.get(i); B.set(i, sum - C.get(i));
  592. } }
  593. }
  594.  
  595. /* sort all type LMS suffixes */
  596. private static
  597. void
  598. LMSsort(BaseArray T, int[] SA, BaseArray C, BaseArray B, int n, int k) {
  599. System.out.printf("lmsSort: n %d k %dn",n,k);
  600. int b, i, j;
  601. int c0, c1;
  602. /* compute SAl */
  603. if(C == B) { getCounts(T, C, n, k); }
  604. getBuckets(C, B, k, false); /* find starts of buckets */
  605. j = n - 1;
  606. b = B.get(c1 = T.get(j));
  607. --j;
  608. SA[b++] = (T.get(j) < c1) ? ~j : j;
  609. for(i = 0; i < n; ++i) {
  610. if(0 < (j = SA[i])) {
  611. if((c0 = T.get(j)) != c1) { B.set(c1, b); b = B.get(c1 = c0); }
  612. --j;
  613. SA[b++] = (T.get(j) < c1) ? ~j : j;
  614. SA[i] = 0;
  615. } else if(j < 0) {
  616. SA[i] = ~j;
  617. }
  618. }
  619. //marking
  620.  
  621. /* compute SAs */
  622. if(C == B) { getCounts(T, C, n, k); }
  623. // printSA("lmsSort:head:before getCounts",((IntArray)C).m_A,k);
  624. getBuckets(C, B, k, true); /* find ends of buckets */
  625.  
  626. // printSA("lmsSort:head:after getBuckets",((IntArray)B).m_A,k);
  627. // printSA("lmsSort:suffixArray",SA,n);
  628. //mark
  629. c0 = 0;
  630. for(i = n - 1, b = B.get(c1 = 0); 0 <= i; --i) {
  631. if(0 < (j = SA[i])) {
  632. c0 = T.get(j);
  633. // System.out.printf("lmsSort:s: j %d c0 %c c1 %c b %dn",j,c0,c1,b);
  634. if(c0 != c1) { B.set(c1, b); b = B.get(c1 = c0); }
  635. --j;
  636. SA[--b] = (T.get(j) > c1) ? ~(j + 1) : j;
  637. SA[i] = 0;
  638. }
  639. }
  640. // printSA("lmsSort:lastline:suffixArray",SA,n);
  641. }
  642. private static
  643. int
  644. LMSpostproc(BaseArray T, int[] SA, int n, int m) {
  645. int i, j, p, q, plen, qlen, name;
  646. int c0, c1;
  647. boolean diff;
  648. System.out.printf("lmsPost: n %d m %dn",n,m);
  649. // printSA("lmsPost:start",SA,n);
  650. /* compact all the sorted substrings into the first m items of SA
  651. 2*m must be not larger than n (proveable) */
  652. for(i = 0; (p = SA[i]) < 0; ++i) { SA[i] = ~p; }
  653. if(i < m) {
  654. for(j = i, ++i;; ++i) {
  655. if((p = SA[i]) < 0) {
  656. SA[j++] = ~p; SA[i] = 0;
  657. if(j == m) { break; }
  658. }
  659. }
  660. }
  661.  
  662. /* store the length of all substrings */
  663. i = n - 1;
  664. j = n - 1;
  665. c0 = T.get(n - 1);
  666. do { c1 = c0;
  667. } while((0 <= --i) && ((c0 = T.get(i)) >= c1));
  668. for(; 0 <= i;) {
  669. do { c1 = c0;
  670. } while((0 <= --i) && ((c0 = T.get(i)) <= c1));
  671. if(0 <= i) {
  672. SA[m + ((i + 1) >> 1)] = j - i;
  673. j = i + 1;
  674. do { c1 = c0;
  675. } while((0 <= --i) && ((c0 = T.get(i)) >= c1));
  676. }
  677. }
  678.  
  679. /* find the lexicographic names of all substrings */
  680. for(i = 0, name = 0, q = n, qlen = 0; i < m; ++i) {
  681. p = SA[i]; plen = SA[m + (p >> 1)]; diff = true;
  682. if((plen == qlen) && ((q + plen) < n)) {
  683. for(j = 0; (j < plen) && (T.get(p + j) == T.get(q + j)); ++j) { }
  684. if(j == plen) { diff = false; }
  685. }
  686. if(diff != false) { ++name; q = p; qlen = plen; }
  687. SA[m + (p >> 1)] = name;
  688. }
  689. //System.out.printf("lmsPost last line name = %dn",name);
  690. return name;
  691. }
  692.  
  693. /* compute SA and BWT */
  694. private static
  695. void
  696. induceSA(BaseArray T, int[] SA, BaseArray C, BaseArray B, int n, int k) {
  697. int b, i, j;
  698. int c0, c1;
  699. System.out.printf("induceSA: n %d k %dn",n,k);
  700. /* compute SAl */
  701. if(C == B) { getCounts(T, C, n, k); }
  702. getBuckets(C, B, k, false); /* find starts of buckets */
  703. j = n - 1;
  704. b = B.get(c1 = T.get(j));
  705. SA[b++] = ((0 < j) && (T.get(j - 1) < c1)) ? ~j : j;
  706. for(i = 0; i < n; ++i) {
  707. j = SA[i]; SA[i] = ~j;
  708. if(0 < j) {
  709. if((c0 = T.get(--j)) != c1) { B.set(c1, b); b = B.get(c1 = c0); }
  710. SA[b++] = ((0 < j) && (T.get(j - 1) < c1)) ? ~j : j;
  711. }
  712. }
  713. /* compute SAs */
  714. if(C == B) { getCounts(T, C, n, k); }
  715. getBuckets(C, B, k, true); /* find ends of buckets */
  716. for(i = n - 1, b = B.get(c1 = 0); 0 <= i; --i) {
  717. if(0 < (j = SA[i])) {
  718. if((c0 = T.get(--j)) != c1) { B.set(c1, b); b = B.get(c1 = c0); }
  719. SA[--b] = ((j == 0) || (T.get(j - 1) > c1)) ? ~j : j;
  720. } else {
  721. SA[i] = ~j;
  722. }
  723. }
  724. }
  725. private static
  726. int
  727. computeBWT(BaseArray T, int[] SA, BaseArray C, BaseArray B, int n, int k) {
  728. int b, i, j, pidx = -1;
  729. int c0, c1;
  730. /* compute SAl */
  731. if(C == B) { getCounts(T, C, n, k); }
  732. getBuckets(C, B, k, false); /* find starts of buckets */
  733. j = n - 1;
  734. b = B.get(c1 = T.get(j));
  735. SA[b++] = ((0 < j) && (T.get(j - 1) < c1)) ? ~j : j;
  736. for(i = 0; i < n; ++i) {
  737. if(0 < (j = SA[i])) {
  738. SA[i] = ~(c0 = T.get(--j));
  739. if(c0 != c1) { B.set(c1, b); b = B.get(c1 = c0); }
  740. SA[b++] = ((0 < j) && (T.get(j - 1) < c1)) ? ~j : j;
  741. } else if(j != 0) {
  742. SA[i] = ~j;
  743. }
  744. }
  745. /* compute SAs */
  746. if(C == B) { getCounts(T, C, n, k); }
  747. getBuckets(C, B, k, true); /* find ends of buckets */
  748. for(i = n - 1, b = B.get(c1 = 0); 0 <= i; --i) {
  749. if(0 < (j = SA[i])) {
  750. SA[i] = (c0 = T.get(--j));
  751. if(c0 != c1) { B.set(c1, b); b = B.get(c1 = c0); }
  752. SA[--b] = ((0 < j) && (T.get(j - 1) > c1)) ? ~((int)T.get(j - 1)) : j;
  753. } else if(j != 0) {
  754. SA[i] = ~j;
  755. } else {
  756. pidx = i;
  757. }
  758. }
  759. return pidx;
  760. }
  761.  
  762. /* find the suffix array SA of T[0..n-1] in {0..k-1}^n
  763. use a working space (excluding T and SA) of at most 2n+O(1) for a constant alphabet
  764. args = new ByteArray(T, 0), SA, 0, n, 256, false
  765. */
  766. private static
  767. int
  768. SA_IS(BaseArray T, int[] SA, int fs, int n, int k, boolean isbwt) {
  769. BaseArray C, B, RA;
  770. int i, j, b, c, m, p, q, name, pidx = 0, newfs;
  771. int c0, c1;
  772. int flags = 0;
  773. System.out.printf("sais: fs %d k %d n %dn",fs,k,n);
  774. if(k <= 256) {
  775. C = new IntArray(new int[k], 0);
  776. System.out.println("ALLOCATE_ARRAY freqTable at "+C.hashCode());
  777. if(k <= fs) {
  778. B = new IntArray(SA, n + fs - k);
  779. System.out.println("ALLOCATE_ARRAY suffixArrayHead at "+B.hashCode());
  780. flags = 1; }
  781. else {
  782. B = new IntArray(new int[k], 0); flags = 3;
  783. System.out.println("ALLOCATE_ARRAY suffixArrayHead at "+B.hashCode());
  784. }
  785. } else if(k <= fs) {
  786. C = new IntArray(SA, n + fs - k);
  787. System.out.println("ALLOCATE_ARRAY freqTable at "+C.hashCode());
  788. if(k <= (fs - k)) { B = new IntArray(SA, n + fs - k * 2);
  789. System.out.println("ALLOCATE_ARRAY suffixArrayHead at "+B.hashCode());
  790. flags = 0; }
  791. else if(k <= 1024) { B = new IntArray(new int[k], 0);
  792. System.out.println("ALLOCATE_ARRAY suffixArrayHead at "+B.hashCode());
  793. flags = 2; }
  794. else { B = C; flags = 8; }
  795. } else {
  796. C = B = new IntArray(new int[k], 0);
  797. flags = 4 | 8;
  798. }
  799.  
  800. /* stage 1: reduce the problem by at least 1/2
  801. sort all the LMS-substrings */
  802. getCounts(T, C, n, k); getBuckets(C, B, k, true); /* find ends of buckets */
  803. for(i = 0; i < n; ++i) { SA[i] = 0; }
  804. b = -1; i = n - 1; j = n; m = 0; c0 = T.get(n - 1);
  805. do { c1 = c0; } while( (0 <= --i) && ((c0 = T.get(i)) >= c1));
  806. for(; 0 <= i;) {
  807. do {
  808. c1 = c0; } while((0 <= --i) && ((c0 = T.get(i)) <= c1));
  809.  
  810. if(0 <= i) {
  811. if(0 <= b) { SA[b] = j; }
  812. b = B.update(c1, -1);
  813. j = i; ++m;
  814. do { c1 = c0; } while((0 <= --i) && ((c0 = T.get(i)) >= c1));
  815. }
  816. }
  817.  
  818. if(1 < m) {
  819. LMSsort(T, SA, C, B, n, k);
  820. name = LMSpostproc(T, SA, n, m);
  821. } else if(m == 1) {
  822. SA[b] = j + 1;
  823. name = 1;
  824. } else {
  825. name = 0;
  826. }
  827.  
  828. // System.out.printf("sais:after m > 1: name %d m %d flags %dn",name,m,flags);
  829.  
  830. /* stage 2: solve the reduced problem
  831. recurse if names are not yet unique */
  832. if(name < m) {
  833. if((flags & 4) != 0) {
  834. System.out.println("Freeing freqTable at "+C.hashCode()+"nFreeing suffixArrayHead at " +B.hashCode());
  835. C = null; B = null;
  836.  
  837. }
  838. if((flags & 2) != 0) {
  839. System.out.println("Freeing suffixArrayHead at " +B.hashCode());
  840. B = null; }
  841. newfs = (n + fs) - (m * 2);
  842. if((flags & (1 | 4 | 8)) == 0) {
  843. if((k + name) <= newfs) { newfs -= k; }
  844. else { flags |= 8; }
  845. }
  846. //mark
  847. for(i = m + (n >> 1) - 1, j = m * 2 + newfs - 1; m <= i; --i) {
  848. if(SA[i] != 0) {
  849. // System.out.printf("sais:before sa j--: i %d j %dn",i,j);
  850. SA[j--] = SA[i] - 1;
  851. // System.out.printf("sais:after sa j--: i %d j %dn",i,j);
  852. }
  853. }
  854. RA = new IntArray(SA, m + newfs);
  855. System.out.println("ALLOCATE_ARRAY RA at "+RA.hashCode());
  856. // printSA("sais:before recurse:new buffer",((IntArray)RA).m_A,n);
  857. System.out.println("Printing new buffer "+((IntArray)RA).m_pos);
  858.  
  859. SA_IS(RA, SA, newfs, m, name, false);
  860. System.out.println("Freeing t_sa at " +RA.hashCode());
  861. RA = null;
  862.  
  863. //printSA("sais:after recurse:suffixArray",SA,n);
  864.  
  865. i = n - 1; j = m * 2 - 1; c0 = T.get(n - 1);
  866. do { c1 = c0; } while((0 <= --i) && ((c0 = T.get(i)) >= c1));
  867. for(; 0 <= i;) {
  868. do { c1 = c0; } while((0 <= --i) && ((c0 = T.get(i)) <= c1));
  869. if(0 <= i) {
  870. SA[j--] = i + 1;
  871. do { c1 = c0; } while((0 <= --i) && ((c0 = T.get(i)) >= c1));
  872. }
  873. }
  874.  
  875. for(i = 0; i < m; ++i) { SA[i] = SA[m + SA[i]]; }
  876. if((flags & 4) != 0) { C = B = new IntArray(new int[k], 0);
  877. System.out.println("ALLOCATE_ARRAY after sais() for freqTable at "+C.hashCode()+" for suffixArrayHead "+B.hashCode());
  878. }
  879. if((flags & 2) != 0) { B = new IntArray(new int[k], 0);
  880. System.out.println("ALLOCATE_ARRAY suffixArrayHead at "+B.hashCode());}
  881. }
  882.  
  883. /* stage 3: induce the result for the original problem */
  884. if((flags & 8) != 0) { getCounts(T, C, n, k); }
  885. /* put all left-most S characters into their buckets */
  886. if(1 < m) {
  887. getBuckets(C, B, k, true); /* find ends of buckets */
  888. i = m - 1; j = n; p = SA[m - 1]; c1 = T.get(p);
  889. do {
  890. q = B.get(c0 = c1);
  891. while(q < j) { SA[--j] = 0; }
  892. do {
  893. SA[--j] = p;
  894. if(--i < 0) { break; }
  895. p = SA[i];
  896. } while((c1 = T.get(p)) == c0);
  897. } while(0 <= i);
  898. while(0 < j) { SA[--j] = 0; }
  899. }
  900. if(isbwt == false) { induceSA(T, SA, C, B, n, k); }
  901. else { pidx = computeBWT(T, SA, C, B, n, k); }
  902. System.out.println("Freeing freqTable at " +C.hashCode()+" suffixArrayHead at "+B.hashCode());
  903. C = null; B = null;
  904.  
  905. return pidx;
  906. }
  907.  
  908. /** Suffixsorting **/
  909. /* byte */
  910. public static
  911. int
  912. suffixsort(byte[] T, int[] SA, int n) {
  913. if((T == null) || (SA == null) || (T.length < n) || (SA.length < n)) { return -1; }
  914. if(n <= 1) { if(n == 1) { SA[0] = 0; } return 0; }
  915. return SA_IS(new ByteArray(T, 0), SA, 0, n, 256, false);
  916. }
  917. /* char */
  918. public static
  919. int
  920. suffixsort(char[] T, int[] SA, int n) {
  921. if((T == null) || (SA == null) || (T.length < n) || (SA.length < n)) { return -1; }
  922. if(n <= 1) { if(n == 1) { SA[0] = 0; } return 0; }
  923. return SA_IS(new CharArray(T, 0), SA, 0, n, 65536, false);
  924. }
  925. /* short */
  926. public static
  927. int
  928. suffixsort(short[] T, int[] SA, int n, int k) {
  929. if((T == null) || (SA == null) ||
  930. (T.length < n) || (SA.length < n) ||
  931. (k <= 0) || (65536 < k)) { return -1; }
  932. if(n <= 1) { if(n == 1) { SA[0] = 0; } return 0; }
  933. return SA_IS(new ShortArray(T, 0), SA, 0, n, k, false);
  934. }
  935. /* int */
  936. public static
  937. int
  938. suffixsort(int[] T, int[] SA, int n, int k) {
  939. if((T == null) || (SA == null) ||
  940. (T.length < n) || (SA.length < n) ||
  941. (k <= 0)) { return -1; }
  942. if(n <= 1) { if(n == 1) { SA[0] = 0; } return 0; }
  943. return SA_IS(new IntArray(T, 0), SA, 0, n, k, false);
  944. }
  945. /* String */
  946. public static
  947. int
  948. suffixsort(String T, int[] SA, int n) {
  949. if((T == null) || (SA == null) ||
  950. (T.length() < n) || (SA.length < n)) { return -1; }
  951. if(n <= 1) { if(n == 1) { SA[0] = 0; } return 0; }
  952. return SA_IS(new StringArray(T, 0), SA, 0, n, 65536, false);
  953. }
  954.  
  955. /** Burrows-Wheeler Transform **/
  956. /* byte */
  957. public static
  958. int
  959. bwtransform(byte[] T, byte[] U, int[] A, int n) {
  960. int i, pidx;
  961. if((T == null) || (U == null) || (A == null) ||
  962. (T.length < n) || (U.length < n) || (A.length < n)) { return -1; }
  963. if(n <= 1) { if(n == 1) { U[0] = T[0]; } return n; }
  964. pidx = SA_IS(new ByteArray(T, 0), A, 0, n, 256, true);
  965. U[0] = T[n - 1];
  966. for(i = 0; i < pidx; ++i) { U[i + 1] = (byte)(A[i] & 0xff); }
  967. for(i += 1; i < n; ++i) { U[i] = (byte)(A[i] & 0xff); }
  968. return pidx + 1;
  969. }
  970. /* char */
  971. public static
  972. int
  973. bwtransform(char[] T, char[] U, int[] A, int n) {
  974. int i, pidx;
  975. if((T == null) || (U == null) || (A == null) ||
  976. (T.length < n) || (U.length < n) || (A.length < n)) { return -1; }
  977. if(n <= 1) { if(n == 1) { U[0] = T[0]; } return n; }
  978. pidx = SA_IS(new CharArray(T, 0), A, 0, n, 65536, true);
  979. U[0] = T[n - 1];
  980. for(i = 0; i < pidx; ++i) { U[i + 1] = (char)(A[i] & 0xffff); }
  981. for(i += 1; i < n; ++i) { U[i] = (char)(A[i] & 0xffff); }
  982. return pidx + 1;
  983. }
  984. /* short */
  985. public static
  986. int
  987. bwtransform(short[] T, short[] U, int[] A, int n, int k) {
  988. int i, pidx;
  989. if((T == null) || (U == null) || (A == null) ||
  990. (T.length < n) || (U.length < n) || (A.length < n) ||
  991. (k <= 0) || (65536 < k)) { return -1; }
  992. if(n <= 1) { if(n == 1) { U[0] = T[0]; } return n; }
  993. pidx = SA_IS(new ShortArray(T, 0), A, 0, n, k, true);
  994. U[0] = T[n - 1];
  995. for(i = 0; i < pidx; ++i) { U[i + 1] = (short)(A[i] & 0xffff); }
  996. for(i += 1; i < n; ++i) { U[i] = (short)(A[i] & 0xffff); }
  997. return pidx + 1;
  998. }
  999. /* int */
  1000. public static
  1001. int
  1002. bwtransform(int[] T, int[] U, int[] A, int n, int k) {
  1003. int i, pidx;
  1004. if((T == null) || (U == null) || (A == null) ||
  1005. (T.length < n) || (U.length < n) || (A.length < n) ||
  1006. (k <= 0)) { return -1; }
  1007. if(n <= 1) { if(n == 1) { U[0] = T[0]; } return n; }
  1008. pidx = SA_IS(new IntArray(T, 0), A, 0, n, k, true);
  1009. U[0] = T[n - 1];
  1010. for(i = 0; i < pidx; ++i) { U[i + 1] = A[i]; }
  1011. for(i += 1; i < n; ++i) { U[i] = A[i]; }
  1012. return pidx + 1;
  1013. }
  1014. }
  1015.  
  1016. [i@localhost lab]$ ./a.out input
  1017. ALLOCATE_ARRAY bufferArray at 0x8f2e50
  1018. sais: fs 0 k 256 n 500
  1019. ALLOCATE_ARRAY freqTable at 0x8f3670
  1020. ALLOCATE_ARRAY suffixArrayHead at 0x8f38a0
  1021. getCounts: n 500 k 256 buffer at 0x8f2e50 freqTable 0x8f3670
  1022. getBuckets: k 256 isFront 0 freqTable at 0x8f3670 suffixArrayHead 0x8f38a0
  1023. lmsSort: n 500 k 256
  1024. getBuckets: k 256 isFront 1 freqTable at 0x8f3670 suffixArrayHead 0x8f38a0
  1025. getBuckets: k 256 isFront 0 freqTable at 0x8f3670 suffixArrayHead 0x8f38a0
  1026. lmsPost: n 500 m 138
  1027. FREE_ARRAY suffixArrayHead at 0x8f38a0
  1028. ALLOCATE_ARRAY t_sa at 0x8f3ad0
  1029. Printing new buffer curr = 362
  1030. sais: fs 224 k 95 n 138
  1031. ALLOCATE_ARRAY freqTable at 0x8f38a0
  1032. ALLOCATE_ARRAY suffixArrayHead at 0x8f3990
  1033. getCounts: n 138 k 95 buffer at 0x8f3ad0 freqTable 0x8f38a0
  1034. getBuckets: k 95 isFront 0 freqTable at 0x8f38a0 suffixArrayHead 0x8f3990
  1035. lmsSort: n 138 k 95
  1036. getBuckets: k 95 isFront 1 freqTable at 0x8f38a0 suffixArrayHead 0x8f3990
  1037. getBuckets: k 95 isFront 0 freqTable at 0x8f38a0 suffixArrayHead 0x8f3990
  1038. lmsPost: n 138 m 50
  1039. getBuckets: k 95 isFront 0 freqTable at 0x8f38a0 suffixArrayHead 0x8f3990
  1040. induceSA: n 138 k 95
  1041. getBuckets: k 95 isFront 1 freqTable at 0x8f38a0 suffixArrayHead 0x8f3990
  1042. getBuckets: k 95 isFront 0 freqTable at 0x8f38a0 suffixArrayHead 0x8f3990
  1043. FREE_ARRAY freqTable at 0x8f38a0
  1044. FREE_ARRAY suffixArrayHead at 0x8f3990
  1045. FREE_ARRAY t_sa at 0x8f3ad0
  1046. ALLOCATE_ARRAY suffixArrayHead at 0x8f3ad0
  1047. getBuckets: k 256 isFront 0 freqTable at 0x8f3670 suffixArrayHead 0x8f3ad0
  1048. induceSA: n 500 k 256
  1049. getBuckets: k 256 isFront 1 freqTable at 0x8f3670 suffixArrayHead 0x8f3ad0
  1050. getBuckets: k 256 isFront 0 freqTable at 0x8f3670 suffixArrayHead 0x8f3ad0
  1051. FREE_ARRAY freqTable at 0x8f3670
  1052. FREE_ARRAY suffixArrayHead at 0x8f3ad0
  1053. Printing suffix array and BWT
  1054.  
  1055. 0 C
  1056. 0 C
  1057. 0 C
  1058. 0 C
  1059. 0 C
  1060. 0 C
  1061. 0 C
  1062. 0 C
  1063. 0 C
  1064. 0 C
  1065. 0 C
  1066. 0 C
  1067. 0 C
  1068. 429 C
  1069. 0 C
  1070. 0 C
  1071. .
  1072. .
  1073. 0 C
  1074. 0 C
  1075. 0 C
  1076. 0 C
  1077. Key is 499
  1078. *** Error in `./a.out': double free or corruption (!prev): 0x00000000008f1a50 ***
  1079. ======= Backtrace: =========
  1080. /lib64/libc.so.6(+0x7925b)[0x7f6cd9ee325b]
  1081. /lib64/libc.so.6(+0x828ea)[0x7f6cd9eec8ea]
  1082. /lib64/libc.so.6(cfree+0x4c)[0x7f6cd9ef031c]
  1083. /lib64/libc.so.6(_IO_setb+0x4b)[0x7f6cd9ee79ab]
  1084. /lib64/libc.so.6(_IO_file_close_it+0xae)[0x7f6cd9ee5a6e]
  1085. /lib64/libc.so.6(fclose+0x1bf)[0x7f6cd9ed877f]
  1086. ./a.out[0x402848]
  1087. /lib64/libc.so.6(__libc_start_main+0xf1)[0x7f6cd9e8a401]
  1088. ./a.out[0x40062a]
  1089. ======= Memory map: ========
  1090. 00400000-00403000 r-xp 00000000 08:08 419785 a.out
  1091. 00602000-00603000 r--p 00002000 08:08 419785 a.out
  1092. 00603000-00604000 rw-p 00003000 08:08 419785 a.out
  1093. 008f1000-00912000 rw-p 00000000 00:00 0 [heap]
  1094. 7f6cd4000000-7f6cd4021000 rw-p 00000000 00:00 0
  1095. 7f6cd4021000-7f6cd8000000 ---p 00000000 00:00 0
  1096. 7f6cd9c53000-7f6cd9c69000 r-xp 00000000 08:08 680007 /usr/lib64/libgcc_s-6.4.1-20170727.so.1
  1097. 7f6cd9c69000-7f6cd9e68000 ---p 00016000 08:08 680007 /usr/lib64/libgcc_s-6.4.1-20170727.so.1
  1098. 7f6cd9e68000-7f6cd9e69000 r--p 00015000 08:08 680007 /usr/lib64/libgcc_s-6.4.1-20170727.so.1
  1099. 7f6cd9e69000-7f6cd9e6a000 rw-p 00016000 08:08 680007 /usr/lib64/libgcc_s-6.4.1-20170727.so.1
  1100. 7f6cd9e6a000-7f6cda027000 r-xp 00000000 08:08 666052 /usr/lib64/libc-2.24.so
  1101. 7f6cda027000-7f6cda226000 ---p 001bd000 08:08 666052 /usr/lib64/libc-2.24.so
  1102. 7f6cda226000-7f6cda22a000 r--p 001bc000 08:08 666052 /usr/lib64/libc-2.24.so
  1103. 7f6cda22a000-7f6cda22c000 rw-p 001c0000 08:08 666052 /usr/lib64/libc-2.24.so
  1104. 7f6cda22c000-7f6cda230000 rw-p 00000000 00:00 0
  1105. 7f6cda230000-7f6cda255000 r-xp 00000000 08:08 665877 /usr/lib64/ld-2.24.so
  1106. 7f6cda43a000-7f6cda43c000 rw-p 00000000 00:00 0
  1107. 7f6cda452000-7f6cda455000 rw-p 00000000 00:00 0
  1108. 7f6cda455000-7f6cda456000 r--p 00025000 08:08 665877 /usr/lib64/ld-2.24.so
  1109. 7f6cda456000-7f6cda457000 rw-p 00026000 08:08 665877 /usr/lib64/ld-2.24.so
  1110. 7f6cda457000-7f6cda458000 rw-p 00000000 00:00 0
  1111. 7ffe93214000-7ffe93235000 rw-p 00000000 00:00 0 [stack]
  1112. 7ffe932f1000-7ffe932f3000 r--p 00000000 00:00 0 [vvar]
  1113. 7ffe932f3000-7ffe932f5000 r-xp 00000000 00:00 0 [vdso]
  1114. ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
  1115. Aborted (core dumped)
  1116.  
  1117. input: 500 bytes ... sais: fs 0 k 256 n 500
  1118. ALLOCATE_ARRAY freqTable at 1550089733
  1119. ALLOCATE_ARRAY suffixArrayHead at 865113938
  1120. getCounts: n 500 k 256
  1121. getBuckets: k 256 front false
  1122. lmsSort: n 500 k 256
  1123. getBuckets: k 256 front true
  1124. getBuckets: k 256 front false
  1125. lmsPost: n 500 m 138
  1126. Freeing suffixArrayHead at 865113938
  1127. ALLOCATE_ARRAY RA at 1442407170
  1128. Printing new buffer 362
  1129. sais: fs 224 k 95 n 138
  1130. ALLOCATE_ARRAY freqTable at 1028566121
  1131. ALLOCATE_ARRAY suffixArrayHead at 1118140819
  1132. getCounts: n 138 k 95
  1133. getBuckets: k 95 front false
  1134. lmsSort: n 138 k 95
  1135. getBuckets: k 95 front true
  1136. getBuckets: k 95 front false
  1137. lmsPost: n 138 m 50
  1138. getBuckets: k 95 front false
  1139. induceSA: n 138 k 95
  1140. getBuckets: k 95 front true
  1141. getBuckets: k 95 front false
  1142. Freeing freqTable at 1028566121 suffixArrayHead at 1118140819
  1143. Freeing t_sa at 1442407170
  1144. ALLOCATE_ARRAY suffixArrayHead at 1975012498
  1145. getBuckets: k 256 front false
  1146. induceSA: n 500 k 256
  1147. getBuckets: k 256 front true
  1148. getBuckets: k 256 front false
  1149. Freeing freqTable at 1550089733 suffixArrayHead at 1975012498
  1150. 0.045 sec
  1151. Printing T and SA
  1152. 105 C
  1153. 317 G
  1154. 337 T
  1155. 298 T
  1156. 403 C
  1157. 213 C
  1158. 324 T
  1159. 423 T
  1160. 26 C
  1161. 106 A
  1162. 109 G
  1163. .
  1164. .
  1165. 29 C
  1166. 371 G
  1167. 378 A
  1168. Key is 41
  1169.  
  1170. sufcheck: Done.
Add Comment
Please, Sign In to add comment