STK++ 0.9.13
STK::MemSAllocator1D< Type_, NzMax_ > Class Template Reference

memory allocator for sparse vectors classes. More...

#include <STK_MemSAllocator1D.h>

Inheritance diagram for STK::MemSAllocator1D< Type_, NzMax_ >:
Inheritance graph

Public Types

enum  { nzmax_ = (NzMax_< (UnknownSize-2)) ? NzMax_+2 : UnknownSize }
 
typedef Type_ Type
 
typedef hidden::RemoveConst< Type_ >::Type constTypeConst
 
typedef Array1D< int, nzmax_Indexes
 Type of the array storing indexes.
 
typedef Array1D< Type, nzmax_Values
 Type of the array storing data.
 
typedef TRange< UnknownSizeAllocatorRange
 Type of the range of the data.
 

Public Member Functions

 MemSAllocator1D ()
 default constructor
 
 MemSAllocator1D (AllocatorRange const &I)
 constructor with specified dimension
 
 MemSAllocator1D (AllocatorRange const &I, int nzmax)
 constructor with specified dimensions
 
 MemSAllocator1D (MemSAllocator1D const &A, bool ref=false)
 copy constructor
 
template<int OtherNzMax_>
 MemSAllocator1D (MemSAllocator1D< Type, OtherNzMax_ > const &A)
 Copy constructor.
 
template<int OtherNzMax_>
 MemSAllocator1D (MemSAllocator1D< Type, OtherNzMax_ > const &A, AllocatorRange const &I, bool ref=true)
 Copy constructor.
 
 ~MemSAllocator1D ()
 destructor.
 
AllocatorRange constrange () const
 
int begin () const
 
int end () const
 
int size () const
 
int beginIdx () const
 
int endIdx () const
 
int sizeIdx () const
 
Indexes constidx () const
 
Values constval () const
 
TypeConst elt (int pos) const
 This method allows to get the jth value.
 
void setValue (int pos, Type const &value)
 This method allows to overwrite or insert an element to the given position.
 
void setZero (int pos)
 This method allows to write zero to the given position.
 
template<int OtherSize>
MemSAllocator1Dmalloc (TRange< OtherSize > const &I)
 main method for memory allocation.
 
template<int OtherSize>
MemSAllocator1Drealloc (TRange< OtherSize > const &I)
 function for main ptr memory reallocation.
 
void free ()
 function releasing all stored values.
 
template<int OtherSize_, int RangeSize_>
MemSAllocator1Dmemcpy (int pos, MemSAllocator1D< Type, OtherSize_ > const &T, TRange< RangeSize_ > const &range)
 function copying a part of allocator T in this.
 
void memmove (int pos, Range const &range)
 function moving a part of the allocator.
 
MemSAllocator1Dexchange (MemSAllocator1D &T)
 exchange this with T.
 
MemSAllocator1Dassign (MemSAllocator1D const &T)
 copy the Allocator T by value.
 
template<int OtherSize_>
MemSAllocator1Dassign (TRange< OtherSize_ > const &I, Type const &value)
 assign a value to allocator.
 
MemSAllocator1Dmove (MemSAllocator1D const &T)
 move the Allocator T to this.
 
MemSAllocator1Dshift (int first)
 shift the first index of the data to first.
 
template<int OtherSize>
MemSAllocator1D< Type_, NzMax_ > & malloc (TRange< OtherSize > const &I)
 
template<int OtherSize>
MemSAllocator1D< Type_, NzMax_ > & realloc (TRange< OtherSize > const &I)
 
template<int OtherSize_, int RangeSize_>
MemSAllocator1D< Type_, NzMax_ > & memcpy (int pos, MemSAllocator1D< Type, OtherSize_ > const &T, TRange< RangeSize_ > const &range)
 
template<int OtherSize_>
MemSAllocator1D< Type, NzMax_ > & assign (TRange< OtherSize_ > const &I, Type const &value)
 
bool isRef () const
 
void setRef (bool ref) const
 Modify the container : can become a reference or the owner of the data.
 
- Public Member Functions inherited from STK::TRef<-1 >
bool isRef () const
 
bool ref () const
 
void exchange (TRef const &T)
 swap this with the container T.
 
void setRef (bool ref) const
 Modify the container : can become a reference or the owner of the data.
 

Protected Attributes

Indexesp_idx_
 array of indexes
 
Valuesp_val_
 array of values
 

Private Member Functions

void writeValue (int pos, Type_ const &value)
 Write a value at the given position.
 
void setValue1 (int pos, TypeConst value)
 Write a value at position idx1_.
 
void findIdx1 (int pos) const
 find first position in p_idx_ less or equal to pos
 
void findIdx1Next (int pos) const
 find first position in p_idx_ less or equal to pos
 
void findIdx1Prev (int pos) const
 find idx1_ previous position in p_idx_ greater than pos
 
void findIdx2 (int pos) const
 find first position in p_idx_ less or equal to pos
 
