STK++ 0.9.13
STK_ISparseArray1D.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2017 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23 */
24
25/*
26 * Project: stkpp::Arrays
27 * created on: 10 mars 2017
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_ISPARSEARRAY1D_H
36#define STK_ISPARSEARRAY1D_H
37
39
40
41namespace STK
42{
43
55template<class Derived>
56class ISparseArray1D: public ITContainer1D<Derived>
57{
58 public:
60
62 //typedef typename hidden::Traits<Derived>::Row Row;
64 //typedef typename hidden::Traits<Derived>::SubRow SubRow;
65 //typedef typename hidden::Traits<Derived>::SubCol SubCol;
66 //typedef typename hidden::Traits<Derived>::SubVector SubVector;
68
69 enum
70 {
76 };
82
83 using Base::range;
84 using Base::begin;
85 using Base::end;
86 using Base::size;
87 using Base::elt;
88 using Base::setRange;
89
90 protected:
91
102 ISparseArray1D( Range const& I, Type const& v);
107 ISparseArray1D( const ISparseArray1D &T, bool ref =false);
111 template<class OtherDerived>
120 template<class OtherDerived>
122
125
126 public:
128 inline bool isRef() const { return allocator_.isRef();}
134 inline void setRef(bool ref) const { allocator_.setRef(ref);}
135
136// /** @return a constant pointer on the data set*/
137// inline Type* const& p_data() const { return allocator_.p_data();}
139 Allocator const& allocator() const { return allocator_;}
140
142 inline RowRange const& rows() const { return range();}
144 inline int beginRows() const { return begin();}
146 inline int endRows() const { return end();}
148 inline int sizeRows() const { return size();}
149
151 inline ColRange cols() const { return ColRange(1);}
153 inline int beginCols() const { return baseIdx;}
155 inline int endCols() const { return baseIdx+1;}
157 inline int sizeCols() const { return 1;};
158
160 inline int lastIdxRows() const { return this->lastIdx();}
162 inline int lastIdxCols() const { return baseIdx;}
163
165 int capacity() const { return isRef() ? 0 : allocator_.size();}
166
171 inline Type& elt1Impl(int pos) { return allocator_.elt(pos);}
176 inline TypeConst elt1Impl(int pos) const { return allocator_.elt(pos);}
177
181 void shiftImpl(int beg = baseIdx);
188 Derived& resizeImpl(Range const& I);
192 void reserve(int size);
196 void clear();
201 void move(Derived const& T);
205 Derived& pushBack( int n=1);
209 Derived& popBack(int n = 1);
214 Derived& erase(int pos, int n=1);
218 Derived& insertElt( int pos, int n =1);
223 Derived& insert( int pos, Type const& v);
228 Derived& insert( Range const& I, Type const& v);
232 Derived& push_front(Type const& v);
236 Derived& push_back(Type const& v);
240 void swap(int pos1, int pos2);
250 Derived& assign( ISparseArray1D const& src);
251
255 Derived& setValue(Type const& value);
256};
257
258}
259
260#endif /* STK_ISPARSEARRAY1D_H */
In this file we define and implement the MemSAllocator class.
Interface class for SparseArray1D.
ISparseArray1D(ExprBase< OtherDerived > const &T)
Copy constructor.
ISparseArray1D(ISparseArray1D< OtherDerived > const &T, Range const &I)
constructor by reference, ref_=1.
void clear()
Clear the object.
Allocator const & allocator() const
void exchange(ISparseArray1D &T)
exchange this Container with T.
hidden::Traits< Derived >::Type Type
Derived & push_back(Type const &v)
STL compatibility: append an element v.
ISparseArray1D(const ISparseArray1D &T, bool ref=false)
Copy constructor.
hidden::Traits< Derived >::Col Col
Derived & pushBack(int n=1)
Add n Elements to the end of the container.
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
Derived & resizeImpl(Range const &I)
Resize the container.
hidden::Traits< Derived >::SubArray SubArray
ISparseArray1D(Range const &I)
constructor with a specified Range.
ITContainer1D< Derived > Base
void reserve(int size)
reserve internal memory for at least size elements.
void move(Derived const &T)
move T to this.
Derived & popBack(int n=1)
Delete last elts of the container.
ISparseArray1D()
Default constructor.
Derived & insert(Range const &I, Type const &v)
STL compatibility: Insert element v in the range I of the Array.
ISparseArray1D(Range const &I, Type const &v)
Misc constructor with first and last, initialization with a constant.
RowRange const & rows() const
Derived & erase(int pos, int n=1)
Delete n elements at the pos index to the container.
~ISparseArray1D()
destructor: allocated memory is liberated by MemAllocator base class.
Type & elt1Impl(int pos)
access to an element
Derived & setValue(Type const &value)
set a value to this container.
Derived & push_front(Type const &v)
STL compatibility: push front an element.
void setRef(bool ref) const
Modify the state of the container: this become a reference (if ref is true) or the owner of the data ...
hidden::CheckShift< Derived, structure_ > CheckShift
void swap(int pos1, int pos2)
Swapping the pos1 elt and the pos2 elt.
RowRange const & range() const
Derived & insertElt(int pos, int n=1)
Insert n elements at the position pos of the container.
Derived & assign(ISparseArray1D const &src)
overwrite this with src.
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
Derived & insert(int pos, Type const &v)
STL compatibility: Insert element v at position pos of the Array.
void shiftImpl(int beg=baseIdx)
New beginning index for the object.
TypeConst elt1Impl(int pos) const
access to a constant element
ISparseArray1D(ISparseArray1D const &T, Range const &I)
constructor by reference, ref_=1.
Interface base class for homogeneous 1D containers.
void setRange(RowRange const &I=RowRange())
Set range of the rows of the container.
hidden::Traits< Derived >::TypeConst TypeConst
RowRange const & range() const
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
const int baseIdx
base index of the containers created in STK++.
The namespace STK is the main domain space of the Statistical ToolKit project.
Utility class allowing to know if in an assignment the destination must be resized or shifted.