36#ifndef STK_MEMSALLOCATOR1D_H
37#define STK_MEMSALLOCATOR1D_H
39#include "../STK_Array1D.h"
44template<
typename Type_,
int NzMax_=UnknownSize>
class MemSAllocator1D;
52template<
typename Type_,
int NzMax_>
92 template<
int OtherNzMax_>
98 template<
int OtherNzMax_>
145 template<
int OtherSize>
157 template<
int OtherSize>
166 template<
int OtherSize_,
int RangeSize_>
188 template<
int OtherSize_>
225 void writeValue(
int pos, Type_
const& value);
284template<
typename Type_,
int NzMax_>
299template<
typename Type_,
int NzMax_>
316template<
typename Type_,
int NzMax_>
335template<
typename Type_,
int NzMax_>
346template<
typename Type_,
int NzMax_>
347template<
int OtherNzMax_>
359template<
typename Type_,
int NzMax_>
360template<
int OtherNzMax_>
373template<
typename Type_,
int NzMax_>
388template<
typename Type_,
int NzMax_>
392#ifdef STK_BOUNDS_CHECK
399 return (p_idx_->elt(idx1_) == pos) ? p_val_->elt(idx1_) :
zero_;
407template<
typename Type_,
int NzMax_>
410#ifdef STK_BOUNDS_CHECK
416 if (value ==
zero_) { setZero(pos);}
417 else { writeValue(pos, value);}
420template<
typename Type_,
int NzMax_>
423#ifdef STK_BOUNDS_CHECK
430 if (p_idx_->elt(idx1_) == pos)
432 p_idx_->erase(idx1_);
433 p_val_->erase(idx1_);
441template<
typename Type_,
int NzMax_>
442template<
int OtherSize>
446 if (range_ ==
I)
return *
this;
448 p_idx_->resize(
Range(
I.begin(),2) );
449 p_val_->resize(
Range(
I.begin(),2) );
466template<
typename Type_,
int NzMax_>
467template<
int OtherSize>
471 if (range_ ==
I)
return *
this;
479template<
typename Type_,
int NzMax_>
493template<
typename Type_,
int NzMax_>
494template<
int OtherSize_,
int RangeSize_>
497 if (range.size() <= 0)
return *
this;
498#ifdef STK_BOUNDS_CHECK
501 if (!T.range().isContaining(range))
504 for (
int k=range.begin(); k<range.end(); ++k, ++pos)
505 { setValue(pos, T.elt(k));}
512template<
typename Type_,
int NzMax_>
515 if ((range.
size() <= 0)||(range.
begin() == pos))
return;
516#ifdef STK_BOUNDS_CHECK
521 if (!range_.isContaining(range))
524 if (pos < range.
begin())
528 findIdx2(range.
begin());
530 for (
int k= range.
begin(); k<range.
end(); ++k, ++pos)
535 if (p_idx_->elt(idx2_) != k) { setZero1(pos);}
536 else { setValue1(pos);}
545 for (
int k= range.
lastIdx(); k>=range.
begin(); --k, --pos)
550 if (p_idx_->elt(idx2_) != k) { setZero1(pos);}
551 else { setValue2(pos);}
559template<
typename Type_,
int NzMax_>
562 std::swap(p_idx_, T.
p_idx_);
563 std::swap(p_val_, T.
p_val_);
564 std::swap(range_, T.
range_);
574template<
typename Type_,
int NzMax_>
584template<
typename Type,
int NzMax_>
585template<
int OtherSize_>
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)
598 setValue1(pos, value);
603 for (
int pos=
I.begin(); pos <
I.end(); ++pos)
621template<
typename Type_,
int NzMax_>
634template<
typename Type_,
int NzMax_>
637 int inc = first - begin();
639 { p_idx_->elt(
t) += inc;}
650template<
typename Type_,
int NzMax_>
654 setValue1(pos, value);
662template<
typename Type_,
int NzMax_>
666 if (p_idx_->elt(idx1_) == pos) { p_val_->elt(idx1_) =value;}
670 p_idx_->insert(idx1_+1, pos);
671 p_val_->insert(idx1_+1, value);
676template<
typename Type_,
int NzMax_>
680 if (p_idx_->elt(idx1_) == pos)
682 p_idx_->erase(idx1_);
683 p_val_->erase(idx1_);
692template<
typename Type_,
int NzMax_>
696 if (p_idx_->elt(idx1_) == pos)
697 { p_val_->elt(idx1_) = p_val_->elt(idx2_);}
701 p_idx_->insert(idx1_, pos);
702 p_val_->insertElt(idx1_, 1);
703 p_val_->elt(idx1_) = p_val_->elt(idx2_+1);
711template<
typename Type_,
int NzMax_>
715 if (p_idx_->elt(idx1_) == pos)
716 { p_val_->elt(idx1_) = p_val_->elt(idx2_);}
720 p_idx_->insert(idx1_, pos);
721 p_val_->insertElt(idx1_, 1);
722 p_val_->elt(idx1_) = p_val_->elt(idx2_);
#define STKOUT_OF_RANGE_1ARG(Where, Arg, Error)
#define STKRUNTIME_ERROR_1ARG(Where, Arg, Error)
#define STKOUT_OF_RANGE_2ARG(Where, Arg1, Arg2, Error)
memory allocator for sparse vectors classes.
Array1D< int, nzmax_ > Indexes
Type of the array storing indexes.
TRange< UnknownSize > AllocatorRange
Type of the range of the data.
void free()
function releasing all stored values.
TypeConst elt(int pos) const
This method allows to get the jth value.
void writeValue(int pos, Type_ const &value)
Write a value at the given position.
Values * p_val_
array of values
MemSAllocator1D & malloc(TRange< OtherSize > const &I)
main method for memory allocation.
void setZero1(int pos)
Set zero at position idx1_.
void memmove(int pos, Range const &range)
function moving a part of the allocator.
MemSAllocator1D()
default constructor
MemSAllocator1D & assign(TRange< OtherSize_ > const &I, Type const &value)
assign a value to allocator.
Indexes * p_idx_
array of indexes
const Type zero_
zero value
MemSAllocator1D & shift(int first)
shift the first index of the data to first.
Array1D< Type, nzmax_ > Values
Type of the array storing data.
void findIdx1(int pos) const
find first position in p_idx_ less or equal to pos
AllocatorRange range_
Range of the data.
AllocatorRange const & range() const
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
hidden::RemoveConst< Type_ >::Type const & TypeConst
MemSAllocator1D & exchange(MemSAllocator1D &T)
exchange this with T.
void findIdx2(int pos) const
find first position in p_idx_ less or equal to pos
~MemSAllocator1D()
destructor.
MemSAllocator1D & assign(MemSAllocator1D const &T)
copy the Allocator T by value.
int idx1_
Current indexes used for internal lookup.
void setValue1(int pos, TypeConst value)
Write a value at position idx1_.
MemSAllocator1D & realloc(TRange< OtherSize > const &I)
function for main ptr memory reallocation.
Values const & val() const
void setZero(int pos)
This method allows to write zero to the given position.
Indexes const & idx() const
void setValue2(int pos)
Set value idx2_ at position idx1_ when idx1 > idx2.
void findIdx1Next(int pos) const
find first position in p_idx_ less or equal to pos
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.
MemSAllocator1D & move(MemSAllocator1D const &T)
move the Allocator T to this.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
int begin() const
get the first index of the TRange.
Index sub-vector region: Specialization when the size is unknown.
int lastIdx() const
get the last index of the TRange.
int end() const
get the ending index of the TRange.
int size() const
get the size of the TRange (the number of elements).
const int UnknownSize
This value means that an integer is not known at compile-time, and that instead the value is stored i...
The namespace STK is the main domain space of the Statistical ToolKit project.
TRange< UnknownSize > Range
Arithmetic properties of STK fundamental types.
void setRef(bool ref) const
Modify the container : can become a reference or the owner of the data.
void exchange(TRef const &T)
swap this with the container T.