void findIdx2Next (int pos) const
 find idx2_ next position in p_idx_ less or equal to pos
 
void findIdx2Prev (int pos) const
 find idx2_ previous position in p_idx_ greater than pos
 
void setZero1 (int pos)
 Set zero at position idx1_.
 
void setValue1 (int pos)
 Set value idx2_ at position idx1_ when idx1 < idx2.
 
void setValue2 (int pos)
 Set value idx2_ at position idx1_ when idx1 > idx2.
 

Private Attributes

AllocatorRange range_
 Range of the data.
 
const Type zero_
 zero value
 
int idx1_
 Current indexes used for internal lookup.
 
int idx2_
 

Additional Inherited Members

- Protected Member Functions inherited from STK::TRef<-1 >
 TRef (bool ref)
 Default constructor We have to specify the member ref_.
 
 ~TRef ()
 destructor.
 

Detailed Description

template<typename Type_, int NzMax_>
class STK::MemSAllocator1D< Type_, NzMax_ >

memory allocator for sparse vectors classes.

Template Parameters
Type_type of elements stored in this allocator
NzMax_maximal number of element in sparse vector

Definition at line 53 of file STK_MemSAllocator1D.h.

Member Typedef Documentation

◆ AllocatorRange

template<typename Type_ , int NzMax_>
typedef TRange<UnknownSize> STK::MemSAllocator1D< Type_, NzMax_ >::AllocatorRange

Type of the range of the data.

Definition at line 68 of file STK_MemSAllocator1D.h.

◆ Indexes

template<typename Type_ , int NzMax_>
typedef Array1D<int, nzmax_> STK::MemSAllocator1D< Type_, NzMax_ >::Indexes

Type of the array storing indexes.

Definition at line 64 of file STK_MemSAllocator1D.h.

◆ Type

template<typename Type_ , int NzMax_>
typedef Type_ STK::MemSAllocator1D< Type_, NzMax_ >::Type

Definition at line 60 of file STK_MemSAllocator1D.h.

◆ TypeConst

template<typename Type_ , int NzMax_>
typedef hidden::RemoveConst<Type_>::Type const& STK::MemSAllocator1D< Type_, NzMax_ >::TypeConst

Definition at line 61 of file STK_MemSAllocator1D.h.

◆ Values

template<typename Type_ , int NzMax_>
typedef Array1D<Type, nzmax_> STK::MemSAllocator1D< Type_, NzMax_ >::Values

Type of the array storing data.

Definition at line 66 of file STK_MemSAllocator1D.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename Type_ , int NzMax_>
anonymous enum
Enumerator
nzmax_ 

Definition at line 56 of file STK_MemSAllocator1D.h.

57 {
58 nzmax_ = (NzMax_< (UnknownSize-2)) ? NzMax_+2 : UnknownSize
59 };
const int UnknownSize
This value means that an integer is not known at compile-time, and that instead the value is stored i...

Constructor & Destructor Documentation

◆ MemSAllocator1D() [1/6]

template<typename Type_ , int NzMax_>
STK::MemSAllocator1D< Type_, NzMax_ >::MemSAllocator1D ( )

default constructor

Definition at line 285 of file STK_MemSAllocator1D.h.

285 : IContainerRef(false)
286 , p_idx_(new Indexes(2))
287 , p_val_(new Values(2))
288 , range_()
289 , zero_(0)
290{
291 p_idx_->setValue(Arithmetic<int>::max());
292 p_idx_->front() = -Arithmetic<int>::max();
293 p_val_->setValue(Arithmetic<Type>::NA());
294}
Array1D< int, nzmax_ > Indexes
Type of the array storing indexes.
Values * p_val_
array of values
Indexes * p_idx_
array of indexes
const Type zero_
zero value
Array1D< Type, nzmax_ > Values
Type of the array storing data.
AllocatorRange range_
Range of the data.
TRef<-1 > IContainerRef
static Type NA()
Adding a Non Available (NA) special number.

References STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_, and STK::MemSAllocator1D< Type_, NzMax_ >::p_val_.

◆ MemSAllocator1D() [2/6]

template<typename Type_ , int NzMax_>
STK::MemSAllocator1D< Type_, NzMax_ >::MemSAllocator1D ( AllocatorRange const I)

constructor with specified dimension

Parameters
Irange of the rows

Definition at line 300 of file STK_MemSAllocator1D.h.

301 : IContainerRef(false)
302 , p_idx_(new Indexes(2))
303 , p_val_(new Values(2))
304 , range_(I)
305 , zero_(0)
306{
307 p_idx_->setValue(Arithmetic<int>::max());
308 p_idx_->front() = -Arithmetic<int>::max();
309 p_val_->setValue(Arithmetic<Type>::NA());
310}

References STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_, and STK::MemSAllocator1D< Type_, NzMax_ >::p_val_.

◆ MemSAllocator1D() [3/6]

template<typename Type_ , int NzMax_>
STK::MemSAllocator1D< Type_, NzMax_ >::MemSAllocator1D ( AllocatorRange const I,
int  nzmax 
)

