60 for (
int &x:
values) x += value;
101 void IntArray :: checkBounds(
int i)
const 117 if ( allocChunk > 0 && (
int)this->
values.capacity() < n ) {
118 this->
values.reserve(n + allocChunk);
126 this->
values.assign(n, 0);
132 values.reserve(futureSize);
138 this->
values.resize(maxValue);
139 for (
int i = 1; i <= maxValue; ++i ) {
156 if ( allocChunk && (
int)
values.capacity() < this->
giveSize() + 1 ) {
166 this->checkBounds(_pos);
209 for (
const int &x: logical.
values) {
214 this->
values.resize(newsize);
217 for (
int i = 1; i <= logical.
giveSize(); ++i ) {
218 if ( logical.
at(i) ) {
228 printf(
"IntArray of size : %d\n", this->
giveSize());
229 for (
int i = 1; i <= this->
giveSize(); ++i ) {
231 printf(
" (other components not printed)");
234 printf(
"%d ", this->
at(i) );
245 printf(
"%s (%d): ", name.c_str(), this->
giveSize());
246 for (
int i = 1; i <= this->
giveSize(); ++i ) {
248 printf(
" (other components not printed)");
251 printf(
"%d ", this->
at(i) );
261 if(!std::isfinite((
double)val)) {
276 std :: ofstream arrayfile (filename);
277 if (arrayfile.is_open()) {
279 arrayfile <<
"IntArray of size : " << this->
giveSize() <<
"\n";
280 for (
int x: *
this ) {
281 arrayfile << x <<
"\t";
292 if ( !stream.
write(this->giveSize()) ) {
309 if ( !stream.
read(size) ) {
334 auto it = std::find(
values.begin(),
values.end(), value);
336 if ( it ==
values.end() ) {
339 return (
int)(it -
values.begin() + 1);
346 return std::binary_search (
values.begin(),
values.end(), _val);
352 if ( allocChunk > 0 &&
values.size() + 1 >=
values.capacity() ) {
355 auto low = std::lower_bound(
values.begin(),
values.end(), val);
362 if ( allocChunk > 0 &&
values.size() + 1 >=
values.capacity() ) {
365 auto low = std::lower_bound(
values.begin(),
values.end(), val);
366 if ( low ==
values.end() || *low != val ) {
376 auto low = std::lower_bound(
values.begin(),
values.end(), value);
377 if ( *low == value ) {
387 for (
int val: iarray ) {
390 if (
values [ i ] == val ) {
396 if (
values [ i ] > val ) {
429 for (
const int &val: x ) {
void eraseSorted(int value)
Erase the element of given value.
contextIOResultType storeYourself(DataStream &stream) const
Stores array to output stream.
void enumerate(int maxVal)
Resizes receiver and enumerates from 1 to the maximum value given.
std::vector< int > values
Stored values.
void printYourself() const
Prints receiver on stdout.
void erase(int pos)
Erase the element at given position (1-based index) Receiver will shrink accordingly, the values at positions (pos+1,...,size) will be moved to positions (pos,...,size-1)
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
bool isEmpty() const
Checks if receiver is empty (i.e., zero sized).
void zero()
Sets all component to zero.
int minimum() const
Finds the minimum component in the array.
int givePackSize(DataStream &buff) const
Returns how much space is needed to pack receivers message.
bool insertSortedOnce(int value, int allocChunk=0)
Inserts given value into a receiver, which is assumed to be sorted.
std::vector< int >::iterator end()
void findNonzeros(const IntArray &logical)
Finds all indices where the input array is nonzero.
Class implementing an array of integers.
int & at(int i)
Coefficient access function.
virtual int read(int *data, int count)=0
Reads count integer values into array pointed by data.
friend std::ostream & operator<<(std::ostream &out, const IntArray &x)
void sort(IntArray &arry, operation op)
Sorts the receiver using quicksort algorithm.
bool containsOnlyZeroes() const
Checks if receiver is all zero.
void printYourselfToFile(const std::string filename, const bool showDimensions=true) const
Print receiver to file.
virtual int write(const int *data, int count)=0
Writes count integer values from array pointed by data.
bool isFinite() const
Returns true if no element is NAN or infinite.
void insertSorted(int value, int allocChunk=0)
Inserts given value into a receiver, which is assumed to be sorted.
void insertOnce(int p)
Insert once (does not make any assumption about receiver state or ordering, quite inefficient)...
int maximum() const
Finds the maximum component in the array.
void resizeWithValues(int n, int allocChunk=0)
Checks size of receiver towards requested bounds.
void resize(int n)
Checks size of receiver towards requested bounds.
int & operator()(int i)
Coefficient access function.
contextIOResultType restoreYourself(DataStream &stream)
Restores array from image on stream.
void add(int val)
Adds given scalar to all values of receiver.
int findSorted(int value) const
Finds the first occurrence of given value, assuming that the receiver is sorted.
void pY() const
Abbreviation for printYourself().
void followedBy(const IntArray &b, int allocChunk=0)
Appends array b at the end of receiver.
std::vector< int >::iterator begin()
void preallocate(int futureSize)
Preallocates receiver to given futureSize if larger then allocatedSize.
the oofem namespace is to define a context or scope in which all oofem names are defined.
int findCommonValuesSorted(const IntArray &iarray, IntArray &common, int allocChunk=0) const
Extracts common values in receiver and iarray.
int findFirstIndexOf(int value) const
Finds index of first occurrence of given value in array.
virtual int givePackSizeOfInt(int count)=0