Skip to content

Commit b44ee90

Browse files
committed
minor GVec adjustments
1 parent 490ef38 commit b44ee90

4 files changed

Lines changed: 44 additions & 43 deletions

File tree

gclib/GVec.hh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,10 @@ template <class OBJ> class GVec {
111111
//this will reject identical items in sorted lists only!
112112
void setCapacity(int NewCapacity);
113113
int Count() { return fCount; }
114-
115114
void setCount(int NewCount); // will trim or expand the array as needed
116-
void setCount(int NewCount, OBJ* v); //same as setCount() but new objects are set to v
117115
void setCount(int NewCount, OBJ v);
118116
void Resize(int NewCount) { setCount(NewCount); }
119-
//void Resize(int NewCount, OBJ* v) { setCount(NewCount, v); }
120-
void Resize(int NewCount, OBJ v) { setCount(NewCount, &v); }
117+
void Resize(int NewCount, OBJ v) { setCount(NewCount, v); }
121118

122119
//void Move(int curidx, int newidx);
123120
bool isEmpty() { return fCount==0; }
@@ -290,13 +287,15 @@ template <class OBJ> void GVec<OBJ>::setCapacity(int NewCapacity) {
290287
else {
291288
if (IsPrimitiveType<OBJ>::VAL) {
292289
GREALLOC(fArray, NewCapacity*sizeof(OBJ));
290+
//also zero init the new items?
291+
memset(fArray+fCount, 0, (NewCapacity-fCount)*sizeof(OBJ));
293292
} else {
294293
OBJ* oldArray=fArray;
295294
//fArray=new OBJ[NewCapacity]();
296295
fArray=new OBJ[NewCapacity];
297296
for (int i=0;i<this->fCount;i++) {
298297
fArray[i] = oldArray[i];
299-
}// we need operator= here
298+
}// we need operator= here
300299
//wouldn't be faster to use memcpy instead?
301300
//memcpy(fArray, oldArray, fCount*sizeof(OBJ));
302301
if (oldArray) delete[] oldArray;
@@ -355,16 +354,16 @@ template <class OBJ> void GVec<OBJ>::Grow(int idx, OBJ& item) {
355354
newList[idx]=item;
356355
//copy data after idx
357356
memmove(&newList[idx+1],&fArray[idx], (fCount-idx)*sizeof(OBJ));
358-
//..shouldn't do this:
357+
//..shouldn't do this (zero init new unused items in the array)
359358
memset(&newList[fCount+1], 0, (NewCapacity-fCount-1)*sizeof(OBJ));
360359
//data copied:
361360
GFREE(fArray);
362361
} else {
363-
newList=new OBJ[NewCapacity]; //]()
362+
newList=new OBJ[NewCapacity];
364363
// operator= required!
365364
for (int i=0;i<idx;i++) {
366365
newList[i]=fArray[i];
367-
}
366+
}
368367
newList[idx]=item;
369368
//copy data after idx
370369
//memmove(&newList[idx+1],&fArray[idx], (fCount-idx)*sizeof(OBJ));
@@ -499,9 +498,12 @@ template <class OBJ> void GVec<OBJ>::setCount(int NewCount) {
499498
GError(GVEC_COUNT_ERR, NewCount);
500499
//if (NewCount > fCapacity) setCapacity(NewCount);
501500
while(NewCount > fCapacity) Grow();
501+
if (IsPrimitiveType<OBJ>::VAL && NewCount>fCount) {
502+
memset(fArray+fCount, 0, (NewCount-fCount)*sizeof(OBJ));
503+
}
502504
fCount = NewCount; //new items will be populated by the default object constructor(!)
503505
}
504-
506+
/*
505507
template <class OBJ> void GVec<OBJ>::setCount(int NewCount, OBJ* v) {
506508
if (NewCount<0 || NewCount > MAXLISTSIZE)
507509
GError(GVEC_COUNT_ERR, NewCount);
@@ -512,7 +514,7 @@ template <class OBJ> void GVec<OBJ>::setCount(int NewCount, OBJ* v) {
512514
}
513515
fCount = NewCount;
514516
}
515-
517+
*/
516518
template <class OBJ> void GVec<OBJ>::setCount(int NewCount, OBJ v) {
517519
if (NewCount<0 || NewCount > MAXLISTSIZE)
518520
GError(GVEC_COUNT_ERR, NewCount);
@@ -524,7 +526,6 @@ template <class OBJ> void GVec<OBJ>::setCount(int NewCount, OBJ v) {
524526
fCount = NewCount;
525527
}
526528

527-
528529
template <class OBJ> void GVec<OBJ>::qSort(int l, int r, GCompareProc* cmpFunc) {
529530
int i, j;
530531
OBJ p,t;

rlink.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,7 +3241,7 @@ int create_graph(int refstart,int s,int g,CBundle *bundle,GPVec<CBundlenode>& bn
32413241

32423242
// finished reading bundle -> now create the parents' and children's patterns
32433243
GVec<bool> visit;
3244-
visit.Resize(graphno,false);
3244+
visit.Resize(graphno);
32453245
GBitVec parents(graphno+edgeno);
32463246

32473247
//fprintf(stderr,"traverse graph[%d][%d] now with %d nodes, %d edges and lastgpos=%d....\n",s,g,graphno,edgeno,lastgpos);//edgeno=0;
@@ -5556,7 +5556,7 @@ CPrediction* store_merge_prediction(float cov,GVec<int>& alltr,GPVec<CMTransfrag
55565556

55575557
bool bfs(int n,GVec<float> *capacity,GVec<float> *flow,GVec<int> *link,GVec<int>& pred) {
55585558
GVec<int> color;
5559-
color.Resize(n+2,0);
5559+
color.Resize(n+2);
55605560
int head=0;
55615561
int tail=0;
55625562
GVec<int> q;
@@ -7650,7 +7650,7 @@ void compute_capacity_back(int firstn, CTransfrag *t,float val,GVec<float>& capa
76507650

76517651
bool weight_bfs(int n,GVec<float> *capacity,GVec<float> *flow,GVec<int> *link,GVec<int>& pred) {
76527652
GVec<int> color;
7653-
color.Resize(n,0);
7653+
color.Resize(n);
76547654
int head=0;
76557655
int tail=0;
76567656
GVec<int> q;
@@ -7740,8 +7740,8 @@ float max_flow(int gno,GVec<int>& path,GBitVec& istranscript,GPVec<CTransfrag>&
77407740
for(int i=0;i<n;i++) {
77417741
node2path[path[i]]=i;
77427742
nodecapacity.cAdd(0.0);
7743-
capacity[i].Resize(n,0);
7744-
flow[i].Resize(n,0);
7743+
capacity[i].Resize(n);
7744+
flow[i].Resize(n);
77457745
}
77467746

77477747
// establish capacities in the network
@@ -7897,8 +7897,8 @@ float long_max_flow(int gno,GVec<int>& path,GBitVec& istranscript,GPVec<CTransfr
78977897
node2path[path[i]]=i;
78987898
nodecapacity.cAdd(0.0);
78997899
noderate.cAdd(1.0); // I set up all rates to be 1 for now
7900-
capacity[i].Resize(n,0);
7901-
flow[i].Resize(n,0);
7900+
capacity[i].Resize(n);
7901+
flow[i].Resize(n);
79027902
}
79037903

79047904
float max_fl=0;
@@ -8062,12 +8062,12 @@ float push_max_flow(int gno,GVec<int>& path,GBitVec& istranscript,GPVec<CTransfr
80628062
}
80638063
GVec<float> capacityleft; // how many transcripts compatible to path enter node
80648064
GVec<float> capacityright; // how many transcripts compatible to path exit node
8065-
capacityleft.Resize(n,0);
8066-
capacityright.Resize(n,0);
8065+
capacityleft.Resize(n);
8066+
capacityright.Resize(n);
80678067
GVec<float> sumleft; // how many transcripts enter node
80688068
GVec<float> sumright; // how many transcripts exit node
8069-
sumleft.Resize(n,0);
8070-
sumright.Resize(n,0);
8069+
sumleft.Resize(n);
8070+
sumright.Resize(n);
80718071

80728072
//bool full=true;
80738073
//if(longreads && path.Count()>3) full=false;
@@ -8362,12 +8362,12 @@ float push_guide_maxflow(int gno,GVec<int>& path,GBitVec& istranscript,GPVec<CTr
83628362
}
83638363
GVec<float> capacityleft; // how many transcripts compatible to path enter node
83648364
GVec<float> capacityright; // how many transcripts compatible to path exit node
8365-
capacityleft.Resize(n,0);
8366-
capacityright.Resize(n,0);
8365+
capacityleft.Resize(n);
8366+
capacityright.Resize(n);
83678367
GVec<float> sumleft; // how many transcripts enter node
83688368
GVec<float> sumright; // how many transcripts exit node
8369-
sumleft.Resize(n,0);
8370-
sumright.Resize(n,0);
8369+
sumleft.Resize(n);
8370+
sumright.Resize(n);
83718371

83728372
/*
83738373
{ // DEBUG ONLY
@@ -8609,8 +8609,8 @@ float guideflow(int gno,GVec<int>& path,GBitVec& istranscript,GPVec<CTransfrag>&
86098609
for(int i=0;i<n;i++) {
86108610
//fprintf(stderr,"%d ",path[i]);
86118611
node2path[path[i]]=i;
8612-
capacity[i].Resize(n,0);
8613-
flow[i].Resize(n,0);
8612+
capacity[i].Resize(n);
8613+
flow[i].Resize(n);
86148614
}
86158615

86168616
//fprintf(stderr,"n=%d ",n);
@@ -8708,12 +8708,12 @@ float guidepushflow(int g,GVec<CGuide>& guidetrf,int gno,GBitVec& istranscript,G
87088708

87098709
GVec<float> capacityleft; // how many transcripts compatible to path enter node
87108710
GVec<float> capacityright; // how many transcripts compatible to path exit node
8711-
capacityleft.Resize(n,0);
8712-
capacityright.Resize(n,0);
8711+
capacityleft.Resize(n);
8712+
capacityright.Resize(n);
87138713
GVec<float> sumleft; // how many transcripts enter node
87148714
GVec<float> sumright; // how many transcripts exit node
8715-
sumleft.Resize(n,0);
8716-
sumright.Resize(n,0);
8715+
sumleft.Resize(n);
8716+
sumright.Resize(n);
87178717

87188718
// compute capacities and sums for all nodes
87198719
for(int i=1;i<n-1;i++) {
@@ -8874,13 +8874,13 @@ float max_flow_EM(int gno,GVec<int>& path,GBitVec& istranscript,GPVec<CTransfrag
88748874
*/
88758875

88768876
GVec<float> through; // these are the capacity of the "trough" transfrags through each node in the path
8877-
through.Resize(n,0);
8877+
through.Resize(n);
88788878

88798879
for(int i=0;i<m;i++) {
88808880
if(i<n) node2path[path[i]]=i;
88818881
if(i<n) nodecapacity.cAdd(0.0);
8882-
capacity[i].Resize(m,0);
8883-
flow[i].Resize(m,0);
8882+
capacity[i].Resize(m);
8883+
flow[i].Resize(m);
88848884
}
88858885

88868886
// establish capacities in the network
@@ -9034,7 +9034,7 @@ float max_flow_EM(int gno,GVec<int>& path,GBitVec& istranscript,GPVec<CTransfrag
90349034
if(doEM) // reset flow to 0
90359035
for(int i=0;i<m;i++) {
90369036
flow[i].Clear();
9037-
flow[i].Resize(m,0);
9037+
flow[i].Resize(m);
90389038
}
90399039

90409040
iterations++;
@@ -9096,8 +9096,8 @@ float weight_max_flow(int gno,GVec<int>& path,GBitVec& istranscript,GPVec<CTrans
90969096
for(int i=0;i<n;i++) {
90979097
node2path[path[i]]=i;
90989098
nodecapacity.cAdd(0.0);
9099-
capacity[i].Resize(n,0);
9100-
flow[i].Resize(n,0);
9099+
capacity[i].Resize(n);
9100+
flow[i].Resize(n);
91019101
rate[i].Resize(n,1);
91029102
}
91039103

@@ -14136,7 +14136,7 @@ void count_good_junctions(BundleData* bdata) {
1413614136
gjunc.Clear();
1413714137
}
1413814138

14139-
for(int s=0;s<3;s++) bpcov[s].Resize(refend-refstart+3, 0);
14139+
for(int s=0;s<3;s++) bpcov[s].Resize(refend-refstart+3);
1414014140

1414114141
GVec<int> unstranded; // remembers unstranded reads
1414214142

@@ -14958,7 +14958,7 @@ int print_predcluster(GList<CPrediction>& pred,int geneno,GStr& refname,
1495814958

1495914959
int npred=pred.Count();
1496014960
GVec<bool> overlap;
14961-
overlap.Resize(npred*npred-npred,false);
14961+
overlap.Resize(npred*npred-npred);
1496214962

1496314963
GVec<CPred> predord;
1496414964
//CPred p(0,pred[0]->cov);

rlink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ struct BundleData {
659659
refseq(), gseq(NULL), readlist(false,true), //bpcov(1024),
660660
junction(true, true, true),
661661
keepguides(false), ptfs(false), pred(false), rc_data(NULL) {
662-
for(int i=0;i<3;i++) bpcov[i].setCapacity(1024);
662+
for(int i=0;i<3;i++) bpcov[i].setCapacity(4096);
663663
}
664664

665665
void getReady(int currentstart, int currentend) {

stringtie.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ int main(int argc, char* argv[]) {
292292
GPVec<RC_Feature> guides_RC_exons(true); //raw count data for all guide exons
293293
GPVec<RC_Feature> guides_RC_introns(true);//raw count data for all guide introns
294294

295-
GVec<int> alncounts(30,0); //keep track of the number of read alignments per chromosome [gseq_id]
295+
GVec<int> alncounts(30); //keep track of the number of read alignments per chromosome [gseq_id]
296296

297297
int bamcount=bamreader.start(); //setup and open input files
298298
#ifndef GFF_DEBUG
@@ -523,7 +523,7 @@ if (tstackSize<DEF_TSTACK_SIZE) defStackSize=DEF_TSTACK_SIZE;
523523
}
524524

525525
if (alncounts.Count()<=gseq_id) {
526-
alncounts.Resize(gseq_id+1, 0);
526+
alncounts.Resize(gseq_id+1);
527527
}
528528
else if (alncounts[gseq_id]>0)
529529
GError("%s\nAlignments (%d) already found for %s !\n",

0 commit comments

Comments
 (0)