constructor with specified dimensions

Parameters
Irange of the rows
nzmaxmaximal number of data

Definition at line 317 of file STK_MemSAllocator1D.h.

318 : IContainerRef(false)
319 , p_idx_( new Indexes(2) )
320 , p_val_( new Values(2) )
321 , range_(I)
322 , zero_(0)
323{
324 p_idx_->reserve(nzmax);
325 p_val_->reserve(nzmax);
326 p_idx_->setValue(Arithmetic<int>::max());
327 p_idx_->front() = -Arithmetic<int>::max();
328 p_val_->setValue(Arithmetic<Type>::NA());
329}

References STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_, and STK::MemSAllocator1D< Type_, NzMax_ >::p_val_.

◆ MemSAllocator1D() [4/6]

template<typename Type_ , int NzMax_>
STK::MemSAllocator1D< Type_, NzMax_ >::MemSAllocator1D ( MemSAllocator1D< Type_, NzMax_ > const A,
bool  ref = false 
)

copy constructor

Parameters
Aallocator to copy
reftrue if this copy is just a reference, false otherwise

Definition at line 336 of file STK_MemSAllocator1D.h.

338 , p_idx_(ref ? A.p_idx_ : new Indexes(A.idx()))
339 , p_val_(ref ? A.p_val_ : new Values(A.val()))
340 , range_(A.range_)
341 , zero_(A.zero_)
342{}
Values const & val() const
Indexes const & idx() const

◆ MemSAllocator1D() [5/6]

template<typename Type_ , int NzMax_>
template<int OtherNzMax_>
STK::MemSAllocator1D< Type_, NzMax_ >::MemSAllocator1D ( MemSAllocator1D< Type, OtherNzMax_ > const A)

Copy constructor.

Parameters
Aallocator to copy

Definition at line 348 of file STK_MemSAllocator1D.h.

349 : IContainerRef(false)
350 , p_idx_(new Indexes(A.idx()))
351 , p_val_(new Values(A.val()))
352 , range_(A.range_)
353 , zero_(A.zero_)
354{}

◆ MemSAllocator1D() [6/6]

template<typename Type_ , int NzMax_>
template<int OtherNzMax_>
STK::MemSAllocator1D< Type_, NzMax_ >::MemSAllocator1D ( MemSAllocator1D< Type, OtherNzMax_ > const A,
AllocatorRange const I,
bool  ref = true 
)

Copy constructor.

Map a range of A.

Parameters
A,Ithe allocator and range to reference
refis this a wrapper of A ? (true by default)

Definition at line 361 of file STK_MemSAllocator1D.h.

366 , p_idx_(ref ? A.p_idx_ : new Indexes(A.idx()))
367 , p_val_(ref ? A.p_val_ : new Values(A.val()))
368 , range_(I)
369 , zero_(A.zero_)
370{}

◆ ~MemSAllocator1D()

template<typename Type_ , int NzMax_>
STK::MemSAllocator1D< Type_, NzMax_ >::~MemSAllocator1D ( )

destructor.

Release memory.

Definition at line 374 of file STK_MemSAllocator1D.h.

375{
376 if (!isRef())
377 {
378 delete p_idx_;
379 delete p_val_;
380 }
381}

Member Function Documentation

◆ assign() [1/3]

template<typename Type_ , int NzMax_>
MemSAllocator1D< Type_, NzMax_ > & STK::MemSAllocator1D< Type_, NzMax_ >::assign ( MemSAllocator1D< Type_, NzMax_ > const T)

copy the Allocator T by value.

The memory is free and the Allocator T is physically copied in this.

Parameters
Tthe allocator to copy by value
Returns
a copy of T

Definition at line 576 of file STK_MemSAllocator1D.h.

577{
578 *p_idx_ = T.idx();
579 *p_val_ = T.val();
580 range_ = T.range();
581 return *this;
582}

References STK::MemSAllocator1D< Type_, NzMax_ >::idx(), STK::MemSAllocator1D< Type_, NzMax_ >::range(), and STK::MemSAllocator1D< Type_, NzMax_ >::val().

◆ assign() [2/3]

template<typename Type_ , int NzMax_>
template<int OtherSize_>
MemSAllocator1D & STK::MemSAllocator1D< Type_, NzMax_ >::assign ( TRange< OtherSize_ > const I,
Type const value 
)

assign a value to allocator.

Parameters
I,valuerange and value to assign to the allocator
Returns
this
Note
allocator is no more sparse !

◆ assign() [3/3]

template<typename Type_ , int NzMax_>
template<int OtherSize_>
MemSAllocator1D< Type, NzMax_ > & STK::MemSAllocator1D< Type_, NzMax_ >::assign ( TRange< OtherSize_ > const I,
Type const value 
)

Definition at line 587 of file STK_MemSAllocator1D.h.

