// Author:Ivana Hrivnacova; IPN Orsay
#include "AliMpArrayI.h"
-#include "AliMpIntPair.h"
#include "AliLog.h"
#include <Riostream.h>
#include <stdlib.h>
+#include <limits.h>
/// \cond CLASSIMP
ClassImp(AliMpArrayI)
const Int_t AliMpArrayI::fgkDefaultSize = 100;
//_____________________________________________________________________________
-AliMpArrayI::AliMpArrayI()
+AliMpArrayI::AliMpArrayI(Bool_t sort)
: TObject(),
+ fSort(sort),
fNofValues(0),
- fValues(fgkDefaultSize)
+ fValues(fgkDefaultSize),
+ fLimits(INT_MIN,INT_MAX)
{
/// Standard & default constructor
//_____________________________________________________________________________
AliMpArrayI::AliMpArrayI(TRootIOCtor* /*ioCtor*/)
: TObject(),
+ fSort(),
fNofValues(),
- fValues()
+ fValues(),
+ fLimits()
{
/// IO constructor
}
AliWarningStream() << "Resized array." << endl;
}
- // Find the position for the new value
- Int_t pos = GetPosition(value);
-
- // Move elements
- for ( Int_t i=fNofValues; i>=pos; i-- )
- fValues.AddAt(fValues.At(i), i+1);
-
+
+ // The position for the new value
+ Int_t pos;
+ if ( fSort ) {
+ pos = GetPosition(value);
+
+ // Move elements
+ for ( Int_t i=fNofValues; i>=pos; i-- )
+ fValues.AddAt(fValues.At(i), i+1);
+ }
+ else
+ pos = fNofValues;
+
// Add the new value in freed space
fValues.AddAt(value, pos);
++fNofValues;
+ // Update linits
+ if ( value < fLimits.GetFirst() ) fLimits.SetFirst(value);
+ if ( value > fLimits.GetSecond() ) fLimits.SetSecond(value);
+
return true;
}
//_____________________________________________________________________________
Bool_t AliMpArrayI::Remove(Int_t value)
{
-/// Add object with its key to the map and arrays
+/// Remove value from the array
// Find the position for the new value
Int_t pos = GetPosition(value);
if ( ! fNofValues ) return false;
- if ( fValues.At(0) > value || fValues.At(fNofValues-1) < value )
+ if ( value < fLimits.GetFirst() || value > fLimits.GetSecond() )
return false;
for ( Int_t i=0; i<fNofValues; i++ )
#ifndef ALI_MP_ARRAY_I_H
#define ALI_MP_ARRAY_I_H
+#include "AliMpIntPair.h"
+
#include <TObject.h>
#include <TArrayI.h>
-class AliMpIntPair;
-
class TString;
class AliMpArrayI : public TObject
{
public:
- AliMpArrayI();
+ AliMpArrayI(Bool_t sort = true);
AliMpArrayI(TRootIOCtor* /*ioCtor*/);
virtual ~AliMpArrayI();
static const Int_t fgkDefaultSize; ///< Default initial size
// data members
- Int_t fNofValues; ///< Number of values in the array
- TArrayI fValues; ///< Array of values
+ Bool_t fSort; ///< Option to sort the values
+ Int_t fNofValues; ///< Number of values in the array
+ TArrayI fValues; ///< Array of values
+ AliMpIntPair fLimits; ///< The minimum and maximum values in the array
ClassDef(AliMpArrayI,1) // Helper class for sorted integer array
};