C++ main module for mmsd Package  1.0
CORE_Array.hpp
Go to the documentation of this file.
1 #ifndef CORE_Array_CPP
2 #define CORE_Array_CPP
3 
4 #include <CORE_Array.h>
5 #include <vector>
6 #include "CORE_Integer.h"
7 #include "CORE_String.h"
8 #include "CORE_Vector.h"
9 #include "CORE_Exception.h"
10 
11 using namespace std;
12 
13 
14 
15 template<class T>
17  mStartIndex=0;
18  mSize=n;
19  mCapacity=n;
20  mCapacityFactor=1;
21  mVector=new T[mCapacity];
22  mCVector=mVector;
23  if (mVector==null)
24  throw CORE_Exception("common/core",
25  "impossible to allocate memory of size "+CORE_Integer::toString(mCapacity),
26  "CORE_Array.hpp",21,"constructor(...)");
27  mHasToBeDeleted=true;
28 
29  //cout << "create an empty array to "<<getIdentityString()<<"\n";
30 }
31 template<class T>
33  mSize=0;
34  mStartIndex=0;
35  mCapacity=10;
36  mCapacityFactor=1;
37  mVector=new T[mCapacity];
38  mCVector=mVector;
39  mHasToBeDeleted=true;
40  if (mVector==null)
41  throw CORE_Exception("common/core",
42  "impossible to allocate memory of size "+CORE_Integer::toString(mCapacity),
43  "CORE_Array.hpp",34,"constructor(...)");
44 
45  //cout << "create an empty array to "<<getIdentityString()<<"\n";
46 }
47 template<class T >
48 template<class Q>
49 CORE_Array<T>::CORE_Array(const std::vector<Q>& values):CORE_List() {
50  mSize=values.size();
51  mStartIndex=0;
52  mCapacity=mSize;
53  mCapacityFactor=1;
54  mVector=new T[mCapacity];
55  mCVector=mVector;
56  mHasToBeDeleted=true;
57  if (mVector==null) throw CORE_Exception("common/core",
58  "impossible to allocate memory of size "+CORE_Integer::toString(mCapacity),
59  "CORE_Array.hpp",48,"constructor(...)");
60  for (tArrayIndex i=0;i<mSize;i++) mVector[i]=(T) values[i];
61  //cout << "create an empty array to "<<getIdentityString()<<"\n";
62 }
63 
64 template<class T>
66  clear();
67  if ((mVector!=null) && (mHasToBeDeleted)) delete[] mVector;
68 
69 }
70 
71 template<class T>
73  tArrayIndex cap=v.getCapacity();
74  tArrayIndex s=0;
75  setValues(cap,v.getCompleteValues(s),0);
76  mSize=v.getSize();
77  mStartIndex=v.getStartIndex();
78  mCapacityFactor=v.getCapacityFactor();
79  mCVector=&mVector[mStartIndex];
80 }
81 
82 
83 template<class T>
85  if (dim>=tArrayIndexMax)
86  throw CORE_Exception("common/core","CORE_Array::setCapacity","capacity too big !"+CORE_Integer::toString(dim));
87 
88  //capacity is ok
89  if (dim==mCapacity) return;
90 
91  // create a new array
92  T *newVector=new T[dim];
93  if (newVector==null)
94  throw CORE_Exception("common/core","impossible to allocate memory of size "+CORE_Integer::toString(dim),"CORE_Array.hpp",81,"setCapacity(cont& int&)");
95 
96  // copy the old value
97  // last index of the usefull value
98  tArrayIndex p=mSize+mStartIndex;
99  tArrayIndex i,n=(p<dim)?p:dim;
100  // copy all the values [0,p]
101  for (i=0;i<n;i++) newVector[i]=mVector[i];
102 
103  // free memory
104  if ((mVector!=null) && (mHasToBeDeleted)) delete[] mVector;
105 
106  // affect the new allocated vector
107  mVector=newVector;
108  mCVector=&mVector[mStartIndex];
109 
110  // set the memeory allocation of the new vector
111  mCapacity=dim;
112 }
113 
114 template<class T>
116  if ((mSize==mCapacity) && (mStartIndex==0)) return;
117  if (mSize>=tArrayIndexMax)throw CORE_Exception("common/core","CORE_Array::resize","capacity too big !"+CORE_Integer::toString(mSize));
118  T *newVector=new T[mSize];
119  if (newVector==null) throw CORE_Exception("common/core","impossible to allocate memory of size "+CORE_Integer::toString(mSize),"CORE_Array.hpp",107,"resize()");
120  for (tArrayIndex i=0;i<mSize;i++)
121  newVector[i]=mCVector[i];
122  if ((mVector!=null) && (mHasToBeDeleted)) delete[] mVector;
123  mVector=newVector;
124  mCVector=mVector;
125  mCapacity=mSize;
126  mStartIndex=0;
127 }
128 
129 template<class T>
131  if ((n==mCapacity) && (mStartIndex==0)) {
132  mSize=n;
133  return;
134  }
135  if ((n>=tArrayIndexMax)|| (n<0)) throw CORE_Exception("common/core","CORE_Array::resize","capacity too big !"+CORE_Integer::toString(n));
136  T *newVector=new T[n];
137  if (newVector==null) throw CORE_Exception("common/core","impossible to allocate memory of size "+CORE_Integer::toString(n),"CORE_Array.hpp",124,"resize(const int&)");
138  for (tArrayIndex i=0;i<n;i++)
139  newVector[i]=mCVector[i];
140  if ((mVector!=null) && (mHasToBeDeleted)) delete[] mVector;
141  mVector=newVector;
142  mCVector=mVector;
143  mSize=n;
144  mCapacity=n;
145  mStartIndex=0;
146 
147 }
148 template<class T>
150  // the size is ok
151  if (mSize==n) return;
152  // compute the capacacity needed by the array (the size value is from the start index)
153  tArrayIndex dim=mStartIndex+n;
154  // set the size
155  if (dim<=mCapacity) mSize=n;
156  else {
157  // update the capacity
158  setCapacity(dim);
159  // set the size
160  mSize=n;
161  }
162 }
163 
164 template<class T>
165 void CORE_Array<T>::add(const T& obj) {
166  tArrayIndex i,dim=mSize+mStartIndex;
167  if (mCapacity<=dim) {
168  mCapacity=mStartIndex+(mSize+1)*mCapacityFactor;
169  if (mCapacity>=tArrayIndexMax)
170  throw CORE_Exception("common/core",
171  "CORE_Array::resize","capacity too big !"+CORE_Integer::toString(mCapacity));
172  T *newVector=new T[mCapacity];
173  if (newVector==null)
174  throw CORE_Exception("common/core",
175  "impossible to allocate memory of size "+CORE_Integer::toString(mCapacity),
176  "CORE_Array.hpp",157,"add(const T&)");
177 
178  for (i=0;i<dim;i++) newVector[i]=mVector[i];
179  if ((mVector!=null) && (mHasToBeDeleted)) delete[] mVector;
180  mVector=newVector;
181  mCVector=&mVector[mStartIndex];
182  }
183  mVector[dim]=obj;
184  mSize++;
185 }
186 
187 template<class T>
188 void CORE_Array<T>::setValues(const tString& v,const tArrayIndex& fromIndex) {
189 
190  if ((v[0]!='[') && (v[0]!='(')) return;
191  SP::CORE_String str=CORE_String::New(v.substr(1,v.length()-2));
192  str->tokenize(",");
193  str->begin();
194  unsigned int n=str->getTokensCount();
195  unsigned int newDim=n+fromIndex;
196  // verify the capacity is sufficent
197  if (newDim>mCapacity) setCapacity(newDim);
198 
199  // set the start index
200  setStartIndex(fromIndex);
201 
202  // set the size
203  setSize(n);
204 
205  T value;
206  unsigned int k=0;
207  while (str->hasNextToken()) {
208  CORE_String::parse(str->nextToken(),value);
209  mCVector[k]=value;
210  k++;
211  }
212 }
213 template<class T>
215  const tArrayIndex& fromIndex) {
216 
217  // size of the array to copy
218  tArrayIndex i,narray=array.getSize();
219 
220  // new dimension of the array
221  tArrayIndex newDim=narray+fromIndex;
222 
223  // verify if the capacity is sufficent
224  if (newDim>mCapacity) setCapacity(newDim);
225 
226  // set the start index
227  setStartIndex(fromIndex);
228 
229  // set the size
230  setSize(narray);
231 
232  // copy the array
233  for (i=0;i<narray;i++) mCVector[i]=array[i];
234 }
235 
236 template<class T>
237 void CORE_Array<T>::setValues(const tArrayIndex& n,const T* values,const tArrayIndex& fromIndex) {
238  tArrayIndex i,narray=n;
239  tArrayIndex newDim=narray+fromIndex;
240 
241  // verify the capacity is sufficent
242  if (newDim>mCapacity) setCapacity(newDim);
243 
244  // set the start index
245  setStartIndex(fromIndex);
246 
247  // set the size
248  setSize(narray);
249 
250  // copy the array
251  for (i=0;i<narray;i++) mCVector[i]=values[i];
252 }
253 template<class T>
254 void CORE_Array<T>::setValues(const vector<T>& values,const tArrayIndex& fromIndex) {
255  tArrayIndex i,narray=values.size();
256  tArrayIndex newDim=narray+fromIndex;
257 
258  // verify the capacity is sufficent
259  if (newDim>mCapacity) setCapacity(newDim);
260 
261  // set the start index
262  setStartIndex(fromIndex);
263 
264  // set the size
265  setSize(narray);
266 
267  // copy the array
268  for (i=0;i<narray;i++) mCVector[i]=values[i];
269 }
270 
271 
272 template<class T>
274 
275  tBoolean hasExisted=false;
276  tArrayIndex k=0;
277  T val;
278  for (tArrayIndex i=0;i<mSize;i++) {
279  val=mCVector[i];
280  if (val!=obj) {
281  mCVector[k]=val;
282  k++;
283  }
284  }
285  hasExisted=(mSize!=k);
286  mSize=k;
287  return hasExisted;
288 }
289 
290 template<class T>
292  if (index>=size()) return false;
293  if (index<0) return false;
294  tArrayIndex i,n=mSize;
295  if (n==0) return false;
296 
297  for (i=index-1;i<n;i++)
298  mCVector[i]=mCVector[i+1];
299 
300  mSize--;
301  return true;
302 }
303 template<class T>
305  if (n>=mSize) return;
306  mCapacity=n+mStartIndex;
307  if (mCapacity>=tArrayIndexMax) throw CORE_Exception("common/core","CORE_Array::contractToLastElement(const int& n)","capacity too big !"+CORE_Integer::toString(mCapacity));
308  T *newVector=new T[mCapacity];
309  if (newVector==null) throw CORE_Exception("common/core","impossible to allocate memory of size "+CORE_Integer::toString(mCapacity),"CORE_Array.hpp",287,"contractToLastElement(const int&)");
310 
311  tArrayIndex i,k=mSize-1+mStartIndex;
312  for (i=mCapacity;i>0;) {
313  i--;
314  newVector[i]=mVector[k];
315  k--;
316  }
317  mSize=n;
318  if ((mVector!=null) && (mHasToBeDeleted)) delete[] mVector;
319  mVector=newVector;
320  mCVector=&mVector[mStartIndex];
321 }
322 
323 template<class T>
324 tArrayIndex CORE_Array<T>::insert(const tArrayIndex& index,const T& obj) {
325  tArrayIndex i,dim=mSize+mStartIndex;
326  if (dim<mCapacity) {
327  for (i=mSize;i>index;i--)
328  mCVector[i]=mCVector[i-1];
329  mCVector[index]=obj;
330 
331  } else {
332  tArrayIndex i,n=index+mStartIndex;
333  mCapacity+=mCapacityFactor*mSize;
334  if (mCapacity>=tArrayIndexMax) throw CORE_Exception("common/core","CORE_Array::insert(const int& index,const T& obj)","capacity too big !"+CORE_Integer::toString(mCapacity));
335  T *newVector=new T[mCapacity];
336  if (newVector==null) throw CORE_Exception("common/core","impossible to allocate memory of size "+CORE_Integer::toString(mCapacity),"CORE_Array.hpp",312,"insert(const int&,const T&)");
337 
338  // copy the vector from [0,index+mStartIndex[
339  for (i=0;i<n;i++) newVector[i]=mVector[i];
340  // insert the obj at index
341  newVector[n]=obj;
342  // copy the vector from [index+mStartIndex,dim]
343  for (i=n+1;i<=dim;i++)
344  newVector[i]=mVector[i-1];
345  if ((mVector!=null) && (mHasToBeDeleted)) delete[] mVector;
346  mVector=newVector;
347  mCVector=&mVector[mStartIndex];
348  }
349  mSize++;
350  return index;
351 }
352 template<class T>
354  const tBoolean& evenIfEqual) {
355  tArrayIndex si=0;
356  tArrayIndex sf=mSize;
357  if (sf==0) {
358  add(obj);
359  return 0;
360  }
361 
362  sf--;
363 
364  if (obj<mCVector[0]) {
365  insert(0,obj);
366  return 0;
367  } else if (obj==mCVector[0]) {
368  if (evenIfEqual) return insert(0,obj);
369  else return 0;
370  }
371 
372  if (obj>mCVector[sf]) {
373  add(obj);
374  return mSize;
375  } else if (obj==mCVector[sf]) {
376  if (evenIfEqual) return insert(mSize-1,obj);
377  return mSize-1;
378  };
379 
380  tArrayIndex i=0;
381  while (sf-si>1) {
382  i=(si+sf)/2;
383  if (obj>mCVector[i]) si=i;
384  else if (obj==mCVector[i]) {
385  if (evenIfEqual) return insert(i,obj);
386  return i;
387  }
388  else sf=i;
389  }
390 
391  if (obj==mCVector[sf]) {
392  if (evenIfEqual) return insert(sf,obj);
393  return sf;
394  }
395  if (obj==mCVector[si]) {
396  if (evenIfEqual) return insert(si,obj);
397  return si;
398  }
399  return insert(sf,obj);
400 }
401 
402 
403 template<class T>
404 tBoolean CORE_Array<T>::getIndex(const T& obj,tArrayIndex& index) const {
405  index=0;
406  tArrayIndex si=0;
407  tArrayIndex sf=mSize;
408  if (sf==0) {
409  return false;
410  }
411  sf--;
412 
413  if (obj<mCVector[si]) {
414  return false;
415  }
416  if (obj>mCVector[sf]) {
417  return false;
418  }
419  tArrayIndex i=0;
420  while (sf-si>1) {
421  i=(si+sf)/2;
422  if (obj>mCVector[i]) si=i;
423  else if (obj==mCVector[i]) {
424  index=i;
425  return true;
426  }
427  else sf=i;
428  }
429  if (mCVector[sf]==obj) {
430  index=sf;
431  return true;
432  }
433  if (mCVector[si]==obj) {
434  index=si;
435  return true;
436  }
437  return false;
438 }
439 
440 template<class T>
441 tBoolean CORE_Array<T>::getInfIndex(const T& obj,tArrayIndex& index) const {
442  index=0;
443  tArrayIndex si=0;
444  tArrayIndex sf=mSize;
445  if (sf==0) {
446  return false;
447  }
448  sf--;
449 
450  if (obj<mCVector[si]) {
451  return false;
452  }
453  if (obj==mCVector[si]) {
454  return true;
455  }
456  if (obj>=mCVector[sf]) {
457  index=sf;
458  return true;
459  }
460  tArrayIndex k,i=0;
461  while (sf-si>1) {
462  i=(si+sf)/2;
463  if (obj>mCVector[i]) si=i;
464  else if (obj==mCVector[i]) {
465  // possibility of egality
466  for (k=i;k>0;) {
467  k--;
468  if (obj!=mCVector[k]) {
469  index=k+1;
470  return true;
471  }
472  }
473  index=sf;
474  return true;
475  }
476  else sf=i;
477  }
478  if (mCVector[sf]==obj) {
479  for (k=sf;k>0;) {
480  k--;
481  if (obj!=mCVector[k]) {
482  index=k+1;
483  return true;
484  }
485  }
486  index=sf;
487  return true;
488  }
489  if (mCVector[si]==obj) {
490  for (k=si;k>0;) {
491  k--;
492  if (obj!=mCVector[k]) {
493  index=k+1;
494  return true;
495  }
496  }
497  index=si;
498  return true;
499  }
500 
501  for (k=si;k>0;) {
502  k--;
503  if (obj!=mCVector[k]) {
504  index=k+1;
505  return true;
506  }
507  }
508  index=si;
509  return true;
510 }
511 
512 template<class T>
513 tBoolean CORE_Array<T>::getSupIndex(const T& obj,tArrayIndex& index) const {
514  tArrayIndex k,n=mSize;
515  tArrayIndex si=0;
516  tArrayIndex sf=n;
517  index=0;
518  if (sf==0) {
519  return false;
520  }
521  sf--;
522 
523  if (obj<mCVector[0]) {
524  return false;
525  }
526  if (obj==mCVector[0]) {
527  for (k=1;k<n;k++) {
528  if (obj!=mCVector[k]) {
529  index=k-1;
530  return true;
531  }
532  }
533  return true;
534  }
535 
536  if (obj>=mCVector[sf]) {
537  index=sf;
538  return true;
539  }
540  tArrayIndex i=0;
541  while (sf-si>1) {
542  i=(si+sf)/2;
543  if (obj>mCVector[i]) si=i;
544  else if (obj==mCVector[i]) {
545  // possibility of egality
546  for (k=i+1;k<n;k++) {
547  if (obj!=mCVector[k]) {
548  index=k-1;
549  return true;
550  }
551  }
552  index=sf;
553  return true;
554  }
555  else sf=i;
556  }
557 
558  if (mCVector[sf]==obj) {
559  for (k=sf+1;k<n;k++) {
560  if (obj!=mCVector[k]) {
561  index=k-1;
562  return true;
563  }
564  }
565  index=sf;
566  return true;
567  }
568  if (mCVector[si]==obj) {
569  for (k=si+1;k<n;k++) {
570  if (obj!=mCVector[k]) {
571  index=k-1;
572  return true;
573  }
574  }
575  index=si;
576  return true;
577  }
578  for (k=sf+1;k<n;k++) {
579  if (obj!=mCVector[k]) {
580  index=k-1;
581  return true;
582  }
583  }
584  index=sf;
585  return true;
586 }
587 
588 template<class T>
590  T old;
591  if (mSize==0) return;
592 
593  tArrayIndex i,mid=mSize/2;
594  tArrayIndex j=mSize-1;
595  for (i=0;i<mid;i++) {
596  old=mCVector[i];
597  mCVector[i]=mCVector[j];
598  mCVector[j]=old;
599  j--;
600  }
601 }
602 
603 template<class T>
605  // size of array to merge
606  tArrayIndex n=array.getSize();
607 
608  // size of this array after merging
609  tArrayIndex i,k,newSize=mSize+n;
610  tArrayIndex newDim=mStartIndex+newSize;
611 
612  if (newDim<mCapacity) {
613  tArrayIndex k=0;
614  for (i=mSize;i<newSize;i++) {
615  mCVector[i]=array[k];
616  k++;
617  }
618  } else {
619  // increase capacity
620  mCapacity=mStartIndex+newSize*mCapacityFactor;
621  if (mCapacity>=tArrayIndexMax)
622  throw CORE_Exception("common/core",
623  "CORE_Array::merge(const CORE_Array<T>& obj)",
624  "capacity too big !"+CORE_Integer::toString(mCapacity));
625  T *newVector=new T[mCapacity];
626  if (newVector==null)
627  throw CORE_Exception("common/core",
628  "impossible to allocate memory of size "+CORE_Integer::toString(mCapacity),
629  "CORE_Array.hpp",517,"merge(const CORE_Array<T>&)");
630 
631  // copy the this vector
632  for (i=mStartIndex+mSize;i>0;) {
633  i--;
634  newVector[i]=mVector[i];
635  }
636  // add the array
637  k=0;
638  for (i=mStartIndex+mSize;i<newDim;i++) {
639  newVector[i]=array[k];
640  k++;
641  }
642 
643  if ((mVector!=null) && (mHasToBeDeleted)) delete[] mVector;
644  mVector=newVector;
645  mCVector=&mVector[mStartIndex];
646  }
647  mSize=newSize;
648 }
649 
650 template<class T>
652  tString str("");
653  tArrayIndex i,dim=mSize;
654  str+="size:"+CORE_Integer::toString(mSize)+"\n";
655  for (i=0;i<dim;i++) {
656  str+=CORE_Integer::toString(i)+":";
657  str+=CORE_String::toString(mCVector[i]);
658  str+="\t";
659 
660 
661  }
662  return str;
663 }
664 template<class T>
665 void CORE_Array<T>::addAfterIndex(const tArrayIndex& index,const T& v) {
666  tArrayIndex i,dim=mSize+1;
667  setSize(dim);
668  for (i=dim-1;i>index+1;i--) {
669  mCVector[i]=mCVector[i-1];
670  }
671  mCVector[index+1]=v;
672 }
673 
674 template<class T>
677 
678  tArrayIndex nIndices=indices.getSize();
679  tArrayIndex i,nValues=values.getSize();
680  tArrayIndex nValuesToAdd=0;
681  for (i=0;i<nValues;i++)
682  nValuesToAdd+=values[i]->getSize();
683 
684  // resize the new dimension
685  tArrayIndex dim=mStartIndex+mSize+nValuesToAdd;
686  if (dim>=tArrayIndexMax)
687  throw CORE_Exception("common/core",
688  "CORE_Array::addAfterIndices(...)",
689  "capacity too big !"+CORE_Integer::toString(dim));
690  T* newValues=new T[dim];
691  if (newValues==null)
692  throw CORE_Exception("common/core",
693  "impossible to allocate memory of size "+CORE_Integer::toString(dim),
694  "CORE_Array.hpp",571,"addAfterIndices(...)");
695  // set the current cursors
696  long long int cur_newValues=dim-1;
697  long long int cur_indices=nIndices-1;
698  long long int cur_mVector=mStartIndex+mSize-1;
699  long long int j;
700  long long int insertIndex=-1;
701  while (cur_indices>-1) {
702  insertIndex=indices[cur_indices]+mStartIndex;
703  //cout << "insert index:"<< insertIndex<<"\n";
704  // copy the values of mVector in newValues
705  //cout << "copy the values from "<<cur_mVector<<" to "<<(insertIndex+1)<<"\n";
706  for (j=cur_mVector;j>insertIndex;j--) {
707  newValues[cur_newValues]=mVector[j];
708  //cout << "newValues["<<cur_newValues<<"]="<<mVector[i]<<"\n";
709  cur_newValues--;
710  }
711  cur_mVector=insertIndex;
712 
713  // insert the new values
714  //cout << "insert the new values \n";
715  CORE_Array<T> &vals=*values[cur_indices].get();
716  tArrayIndex nVals=vals.getSize();
717  for (j=nVals-1;j>=0;j--) {
718  newValues[cur_newValues]=vals[j];
719  //cout << "newValues["<<cur_newValues<<"]="<<vals[i]<<"\n";
720  cur_newValues--;
721  }
722 
723  // insert at new index
724  cur_indices--;
725  }
726 
727  // copy the last values
728  //cout << "copy the last values from "<<cur_mVector<<" to 0 \n";
729  for (j=cur_mVector;j>=(long long int)mStartIndex;j--) {
730  newValues[cur_newValues]=mVector[j];
731  //cout << "newValues["<<cur_newValues<<"]="<<mVector[i]<<"\n";
732  cur_newValues--;
733  }
734 
735  // set the new dimension
736  mCapacity=dim;
737  mSize=dim-mStartIndex;
738 
739  // free memories
740  if ((mVector!=null) && (mHasToBeDeleted)) delete[] mVector;
741  mVector=newValues;
742  mCVector=&mVector[mStartIndex];
743 
744 }
745 
748 template<class T>
749 void CORE_Array<T>::sort(T*& items,const tArrayIndex& N,
750  const tString& order) {
751 
752  tArrayIndex h=1;
753  tArrayIndex i,j;
754  T v;
755  do h=3*h+1;
756  while (h<=N);
757  do {
758  h/=3;
759  for (i=h;i<N;++i) {
760  if (compare(items[i],
761  items[i-h],
762  order)) {
763  v=items[i];
764  j=i;
765  do {
766  items[j]=items[j-h];
767  j=j-h;
768  }
769  while ((j>=h) && (!compare(items[j-h],
770  v,
771  order)));
772  items[j]=v;
773  }
774  }
775  }
776  while (h>1);
777 }
778 
779 template<class T>
780 tBoolean CORE_Array<T>::search(const T* values,const tArrayIndex& n,
781  const T& obj,
782  const tString& order,
783  tArrayIndex& index){
784 
785  int si=0;
786  int sf=n;
787  index=0;
788  if (sf==0) {
789  return false;
790  }
791  sf--;
792 
793  // min
794  if (compare(obj,values[0],order)) {
795  return false;
796  }
797 
798  // max
799  if (compare(values[sf],obj,order)) {
800  return false;
801  }
802 
803  //eq
804  if (compare(values[0],obj,"=")) {
805  return true;
806  }
807  if (compare(values[sf],obj,"=")) {
808  index=sf;
809  return true;
810  }
811 
812 
813 
814  int i=0;
815  while (sf-si>1) {
816  i=(si+sf)/2;
817  if (compare(values[i],obj,"=")) {
818  index=i;
819  return true;
820  } else if (compare(values[i],obj,order)) {
821  si=i;
822  }
823  else sf=i;
824  }
825  if (compare(obj,values[sf],"=")) {
826  index=sf;
827  return true;
828  }
829  if (compare(obj,values[si],"=")) {
830  index=si;
831  return true;
832  }
833  return false;
834 }
835 
836 #endif
const T * getCompleteValues(tArrayIndex &s) const
get the values of the complete vector
Definition: CORE_Array.h:396
void setCapacity(const tArrayIndex &c)
set the capacity of the vector
Definition: CORE_Array.hpp:84
tString toString() const
return the string associated to the string
Definition: CORE_String.h:150
#define tArrayIndex
Definition: types.h:39
tBoolean getSupIndex(const T &v, tArrayIndex &index) const
get the sup index of value return false if no value less than v
Definition: CORE_Array.hpp:513
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
void addAfterIndex(const tArrayIndex &index, const T &v)
add an element after index
Definition: CORE_Array.hpp:665
this class describes a list
Definition: CORE_List.h:12
#define tBoolean
Definition: types.h:48
#define null
Definition: types.h:13
void reverse()
reverse the vector
Definition: CORE_Array.hpp:589
void contractToLastElements(const tArrayIndex &n)
keep only the last n elements of the array and set its capacity also to n
Definition: CORE_Array.hpp:304
static void parse(const tString &str, unsigned char &c)
parse unsigned char c in str
Definition: CORE_String.h:418
tArrayIndex insertInOrder(const T &obj, const tBoolean &evenIfEqual)
insert the object in increasing order
Definition: CORE_Array.hpp:353
tBoolean removeAtIndex(const tArrayIndex &i)
Definition: CORE_Array.hpp:291
void add(const T &obj)
add an element at the end re-allocate the array if capacity too small
Definition: CORE_Array.hpp:165
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
static tBoolean search(const T *values, const tArrayIndex &n, const T &value, const tString &order, tArrayIndex &index)
search the value in values array ordered in order
Definition: CORE_Array.hpp:780
tBoolean remove()
remove the last element
Definition: CORE_Array.h:486
#define tArrayIndexMax
Definition: types.h:40
const T & get(const tArrayIndex &i) const
get the value at index i Assert in (i>-1) Assert in (i
Definition: CORE_Array.h:179
virtual ~CORE_Array()
destroy an array of T*
Definition: CORE_Array.hpp:65
this class describes an array
Definition: CORE_Array.h:18
tArrayIndex insert(const tArrayIndex &i, const T &obj)
insert the object at index i re-allocate the array if capacity too small
Definition: CORE_Array.hpp:324
tBoolean getInfIndex(const T &v, tArrayIndex &index) const
get the inf index of value return false if no value less than v
Definition: CORE_Array.hpp:441
void setSize(const tArrayIndex &n)
set the size of the array
Definition: CORE_Array.hpp:149
void sort()
sort the array in an increasing order
Definition: CORE_Array.h:546
void copy(const CORE_Array< T > &src)
void copy
Definition: CORE_Array.hpp:72
CORE_Array()
build an array of T*
Definition: CORE_Array.hpp:32
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:142
tString toString() const
turn the array into string
Definition: CORE_Array.hpp:651
void setValues(const CORE_Array< T > &array, const tArrayIndex &fromIndex)
Definition: CORE_Array.hpp:214
#define tString
Definition: types.h:49
void merge(const CORE_Array< T > &array)
merge the array in this
Definition: CORE_Array.hpp:604
static SP::CORE_String New()
create a class String
Definition: CORE_String.h:96
const tArrayIndex & getStartIndex() const
get start index
Definition: CORE_Array.h:217
const tFlag & getCapacityFactor() const
get the capacity factor
Definition: CORE_Array.h:213
void resize()
resize the array to the util size
Definition: CORE_Array.hpp:115
const tArrayIndex & getSize() const
return the size of the array
Definition: CORE_Array.h:223
const tArrayIndex & getCapacity() const
return the memory allocation size of the array
Definition: CORE_Array.h:226
void addAfterIndices(const CORE_Array< tArrayIndex > &indices, CORE_SharedPointersList< CORE_Array< T > > &values)
add alements after indices
Definition: CORE_Array.hpp:675
tBoolean getIndex(const T &v, tArrayIndex &index) const
get the index of value return false if no value in index
Definition: CORE_Array.hpp:404