588{
589 // reserve first if not zero_ using upper-bound current size + range size
590 findIdx1(I.begin());
591 if (value!=zero_)
592 {
593 p_idx_->reserve(I.size()+p_idx_->size());
594 p_val_->reserve(I.size()+p_val_->size());
595 for (int pos= I.begin(); pos < I.end(); ++pos)
596 {
597 findIdx1Next(pos);
598 setValue1(pos, value);
599 }
600 }
601 else
602 {
603 for (int pos= I.begin(); pos < I.end(); ++pos)
604 {
605 findIdx1Next(pos);
606 setZero1(pos);
607 }
608 }
609 return *this;
610}
void setZero1(int pos)
Set zero at position idx1_.
void findIdx1(int pos) const
find first position in p_idx_ less or equal to pos
void setValue1(int pos, TypeConst value)
Write a value at position idx1_.
void findIdx1Next(int pos) const
find first position in p_idx_ less or equal to pos

References STK::zero_.

◆ begin()

template<typename Type_ , int NzMax_>
int STK::MemSAllocator1D< Type_, NzMax_ >::begin ( ) const
inline

◆ beginIdx()

template<typename Type_ , int NzMax_>
int STK::MemSAllocator1D< Type_, NzMax_ >::beginIdx ( ) const
inline
Returns
the first index of the index array

Definition at line 115 of file STK_MemSAllocator1D.h.

115{ return p_idx_->begin();}

References STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_.

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::findIdx1(), and STK::MemSAllocator1D< Type_, NzMax_ >::findIdx2().

◆ elt()

template<typename Type_ , int NzMax_>
MemSAllocator1D< Type_, NzMax_ >::TypeConst STK::MemSAllocator1D< Type_, NzMax_ >::elt ( int  pos) const

This method allows to get the jth value.

Parameters
posposition of the element
Returns
0 if the element is not stored, the value of the element otherwise

Definition at line 390 of file STK_MemSAllocator1D.h.

391{
392#ifdef STK_BOUNDS_CHECK
393 if (pos < begin())
395 if (pos >= end())
397#endif
398 findIdx1(pos);
399 return (p_idx_->elt(idx1_) == pos) ? p_val_->elt(idx1_) : zero_;
400}
#define STKOUT_OF_RANGE_1ARG(Where, Arg, Error)
Definition STK_Macros.h:93
TypeConst elt(int pos) const
This method allows to get the jth value.
int idx1_
Current indexes used for internal lookup.

References STK::MemSAllocator1D< Type_, NzMax_ >::begin(), STK::MemSAllocator1D< Type_, NzMax_ >::elt(), STK::MemSAllocator1D< Type_, NzMax_ >::end(), STKOUT_OF_RANGE_1ARG, and STK::zero_.

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::elt().

◆ end()

template<typename Type_ , int NzMax_>
int STK::MemSAllocator1D< Type_, NzMax_ >::end ( ) const
inline

◆ endIdx()

template<typename Type_ , int NzMax_>
int STK::MemSAllocator1D< Type_, NzMax_ >::endIdx ( ) const
inline
Returns
the ending index of the index array

Definition at line 117 of file STK_MemSAllocator1D.h.

117{ return p_idx_->end();}

References STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_.

◆ exchange()

template<typename Type_ , int NzMax_>
MemSAllocator1D< Type_, NzMax_ > & STK::MemSAllocator1D< Type_, NzMax_ >::exchange ( MemSAllocator1D< Type_, NzMax_ > &  T)

exchange this with T.

Parameters
Tthe container to exchange with T

Definition at line 560 of file STK_MemSAllocator1D.h.

561{
562 std::swap(p_idx_, T.p_idx_);
563 std::swap(p_val_, T.p_val_);
564 std::swap(range_, T.range_);
566 return *this;
567}
void exchange(TRef const &T)
swap this with the container T.

References STK::TRef<-1 >::exchange(), STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_, STK::MemSAllocator1D< Type_, NzMax_ >::p_val_, and STK::MemSAllocator1D< Type_, NzMax_ >::range_.

◆ findIdx1()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::findIdx1 ( int  pos) const
inlineprivate

find first position in p_idx_ less or equal to pos

Parameters
posposition to find

Definition at line 236 of file STK_MemSAllocator1D.h.

237 { for ( idx1_ = beginIdx(); p_idx_->elt(idx1_+1) <= pos; ++idx1_) {} }

References STK::MemSAllocator1D< Type_, NzMax_ >::beginIdx(), STK::MemSAllocator1D< Type_, NzMax_ >::idx1_, and STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_.

◆ findIdx1Next()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::findIdx1Next ( int  pos) const
inlineprivate

find first position in p_idx_ less or equal to pos

Parameters
posposition to find

Definition at line 241 of file STK_MemSAllocator1D.h.

242 { if (p_idx_->elt(idx1_) == Arithmetic<int>::max()) return;
243 for ( ; p_idx_->elt(idx1_+1) <= pos; ++idx1_) {}
244 }

