1 /*
2   Copyright (c) 2003 by Stefan Kurtz and The Institute for
3   Genomic Research.  This is OSI Certified Open Source Software.
4   Please see the file LICENSE for licensing information and
5   the file ACKNOWLEDGEMENTS for names of contributors to the
6   code base.
7 */
8 
9 #include <stdio.h>
10 #include <sys/types.h>
11 #include "debugdef.h"
12 #include "types.h"
13 #include "streedef.h"
14 #include "streeacc.h"
15 #include "spacedef.h"
16 #include "protodef.h"
17 
18 #define ADDAMOUNT 128
19 
showdepthtab(ArrayUint * dt)20 void showdepthtab(ArrayUint *dt)
21 {
22   Uint i;
23 
24   for(i=0; i<dt->nextfreeUint; i++)
25   {
26     if(dt->spaceUint[i] > 0)
27     {
28       printf("Depth %lu %lu\n",(Showuint) i,(Showuint) dt->spaceUint[i]);
29     }
30   }
31 }
32 
setdepthtab(ArrayUint * depthtab,Uint depth)33 static void setdepthtab(ArrayUint *depthtab,Uint depth)
34 {
35   Uint i;
36 
37   if(depth >= depthtab->allocatedUint)
38   {
39     depthtab->spaceUint
40       = ALLOCSPACE(depthtab->spaceUint,Uint,depth+ADDAMOUNT);
41     for(i= depthtab->allocatedUint; i<depth+ADDAMOUNT; i++)
42     {
43       depthtab->spaceUint[i] = 0;
44     }
45     depthtab->allocatedUint = depth+ADDAMOUNT;
46   }
47   if(depth + 1 > depthtab->nextfreeUint)
48   {
49     depthtab->nextfreeUint = depth+1;
50   }
51   depthtab->spaceUint[depth]++;
52 }
53 
makedepthtabstree(ArrayUint * depthtab,Suffixtree * stree)54 void makedepthtabstree(ArrayUint *depthtab,Suffixtree *stree)
55 {
56   Uint depth, *btptr, *largeptr, distance;
57   //  Uint headposition;
58 
59   btptr = stree->branchtab;
60   while(btptr < stree->nextfreebranch)
61   {
62     if(ISLARGE(*btptr))
63     {
64       depth = GETDEPTH(btptr);
65       /* headposition = GETHEADPOS(btptr); */
66       setdepthtab(depthtab,depth);
67       btptr += LARGEINTS;
68     } else
69     {
70       distance = GETDISTANCE(btptr);
71       GETCHAINEND(largeptr,btptr,distance);
72       depth = GETDEPTH(largeptr);
73       /* headposition = GETHEADPOS(largeptr); */
74       while(distance > 0)
75       {
76         setdepthtab(depthtab,depth + distance);
77         distance--;
78         btptr += SMALLINTS;
79       }
80       setdepthtab(depthtab,depth);
81       btptr += LARGEINTS;
82     }
83   }
84 }
85