- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Alps-1.3.0/CoinUtils/src/CoinHelperFunctions.hpp File Reference

`#include "CoinUtilsConfig.h"`
`#include <unistd.h>`
`#include <cstdlib>`
`#include <cstdio>`
`#include <algorithm>`
`#include "CoinTypes.hpp"`
`#include "CoinError.hpp"`

Include dependency graph for CoinHelperFunctions.hpp:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Classes
class | CoinThreadRandom
| Class for thread specific random numbers. More...
## Defines
#define | COIN_RESTRICT
#define | COIN_OWN_RANDOM_32
#define | CoinSizeofAsInt(type) (static_cast<int>(sizeof(type)))
| This helper returns "sizeof" as an int.
#define | COIN_DETAIL_PRINT(s) {}
## Functions
template<class T>
void | CoinCopyN (register const T *from, const int size, register T *to)
| This helper function copies an array to another location using Duff's device (for a speedup of ~2).
template<class T>
void | CoinCopy (register const T *first, register const T *last, register T *to)
| This helper function copies an array to another location using Duff's device (for a speedup of ~2).
template<class T>
void | CoinDisjointCopyN (register const T *from, const int size, register T *to)
| This helper function copies an array to another location.
template<class T>
void | CoinDisjointCopy (register const T *first, register const T *last, register T *to)
| This helper function copies an array to another location.
template<class T>
T * | CoinCopyOfArray (const T *array, const int size)
| Return an array of length `size` filled with input from `array`, or null if `array` is null.
template<class T>
T * | CoinCopyOfArrayPartial (const T *array, const int size, const int copySize)
| Return an array of length `size` filled with first copySize from `array`, or null if `array` is null.
template<class T>
T * | CoinCopyOfArray (const T *array, const int size, T value)
| Return an array of length `size` filled with input from `array`, or filled with (scalar) `value` if `array` is null.
template<class T>
T * | CoinCopyOfArrayOrZero (const T *array, const int size)
| Return an array of length `size` filled with input from `array`, or filled with zero if `array` is null.
template<class T>
void | CoinMemcpyN (register const T *from, const int size, register T *to)
| This helper function copies an array to another location.
template<class T>
void | CoinMemcpy (register const T *first, register const T *last, register T *to)
| This helper function copies an array to another location.
template<class T>
void | CoinFillN (register T *to, const int size, register const T value)
| This helper function fills an array with a given value.
template<class T>
void | CoinFill (register T *first, register T *last, const T value)
| This helper function fills an array with a given value.
template<class T>
void | CoinZeroN (register T *to, const int size)
| This helper function fills an array with zero.
void | CoinCheckDoubleZero (double *to, const int size)
| This Debug helper function checks an array is all zero.
void | CoinCheckIntZero (int *to, const int size)
| This Debug helper function checks an array is all zero.
template<class T>
void | CoinZero (register T *first, register T *last)
| This helper function fills an array with a given value.
char * | CoinStrdup (const char *name)
| Returns strdup or NULL if original NULL.
template<class T>
T | CoinMax (register const T x1, register const T x2)
| Return the larger (according to `operator<()` of the arguments.
template<class T>
T | CoinMin (register const T x1, register const T x2)
| Return the smaller (according to `operator<()` of the arguments.
template<class T>
T | CoinAbs (const T value)
| Return the absolute value of the argument.
template<class T>
bool | CoinIsSorted (register const T *first, const int size)
| This helper function tests whether the entries of an array are sorted according to operator<.
template<class T>
bool | CoinIsSorted (register const T *first, register const T *last)
| This helper function tests whether the entries of an array are sorted according to operator<.
template<class T>
void | CoinIotaN (register T *first, const int size, register T init)
| This helper function fills an array with the values init, init+1, init+2, etc.
template<class T>
void | CoinIota (T *first, const T *last, T init)
| This helper function fills an array with the values init, init+1, init+2, etc.
template<class T>
T * | CoinDeleteEntriesFromArray (register T *arrayFirst, register T *arrayLast, const int *firstDelPos, const int *lastDelPos)
| This helper function deletes certain entries from an array.
double | CoinDrand48 (bool isSeed=false, unsigned int seed=1)
| Return a random number between 0 and 1.
void | CoinSeedRandom (int iseed)
| Set the seed for the random number generator.
char | CoinFindDirSeparator ()
| This function figures out whether file names should contain slashes or backslashes as directory separator.
int | CoinStrNCaseCmp (const char *s0, const char *s1, const size_t len)
template<class T>
void | CoinSwap (T &x, T &y)
| Swap the arguments.
template<class T>
int | CoinToFile (const T *array, CoinBigIndex size, FILE *fp)
| This helper function copies an array to file Returns 0 if OK, 1 if bad write.
template<class T>
int | CoinFromFile (T *&array, CoinBigIndex size, FILE *fp, CoinBigIndex &newSize)
| This helper function copies an array from file and creates with new.
int | CoinStrlenAsInt (const char *string)
| This helper returns "strlen" as an int.

## Define Documentation

#define COIN_RESTRICT

Definition at line 30 of file CoinHelperFunctions.hpp.

#define COIN_OWN_RANDOM_32

Definition at line 753 of file CoinHelperFunctions.hpp.

#define CoinSizeofAsInt | ( | type |  | ) | (static_cast<int>(sizeof(type)))

This helper returns "sizeof" as an int.

Definition at line 940 of file CoinHelperFunctions.hpp.

Referenced by CoinBigIndexArrayWithLength::CoinBigIndexArrayWithLength(), CoinDoubleArrayWithLength::CoinDoubleArrayWithLength(), CoinFactorizationDoubleArrayWithLength::CoinFactorizationDoubleArrayWithLength(), CoinIntArrayWithLength::CoinIntArrayWithLength(), CoinUnsignedIntArrayWithLength::CoinUnsignedIntArrayWithLength(), CoinUnsignedIntArrayWithLength::conditionalNew(), CoinBigIndexArrayWithLength::conditionalNew(), CoinIntArrayWithLength::conditionalNew(), CoinFactorizationDoubleArrayWithLength::conditionalNew(), CoinDoubleArrayWithLength::conditionalNew(), CoinUnsignedIntArrayWithLength::getSize(), CoinBigIndexArrayWithLength::getSize(), CoinIntArrayWithLength::getSize(), CoinFactorizationDoubleArrayWithLength::getSize(), CoinDoubleArrayWithLength::getSize(), CoinUnsignedIntArrayWithLength::setSize(), CoinBigIndexArrayWithLength::setSize(), CoinIntArrayWithLength::setSize(), CoinFactorizationDoubleArrayWithLength::setSize(), and CoinDoubleArrayWithLength::setSize().

#define COIN_DETAIL_PRINT | ( | s |  | ) | {}

Definition at line 1087 of file CoinHelperFunctions.hpp.

## Function Documentation

template<class T>

void CoinCopyN | ( | register const T * | from,
|  | const int | size,
|  | register T * | to |
| ) |  |  | `[inline]`

This helper function copies an array to another location using Duff's device (for a speedup of ~2).

The arrays are given by pointers to their first entries and by the size of the source array. Overlapping arrays are handled correctly.

Definition at line 42 of file CoinHelperFunctions.hpp.

Referenced by CoinCopy(), CoinDisjointCopyN(), CoinMemcpyN(), AbcNodeDesc::setLowerBounds(), and AbcNodeDesc::setUpperBounds().

template<class T>

void CoinCopy | ( | register const T * | first,
|  | register const T * | last,
|  | register T * | to |
| ) |  |  | `[inline]`

This helper function copies an array to another location using Duff's device (for a speedup of ~2).

The source array is given by its first and "after last" entry; the target array is given by its first entry. Overlapping arrays are handled correctly.

All of the various CoinCopyN variants use an int for size. On 64-bit architectures, the address diff last-first will be a 64-bit quantity. Given that everything else uses an int, I'm going to choose to kick the difference down to int. -- lh, 100823 --

Definition at line 100 of file CoinHelperFunctions.hpp.

References CoinCopyN().

Referenced by CoinDeleteEntriesFromArray().

template<class T>

void CoinDisjointCopyN | ( | register const T * | from,
|  | const int | size,
|  | register T * | to |
| ) |  |  | `[inline]`

This helper function copies an array to another location.

The two arrays must not overlap (otherwise an exception is thrown). For speed 8 entries are copied at a time. The arrays are given by pointers to their first entries and by the size of the source array.

Note JJF - the speed claim seems to be false on IA32 so I have added CoinMemcpyN which can be used for atomic data

Definition at line 115 of file CoinHelperFunctions.hpp.

References CoinCopyN().

Referenced by CoinDisjointCopy(), CoinTreeSiblings::CoinTreeSiblings(), CoinWarmStartVector< U >::CoinWarmStartVector(), and CoinWarmStartVector< U >::gutsOfCopy().

template<class T>

void CoinDisjointCopy | ( | register const T * | first,
|  | register const T * | last,
|  | register T * | to |
| ) |  |  | `[inline]`

This helper function copies an array to another location.

The two arrays must not overlap (otherwise an exception is thrown). For speed 8 entries are copied at a time. The source array is given by its first and "after last" entry; the target array is given by its first entry.

Definition at line 168 of file CoinHelperFunctions.hpp.

References CoinDisjointCopyN().

Referenced by CoinDeleteEntriesFromArray().

template<class T>

T* CoinCopyOfArray | ( | const T * | array,
|  | const int | size |
| ) |  |  | `[inline]`

Return an array of length `size` filled with input from `array`, or null if `array` is null.

Definition at line 181 of file CoinHelperFunctions.hpp.

template<class T>

T* CoinCopyOfArrayPartial | ( | const T * | array,
|  | const int | size,
|  | const int | copySize |
| ) |  |  | `[inline]`

Return an array of length `size` filled with first copySize from `array`, or null if `array` is null.

Definition at line 198 of file CoinHelperFunctions.hpp.

template<class T>

T* CoinCopyOfArray | ( | const T * | array,
|  | const int | size,
|  | T | value |
| ) |  |  | `[inline]`

Return an array of length `size` filled with input from `array`, or filled with (scalar) `value` if `array` is null.

Definition at line 215 of file CoinHelperFunctions.hpp.

template<class T>

T* CoinCopyOfArrayOrZero | ( | const T * | array,
|  | const int | size |
| ) |  |  | `[inline]`

Return an array of length `size` filled with input from `array`, or filled with zero if `array` is null.

Definition at line 234 of file CoinHelperFunctions.hpp.

template<class T>

void CoinMemcpyN | ( | register const T * | from,
|  | const int | size,
|  | register T * | to |
| ) |  |  | `[inline]`

This helper function copies an array to another location.

The two arrays must not overlap (otherwise an exception is thrown). For speed 8 entries are copied at a time. The arrays are given by pointers to their first entries and by the size of the source array.

Note JJF - the speed claim seems to be false on IA32 so I have added alternative coding if USE_MEMCPY defined

Definition at line 257 of file CoinHelperFunctions.hpp.

References CoinCopyN().

Referenced by c_ekkdcpy(), c_ekkscpy(), CoinMemcpy(), and CoinStrdup().

template<class T>

void CoinMemcpy | ( | register const T * | first,
|  | register const T * | last,
|  | register T * | to |
| ) |  |  | `[inline]`

This helper function copies an array to another location.

The two arrays must not overlap (otherwise an exception is thrown). For speed 8 entries are copied at a time. The source array is given by its first and "after last" entry; the target array is given by its first entry.

Definition at line 344 of file CoinHelperFunctions.hpp.

References CoinMemcpyN().

template<class T>

void CoinFillN | ( | register T * | to,
|  | const int | size,
|  | register const T | value |
| ) |  |  | `[inline]`

This helper function fills an array with a given value.

For speed 8 entries are filled at a time. The array is given by a pointer to its first entry and its size.

Note JJF - the speed claim seems to be false on IA32 so I have added CoinZero to allow for memset.

Definition at line 359 of file CoinHelperFunctions.hpp.

Referenced by CoinFill().

template<class T>

void CoinFill | ( | register T * | first,
|  | register T * | last,
|  | const T | value |
| ) |  |  | `[inline]`

This helper function fills an array with a given value.

For speed 8 entries are filled at a time. The array is given by its first and "after last" entry.

Definition at line 414 of file CoinHelperFunctions.hpp.

References CoinFillN().

template<class T>

void CoinZeroN | ( | register T * | to,
|  | const int | size |
| ) |  |  | `[inline]`

This helper function fills an array with zero.

For speed 8 entries are filled at a time. The array is given by a pointer to its first entry and its size.

Note JJF - the speed claim seems to be false on IA32 so I have allowed for memset as an alternative

Definition at line 428 of file CoinHelperFunctions.hpp.

Referenced by c_ekkczero(), c_ekkdzero(), c_ekkizero(), and CoinZero().

void CoinCheckDoubleZero | ( | double * | to,
|  | const int | size |
| ) |  |  | `[inline]`

This Debug helper function checks an array is all zero.

Definition at line 489 of file CoinHelperFunctions.hpp.

void CoinCheckIntZero | ( | int * | to,
|  | const int | size |
| ) |  |  | `[inline]`

This Debug helper function checks an array is all zero.

Definition at line 502 of file CoinHelperFunctions.hpp.

template<class T>

void CoinZero | ( | register T * | first,
|  | register T * | last |
| ) |  |  | `[inline]`

This helper function fills an array with a given value.

For speed 8 entries are filled at a time. The array is given by its first and "after last" entry.

Definition at line 520 of file CoinHelperFunctions.hpp.

References CoinZeroN().

char* CoinStrdup | ( | const char * | name | ) | `[inline]`

Returns strdup or NULL if original NULL.

Definition at line 528 of file CoinHelperFunctions.hpp.

References CoinMemcpyN().

template<class T>

T CoinMax | ( | register const T | x1,
|  | register const T | x2 |
| ) |  |  | `[inline]`

Return the larger (according to `operator<()` of the arguments.

This function was introduced because for some reason compiler tend to handle the `max()` function differently.

Definition at line 546 of file CoinHelperFunctions.hpp.

Referenced by CoinDenseVector< T >::infNorm().

template<class T>

T CoinMin | ( | register const T | x1,
|  | register const T | x2 |
| ) |  |  | `[inline]`

Return the smaller (according to `operator<()` of the arguments.

This function was introduced because for some reason compiler tend to handle the min() function differently.

Definition at line 557 of file CoinHelperFunctions.hpp.

template<class T>

T CoinAbs | ( | const T | value | ) | `[inline]`

Return the absolute value of the argument.

This function was introduced because for some reason compiler tend to handle the abs() function differently.

Definition at line 568 of file CoinHelperFunctions.hpp.

Referenced by CoinDenseVector< T >::infNorm(), and CoinDenseVector< T >::oneNorm().

template<class T>

bool CoinIsSorted | ( | register const T * | first,
|  | const int | size |
| ) |  |  | `[inline]`

This helper function tests whether the entries of an array are sorted according to operator<.

The array is given by a pointer to its first entry and by its size.

Definition at line 579 of file CoinHelperFunctions.hpp.

Referenced by CoinDeleteEntriesFromArray(), and CoinIsSorted().

template<class T>

bool CoinIsSorted | ( | register const T * | first,
|  | register const T * | last |
| ) |  |  | `[inline]`

This helper function tests whether the entries of an array are sorted according to operator<.

The array is given by its first and "after last" entry.

Definition at line 628 of file CoinHelperFunctions.hpp.

References CoinIsSorted().

template<class T>

void CoinIotaN | ( | register T * | first,
|  | const int | size,
|  | register T | init |
| ) |  |  | `[inline]`

This helper function fills an array with the values init, init+1, init+2, etc.

For speed 8 entries are filled at a time. The array is given by a pointer to its first entry and its size.

Definition at line 639 of file CoinHelperFunctions.hpp.

Referenced by CoinIota().

template<class T>

void CoinIota | ( | T * | first,
|  | const T * | last,
|  | T | init |
| ) |  |  | `[inline]`

This helper function fills an array with the values init, init+1, init+2, etc.

For speed 8 entries are filled at a time. The array is given by its first and "after last" entry.

Definition at line 694 of file CoinHelperFunctions.hpp.

References CoinIotaN().

template<class T>

T* CoinDeleteEntriesFromArray | ( | register T * | arrayFirst,
|  | register T * | arrayLast,
|  | const int * | firstDelPos,
|  | const int * | lastDelPos |
| ) |  |  | `[inline]`

This helper function deletes certain entries from an array.

The array is given by pointers to its first and "after last" entry (first two arguments). The positions of the entries to be deleted are given in the integer array specified by the last two arguments (again, first and "after last" entry).

Definition at line 707 of file CoinHelperFunctions.hpp.

References CoinCopy(), CoinDisjointCopy(), and CoinIsSorted().

double CoinDrand48 | ( | bool | isSeed = `false`,
|  | unsigned int | seed = `1` |
| ) |  |  | `[inline]`

Return a random number between 0 and 1.

A platform-independent linear congruential generator. For a given seed, the generated sequence is always the same regardless of the (32-bit) architecture. This allows to build & test in different environments, getting in most cases the same optimization path.

Set `isSeed` to true and supply an integer seed to set the seed (vid. CoinSeedRandom)

Todo:
  Anyone want to volunteer an upgrade for 64-bit architectures?

Definition at line 771 of file CoinHelperFunctions.hpp.

Referenced by CoinSeedRandom().

void CoinSeedRandom | ( | int | iseed | ) | `[inline]`

Set the seed for the random number generator.

Definition at line 784 of file CoinHelperFunctions.hpp.

References CoinDrand48().

char CoinFindDirSeparator | ( |  | ) | `[inline]`

This function figures out whether file names should contain slashes or backslashes as directory separator.

Definition at line 813 of file CoinHelperFunctions.hpp.

int CoinStrNCaseCmp | ( | const char * | s0,
|  | const char * | s1,
|  | const size_t | len |
| ) |  |  | `[inline]`

Definition at line 833 of file CoinHelperFunctions.hpp.

template<class T>

void CoinSwap | ( | T & | x,
|  | T & | y |
| ) |  |  | `[inline]`

Swap the arguments.

Definition at line 856 of file CoinHelperFunctions.hpp.

template<class T>

int CoinToFile | ( | const T * | array,
|  | CoinBigIndex | size,
|  | FILE * | fp |
| ) |  |  | `[inline]`

This helper function copies an array to file Returns 0 if OK, 1 if bad write.

Definition at line 870 of file CoinHelperFunctions.hpp.

template<class T>

int CoinFromFile | ( | T *& | array,
|  | CoinBigIndex | size,
|  | FILE * | fp,
|  | CoinBigIndex & | newSize |
| ) |  |  | `[inline]`

This helper function copies an array from file and creates with new.

Passed in array is ignored i.e. not deleted. But if NULL and size does not match and newSize 0 then leaves as NULL and 0 Returns 0 if OK, 1 if bad read, 2 if size did not match.

Definition at line 901 of file CoinHelperFunctions.hpp.

int CoinStrlenAsInt | ( | const char * | string | ) | `[inline]`

This helper returns "strlen" as an int.

Definition at line 943 of file CoinHelperFunctions.hpp.