References STK::MemSAllocator1D< Type_, NzMax_ >::idx1_, and STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_.

◆ findIdx1Prev()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::findIdx1Prev ( int  pos) const
inlineprivate

find idx1_ previous position in p_idx_ greater than pos

Parameters
posposition to find

Definition at line 248 of file STK_MemSAllocator1D.h.

249 { for ( ; p_idx_->elt(idx1_) >= pos; --idx1_) {}}

References STK::MemSAllocator1D< Type_, NzMax_ >::idx1_, and STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_.

◆ findIdx2()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::findIdx2 ( int  pos) const
inlineprivate

find first position in p_idx_ less or equal to pos

Parameters
posposition to find

Definition at line 254 of file STK_MemSAllocator1D.h.

255 { for ( idx2_ = beginIdx(); p_idx_->elt(idx2_+1) <= pos; ++idx2_) {} }

References STK::MemSAllocator1D< Type_, NzMax_ >::beginIdx(), STK::MemSAllocator1D< Type_, NzMax_ >::idx2_, and STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_.

◆ findIdx2Next()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::findIdx2Next ( int  pos) const
inlineprivate

find idx2_ next position in p_idx_ less or equal to pos

Parameters
posposition to find

Definition at line 259 of file STK_MemSAllocator1D.h.

260 { if (p_idx_->elt(idx2_) == Arithmetic<int>::max()) return;
261 for ( ; p_idx_->elt(idx2_+1) <= pos; ++idx2_) {}
262 }

References STK::MemSAllocator1D< Type_, NzMax_ >::idx2_, and STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_.

◆ findIdx2Prev()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::findIdx2Prev ( int  pos) const
inlineprivate

find idx2_ previous position in p_idx_ greater than pos

Parameters
posposition to find

Definition at line 266 of file STK_MemSAllocator1D.h.

267 { for ( ; p_idx_->elt(idx2_) >= pos; --idx2_) {}}

References STK::MemSAllocator1D< Type_, NzMax_ >::idx2_, and STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_.

◆ free()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::free ( )

function releasing all stored values.

Definition at line 480 of file STK_MemSAllocator1D.h.

481{
482 p_idx_->clear();
483 p_val_->clear();
485 return;
486}
TRange< UnknownSize > AllocatorRange
Type of the range of the data.

◆ idx()

template<typename Type_ , int NzMax_>
Indexes const & STK::MemSAllocator1D< Type_, NzMax_ >::idx ( ) const
inline
Returns
the vector with the indexes

Definition at line 122 of file STK_MemSAllocator1D.h.

122{ return *p_idx_;}

References STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_.

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::assign().

◆ isRef()

template<typename Type_ , int NzMax_>
bool STK::TRef<-1 >::isRef ( ) const
inline
Returns
true if *this is reference container, false otherwise

Definition at line 81 of file STK_IContainerRef.h.

81{ return ref_;}
bool ref_
Is it a "true" container or a wrapper ? ref_ should be false if this own its own data,...

◆ malloc() [1/2]

template<typename Type_ , int NzMax_>
template<int OtherSize>
MemSAllocator1D & STK::MemSAllocator1D< Type_, NzMax_ >::malloc ( TRange< OtherSize > const I)

main method for memory allocation.

Note
do nothing for sparse arrays.
Parameters
Irange of the data allocated

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::malloc().

◆ malloc() [2/2]

template<typename Type_ , int NzMax_>
template<int OtherSize>
MemSAllocator1D< Type_, NzMax_ > & STK::MemSAllocator1D< Type_, NzMax_ >::malloc ( TRange< OtherSize > const I)

Definition at line 443 of file STK_MemSAllocator1D.h.

444{
445 // there is no necessity to allocate if range_ is the same
446 if (range_ == I) return *this;
447 if (isRef()) { STKRUNTIME_ERROR_1ARG(MemSAllocator1D::malloc,I,cannot operate on references);}
448 p_idx_->resize( Range(I.begin(),2) );
449 p_val_->resize( Range(I.begin(),2) );
450 p_idx_->setValue(Arithmetic<int>::max());
451 p_idx_->front() = -Arithmetic<int>::max();
452 p_val_->setValue(Arithmetic<Type>::NA());
453 range_ = I;
454 return *this;
455}
#define STKRUNTIME_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:129
MemSAllocator1D & malloc(TRange< OtherSize > const &I)
main method for memory allocation.
TRange< UnknownSize > Range
Definition STK_Range.h:59

References STK::MemSAllocator1D< Type_, NzMax_ >::malloc(), and STKRUNTIME_ERROR_1ARG.

◆ memcpy() [1/2]

template<typename Type_ , int NzMax_>
template<int OtherSize_, int RangeSize_>
MemSAllocator1D & STK::MemSAllocator1D< Type_, NzMax_ >::memcpy ( int  pos,
MemSAllocator1D< Type, OtherSize_ > const T,
TRange< RangeSize_ > const range 
)

function copying a part of allocator T in this.

Parameters
posposition where will be copied data
T,rangethe array of data and the range of the data to copy
Note
only which are not zero are copied

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::memcpy().

◆ memcpy() [2/2]

template<typename Type_ , int NzMax_>
template<int OtherSize_, int RangeSize_>
MemSAllocator1D< Type_, NzMax_ > & STK::MemSAllocator1D< Type_, NzMax_ >::memcpy ( int  pos,
MemSAllocator1D< Type, OtherSize_ > const T,
TRange< RangeSize_ > const range 
)

Definition at line 495 of file STK_MemSAllocator1D.h.

496{
497 if (range.size() <= 0) return *this;
498#ifdef STK_BOUNDS_CHECK
499 if (pos < begin()) { STKOUT_OF_RANGE_1ARG(MemSAllocator1D::memcpy,pos,begin() > pos);}
500 if (pos >= end()) { STKOUT_OF_RANGE_1ARG(MemSAllocator1D::memcpy,pos,end() <= pos);}
501 if (!T.range().isContaining(range))
502 { STKOUT_OF_RANGE_1ARG(MemSAllocator::memcopy,range,range not in T.range());}
503#endif
504 for (int k=range.begin(); k<range.end(); ++k, ++pos)
505 { setValue(pos, T.elt(k));}
506 return *this;
507}
AllocatorRange const & range() const
MemSAllocator1D & memcpy(int pos, MemSAllocator1D< Type, OtherSize_ > const &T, TRange< RangeSize_ > const &range)
function copying a part of allocator T in this.
void setValue(int pos, Type const &value)
This method allows to overwrite or insert an element to the given position.
int size() const
get the size of the TRange (the number of elements).
Definition STK_Range.h:303

References STK::MemSAllocator1D< Type_, NzMax_ >::memcpy(), and STKOUT_OF_RANGE_1ARG.

◆ memmove()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::memmove ( int  pos,
Range const range 
)

function moving a part of the allocator.

Parameters
pos,rangeposition and range in form [begin,end) to move

Definition at line 513 of file STK_MemSAllocator1D.h.

514{
515 if ((range.size() <= 0)||(range.begin() == pos)) return;
516#ifdef STK_BOUNDS_CHECK
517 if (pos < begin())
519 if (pos >= end())
523#endif
524 if (pos < range.begin()) // ==> idx1 < idx2
525 {
526 // initialize idx1_ and idx2_
527 findIdx1(pos);
529 // start loop over range
530 for (int k= range.begin(); k<range.end(); ++k, ++pos)
531 {
532 // update idx1_ and idx2 (do nothing at the beginning)
533 findIdx1Next(pos);
534 findIdx2Next(k);
535 if (p_idx_->elt(idx2_) != k) { setZero1(pos);}
536 else { setValue1(pos);}
537 }
538 }
539 else // ==> idx2 < idx1
540 {
541 // initialize idx1_ and idx2_
543 pos += range.size();
544 findIdx1(pos);
545 for (int k= range.lastIdx(); k>=range.begin(); --k, --pos)
546 {
547 // update idx1_ and idx2 (do nothing at the beginning)
548 findIdx1Prev(pos);
549 findIdx2Prev(k);
550 if (p_idx_->elt(idx2_) != k) { setZero1(pos);}
551 else { setValue2(pos);}
552 }
553 }
554}
void memmove(int pos, Range const &range)
function moving a part of the allocator.
void findIdx1Prev(int pos) const
find idx1_ previous position in p_idx_ greater than pos
void findIdx2Next(int pos) const
find idx2_ next position in p_idx_ less or equal to pos
void findIdx2Prev(int pos) const
find idx2_ previous position in p_idx_ greater than pos
void findIdx2(int pos) const
find first position in p_idx_ less or equal to pos
void setValue2(int pos)
Set value idx2_ at position idx1_ when idx1 > idx2.
bool isContaining(TRange< OtherSize_ > const &I) const
check if the TRange I is include in the this TRange
Definition STK_Range.h:107
int lastIdx() const
get the last index of the TRange.
Definition STK_Range.h:313

References STK::RangeBase< Derived >::begin(), STK::TRange< UnknownSize >::end(), STK::TRange< UnknownSize >::lastIdx(), STK::MemSAllocator1D< Type_, NzMax_ >::memmove(), STK::TRange< UnknownSize >::size(), and STKOUT_OF_RANGE_1ARG.

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::memmove().

◆ move()

template<typename Type_ , int NzMax_>
MemSAllocator1D< Type_, NzMax_ > & STK::MemSAllocator1D< Type_, NzMax_ >::move ( MemSAllocator1D< Type_, NzMax_ > const T)

move the Allocator T to this.

The memory of this is freed and T becomes a reference of this. This method allow to move the data of T to this without using physical copy.

Parameters
Tthe allocator to move to this
Returns
this object.
Note
the data member ref_ is mutable so that T can be passed as a constant reference.

Definition at line 622 of file STK_MemSAllocator1D.h.

623{
624 p_idx_->move(T.p_idx_);
625 p_val_->move(T.p_val_);
626 range_ = T.range_;
627 setRef(T.ref());
628 return *this;
629}
void setRef(bool ref) const
Modify the container : can become a reference or the owner of the data.

References STK::MemSAllocator1D< Type_, NzMax_ >::move(), STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_, STK::MemSAllocator1D< Type_, NzMax_ >::p_val_, STK::MemSAllocator1D< Type_, NzMax_ >::range_, and STK::TRef<-1 >::ref().

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::move().

◆ range()

template<typename Type_ , int NzMax_>
AllocatorRange const & STK::MemSAllocator1D< Type_, NzMax_ >::range ( ) const
inline
Returns
the range of the data

Definition at line 106 of file STK_MemSAllocator1D.h.

106{ return range_;}

References STK::MemSAllocator1D< Type_, NzMax_ >::range_.

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::assign().

◆ realloc() [1/2]

template<typename Type_ , int NzMax_>
template<int OtherSize>
MemSAllocator1D & STK::MemSAllocator1D< Type_, NzMax_ >::realloc ( TRange< OtherSize > const I)

function for main ptr memory reallocation.

If the size requested is greater than the allocated size, the Type stored are saved and copied using the operator=. the Type class have to provide this operator.

If the size requested is lesser than the allocated size, only the first elements fitting in the container are copied.

Parameters
Irange of the data to reserve

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::realloc().

◆ realloc() [2/2]

template<typename Type_ , int NzMax_>
template<int OtherSize>
MemSAllocator1D< Type_, NzMax_ > & STK::MemSAllocator1D< Type_, NzMax_ >::realloc ( TRange< OtherSize > const I)

Definition at line 468 of file STK_MemSAllocator1D.h.

469{
470 // there is no necessity to allocate if range_ is the same
471 if (range_ == I) return *this;
472 if (isRef()) { STKRUNTIME_ERROR_1ARG(MemSAllocator1D::realloc,I,cannot operate on references);}
473 p_idx_->resize(I);
474 p_val_->resize(I);
475 range_ = I;
476 return this;
477}
MemSAllocator1D & realloc(TRange< OtherSize > const &I)
function for main ptr memory reallocation.

References STK::MemSAllocator1D< Type_, NzMax_ >::realloc(), and STKRUNTIME_ERROR_1ARG.

◆ setRef()

template<typename Type_ , int NzMax_>
void STK::TRef<-1 >::setRef ( bool  ref) const
inline

Modify the container : can become a reference or the owner of the data.

To use with care if we want to avoid memory leak.

Parameters
ref: false if this own its own data.

Definition at line 92 of file STK_IContainerRef.h.

92{ ref_ = ref;}

◆ setValue()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::setValue ( int  pos,
Type const value 
)

This method allows to overwrite or insert an element to the given position.

Parameters
pos,valueindex and value to set

Definition at line 408 of file STK_MemSAllocator1D.h.

409{
410#ifdef STK_BOUNDS_CHECK
411 if (pos < begin())
413 if (pos >= end())
415#endif
416 if (value == zero_) { setZero(pos);}
417 else { writeValue(pos, value);}
418}
#define STKOUT_OF_RANGE_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:102
void writeValue(int pos, Type_ const &value)
Write a value at the given position.
void setZero(int pos)
This method allows to write zero to the given position.

References STK::MemSAllocator1D< Type_, NzMax_ >::begin(), STK::MemSAllocator1D< Type_, NzMax_ >::end(), STK::MemSAllocator1D< Type_, NzMax_ >::setValue(), STKOUT_OF_RANGE_2ARG, and STK::zero_.

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::setValue().

◆ setValue1() [1/2]

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::setValue1 ( int  pos)
private

Set value idx2_ at position idx1_ when idx1 < idx2.

Parameters
posposition to overwrite

Definition at line 693 of file STK_MemSAllocator1D.h.

694{
695 // there is an existing stored value for this entry
696 if (p_idx_->elt(idx1_) == pos)
697 { p_val_->elt(idx1_) = p_val_->elt(idx2_);}
698 else // value is not yet an entry, so add it
699 {
700 idx1_++;
701 p_idx_->insert(idx1_, pos);
702 p_val_->insertElt(idx1_, 1);
703 p_val_->elt(idx1_) = p_val_->elt(idx2_+1); // take care that elt1 and elt2 are shifted
704 }
705}

◆ setValue1() [2/2]

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::setValue1 ( int  pos,
TypeConst  value 
)
private

Write a value at position idx1_.

If p_idx_->elt(pos) != idx1_ value is inserted at this position, otherwise exiting value is overwritten.

Parameters
pos,valueposition and value to write

Definition at line 663 of file STK_MemSAllocator1D.h.

664{
665 // there is an existing stored value for this entry
666 if (p_idx_->elt(idx1_) == pos) { p_val_->elt(idx1_) =value;}
667 else // value is not yet an entry, so add it
668 {
669 // Otherwise insert it
670 p_idx_->insert(idx1_+1, pos);
671 p_val_->insert(idx1_+1, value);
672 }
673}

◆ setValue2()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::setValue2 ( int  pos)
private

Set value idx2_ at position idx1_ when idx1 > idx2.

Parameters
posposition to overwrite

Definition at line 712 of file STK_MemSAllocator1D.h.

713{
714 // there is an existing stored value for this entry
715 if (p_idx_->elt(idx1_) == pos)
716 { p_val_->elt(idx1_) = p_val_->elt(idx2_);}
717 else // value is not yet an entry, so add it
718 {
719 idx1_++;
720 p_idx_->insert(idx1_, pos);
721 p_val_->insertElt(idx1_, 1);
722 p_val_->elt(idx1_) = p_val_->elt(idx2_);
723
724 }
725}

◆ setZero()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::setZero ( int  pos)

This method allows to write zero to the given position.

Parameters
posindex

Definition at line 421 of file STK_MemSAllocator1D.h.

422{
423#ifdef STK_BOUNDS_CHECK
424 if (pos < begin())
426 if (pos >= end())
428#endif
429 findIdx1(pos);
430 if (p_idx_->elt(idx1_) == pos)
431 {
432 p_idx_->erase(idx1_);
433 p_val_->erase(idx1_);
434 }
435}

References STK::MemSAllocator1D< Type_, NzMax_ >::begin(), STK::MemSAllocator1D< Type_, NzMax_ >::end(), STK::MemSAllocator1D< Type_, NzMax_ >::setZero(), and STKOUT_OF_RANGE_1ARG.

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::setZero().

◆ setZero1()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::setZero1 ( int  pos)
private

Set zero at position idx1_.

Parameters
posposition of the zero to set

Definition at line 677 of file STK_MemSAllocator1D.h.

678{
679 // there is an existing stored value for this entry
680 if (p_idx_->elt(idx1_) == pos)
681 {
682 p_idx_->erase(idx1_);
683 p_val_->erase(idx1_);
684 }
685}

◆ shift()

template<typename Type_ , int NzMax_>
MemSAllocator1D< Type_, NzMax_ > & STK::MemSAllocator1D< Type_, NzMax_ >::shift ( int  first)

shift the first index of the data to first.

Parameters
firstthe index of the first data to set

Definition at line 635 of file STK_MemSAllocator1D.h.

636{
637 int inc = first - begin();
638 for (int t=p_idx_->begin()+1; p_idx_->elt(t) != Arithmetic<int>::max(); ++t)
639 { p_idx_->elt(t) += inc;}
640 range_.shift(first);
641 return *this;
642}
TRange & shift(int first)
Shift the TRange giving the first element: the size is not modified.
Definition STK_Range.h:317

◆ size()

template<typename Type_ , int NzMax_>
int STK::MemSAllocator1D< Type_, NzMax_ >::size ( ) const
inline
Returns
the size of the data

Definition at line 112 of file STK_MemSAllocator1D.h.

112{ return range_.size();}

References STK::MemSAllocator1D< Type_, NzMax_ >::range_, and STK::TRange< UnknownSize >::size().

◆ sizeIdx()

template<typename Type_ , int NzMax_>
int STK::MemSAllocator1D< Type_, NzMax_ >::sizeIdx ( ) const
inline
Returns
the size of the index array

Definition at line 119 of file STK_MemSAllocator1D.h.

119{ return p_idx_->size();}

References STK::MemSAllocator1D< Type_, NzMax_ >::p_idx_.

◆ val()

template<typename Type_ , int NzMax_>
Values const & STK::MemSAllocator1D< Type_, NzMax_ >::val ( ) const
inline
Returns
the vector with the values

Definition at line 124 of file STK_MemSAllocator1D.h.

124{ return *p_val_;}

References STK::MemSAllocator1D< Type_, NzMax_ >::p_val_.

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::assign().

◆ writeValue()

template<typename Type_ , int NzMax_>
void STK::MemSAllocator1D< Type_, NzMax_ >::writeValue ( int  pos,
Type_ const value 
)
private

Write a value at the given position.

If p_idx_->elt(pos) != idx value is inserted at this position, otherwise exiting value is overwritten.

Parameters
pos,valueposition and value to write

Definition at line 651 of file STK_MemSAllocator1D.h.

652{
653 findIdx1(pos);
654 setValue1(pos, value);
655}

Member Data Documentation

◆ idx1_

template<typename Type_ , int NzMax_>
int STK::MemSAllocator1D< Type_, NzMax_ >::idx1_
mutableprivate

◆ idx2_

◆ p_idx_

◆ p_val_

◆ range_

◆ zero_

template<typename Type_ , int NzMax_>
const Type STK::MemSAllocator1D< Type_, NzMax_ >::zero_
private

zero value

Definition at line 216 of file STK_MemSAllocator1D.h.


The documentation for this class was generated from the following file: