SALSA Analysis Modules
Data Structures | Defines | Functions
anamodutils.c File Reference
#include <stdlib.h>
#include "string.h"
#include "anamod.h"
Include dependency graph for anamodutils.c:

Go to the source code of this file.

Data Structures

struct  IntArray_
struct  StringArray_
struct  AnalysisItemArray_
struct  AnalysisDataTypeArray_

Defines

#define NALLOC   70

Functions

PetscErrorCode CreateIntArray (const char *name, int size, IntArray *array)
PetscErrorCode DeleteIntArray (IntArray array)
PetscErrorCode IntArrayAdd (IntArray array, int val, int *idx)
PetscErrorCode IntArraySetAt (IntArray array, int idx, int val)
PetscErrorCode IntArrayTryGetAt (IntArray array, int idx, int *val, PetscTruth *has)
PetscErrorCode IntArrayGetAt (IntArray array, int idx, int *val)
PetscErrorCode CreateStringArray (const char *name, int size, StringArray *array)
PetscErrorCode DeleteStringArray (StringArray array)
PetscErrorCode StringArrayAdd (StringArray array, const char *val, int *idx)
PetscErrorCode StringArrayGetFill (StringArray array, int *idx)
PetscErrorCode StringArraySetAt (StringArray array, int idx, const char *val)
PetscErrorCode StringArrayTryGetAt (StringArray array, int idx, char **val, PetscTruth *has)
PetscErrorCode StringArrayGetAt (StringArray array, int idx, char **val)
PetscErrorCode CreateAnalysisItemArray (const char *name, int size, AnalysisItemArray *array)
PetscErrorCode DeleteAnalysisItemArray (AnalysisItemArray array)
PetscErrorCode AnalysisItemArrayAdd (AnalysisItemArray array, AnalysisItem val, int *idx)
PetscErrorCode AnalysisItemArraySetAt (AnalysisItemArray array, int idx, AnalysisItem val)
PetscErrorCode AnalysisItemArrayTryGetAt (AnalysisItemArray array, int idx, AnalysisItem *val, PetscTruth *has)
PetscErrorCode AnalysisItemArrayGetAt (AnalysisItemArray array, int idx, AnalysisItem *val)
PetscErrorCode CreateAnalysisDataTypeArray (const char *name, int size, AnalysisDataTypeArray *array)
PetscErrorCode DeleteAnalysisDataTypeArray (AnalysisDataTypeArray array)
PetscErrorCode AnalysisDataTypeArrayAdd (AnalysisDataTypeArray array, AnalysisDataType val, int *idx)
PetscErrorCode AnalysisDataTypeArraySetAt (AnalysisDataTypeArray array, int idx, AnalysisDataType val)
PetscErrorCode AnalysisDataTypeArrayTryGetAt (AnalysisDataTypeArray array, int idx, AnalysisDataType *val, PetscTruth *has)
PetscErrorCode AnalysisDataTypeArrayGetAt (AnalysisDataTypeArray array, int idx, AnalysisDataType *val)

Define Documentation

#define NALLOC   70

Function Documentation

PetscErrorCode AnalysisDataTypeArrayAdd ( AnalysisDataTypeArray  array,
AnalysisDataType  val,
int *  idx 
)

Add a new value and return the index. Right now we do not yet dynamically reallocate the array if there is no more space.

Definition at line 372 of file anamodutils.c.

References AnalysisDataTypeArray_::alloc, AnalysisDataTypeArray_::data, AnalysisDataTypeArray_::fill, and AnalysisDataTypeArray_::has.

{
  int ins;
  PetscFunctionBegin;
  if (array->fill>=array->alloc-1) SETERRQ(1,"No more space");
  ins = array->fill++;
  array->data[ins] = val;
  array->has[ins] = PETSC_TRUE;
  PetscFunctionReturn(0);
}
PetscErrorCode AnalysisDataTypeArrayGetAt ( AnalysisDataTypeArray  array,
int  idx,
AnalysisDataType val 
)

As AnalysisDataTypeArrayTryGetAt(), except that it is an error to ask for an index where no value has been set.

Definition at line 424 of file anamodutils.c.

References AnalysisDataTypeArray_::alloc, AnalysisDataTypeArray_::data, and AnalysisDataTypeArray_::has.

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx);
  *val = array->data[idx];
  PetscFunctionReturn(0);
}
PetscErrorCode AnalysisDataTypeArraySetAt ( AnalysisDataTypeArray  array,
int  idx,
AnalysisDataType  val 
)

Set a value at a given index. Right now we do not yet dynamically reallocate the array if the index is out of bound.

Definition at line 388 of file anamodutils.c.

References AnalysisDataTypeArray_::alloc, AnalysisDataTypeArray_::data, AnalysisDataTypeArray_::fill, and AnalysisDataTypeArray_::has.

Referenced by InstantiateFeatureSet().

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  array->data[idx] = val; array->has[idx] = PETSC_TRUE;
  if (idx>array->fill) array->fill = idx;
  PetscFunctionReturn(0);
}
PetscErrorCode AnalysisDataTypeArrayTryGetAt ( AnalysisDataTypeArray  array,
int  idx,
AnalysisDataType val,
PetscTruth *  has 
)

Retrieve data from a given index.

Arguments:

  • array : the AnalysisDataTypeArray object
  • idx : the index; it is an error to ask out of bounds, but not to ask beyond the highest position filled; in that case failure will be reported
  • val (output) : the value retrieved. This argument is allowed to be null.
  • has (output) : true if a value was stored at this index. This argument is allowed to be null.

Definition at line 410 of file anamodutils.c.

References AnalysisDataTypeArray_::alloc, AnalysisDataTypeArray_::data, and AnalysisDataTypeArray_::has.

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  if (has) *has = (PetscTruth)array->has[idx];
  if (array->has[idx] && val) *val = array->data[idx];
  PetscFunctionReturn(0);
}
PetscErrorCode AnalysisItemArrayAdd ( AnalysisItemArray  array,
AnalysisItem  val,
int *  idx 
)

Add a new value and return the index. Right now we do not yet dynamically reallocate the array if there is no more space.

Definition at line 267 of file anamodutils.c.

References AnalysisItemArray_::alloc, AnalysisItemArray_::data, AnalysisItemArray_::fill, and AnalysisItemArray_::has.

{
  int ins;
  PetscFunctionBegin;
  if (array->fill>=array->alloc-1) SETERRQ(1,"No more space");
  ins = array->fill++;
  array->data[ins] = val;
  array->has[ins] = PETSC_TRUE;
  PetscFunctionReturn(0);
}
PetscErrorCode AnalysisItemArrayGetAt ( AnalysisItemArray  array,
int  idx,
AnalysisItem val 
)

As AnalysisItemArrayTryGetAt(), except that it is an error to ask for an index where no value has been set.

Definition at line 319 of file anamodutils.c.

References AnalysisItemArray_::alloc, AnalysisItemArray_::data, and AnalysisItemArray_::has.

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx);
  *val = array->data[idx];
  PetscFunctionReturn(0);
}
PetscErrorCode AnalysisItemArraySetAt ( AnalysisItemArray  array,
int  idx,
AnalysisItem  val 
)

Set a value at a given index. Right now we do not yet dynamically reallocate the array if the index is out of bound.

Definition at line 283 of file anamodutils.c.

References AnalysisItemArray_::alloc, AnalysisItemArray_::data, AnalysisItemArray_::fill, and AnalysisItemArray_::has.

Referenced by InstantiateFeatureSet().

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  array->data[idx] = val; array->has[idx] = PETSC_TRUE;
  if (idx>array->fill) array->fill = idx;
  PetscFunctionReturn(0);
}
PetscErrorCode AnalysisItemArrayTryGetAt ( AnalysisItemArray  array,
int  idx,
AnalysisItem val,
PetscTruth *  has 
)

Retrieve data from a given index.

Arguments:

  • array : the AnalysisItemArray object
  • idx : the index; it is an error to ask out of bounds, but not to ask beyond the highest position filled; in that case failure will be reported
  • val (output) : the value retrieved. This argument is allowed to be null.
  • has (output) : true if a value was stored at this index. This argument is allowed to be null.

Definition at line 305 of file anamodutils.c.

References AnalysisItemArray_::alloc, AnalysisItemArray_::data, and AnalysisItemArray_::has.

Referenced by GetFeatureValue().

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  if (has) *has = (PetscTruth)array->has[idx];
  if (array->has[idx] && val) *val = array->data[idx];
  PetscFunctionReturn(0);
}
PetscErrorCode CreateAnalysisDataTypeArray ( const char *  name,
int  size,
AnalysisDataTypeArray array 
)

Definition at line 338 of file anamodutils.c.

References AnalysisDataTypeArray_::alloc, AnalysisDataTypeArray_::data, AnalysisDataTypeArray_::fill, AnalysisDataTypeArray_::has, NALLOC, and AnalysisDataTypeArray_::name.

Referenced by NewFeatureValues().

{
  AnalysisDataTypeArray anew; PetscErrorCode ierr;
  PetscFunctionBegin;
  ierr = PetscMalloc(sizeof(struct AnalysisDataTypeArray_),&anew); CHKERRQ(ierr);
  ierr = PetscMemzero(anew,sizeof(struct AnalysisDataTypeArray_)); CHKERRQ(ierr);
  if (name) anew->name = strdup(name);
  anew->fill = 0; anew->alloc = NALLOC;
  ierr = PetscMalloc(anew->alloc*sizeof(PetscTruth),&(anew->has)); CHKERRQ(ierr);
  ierr = PetscMemzero(anew->has,anew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr);
  ierr = PetscMalloc(anew->alloc*sizeof(AnalysisDataType),&(anew->data)); CHKERRQ(ierr);
  ierr = PetscMemzero(anew->data,anew->alloc*sizeof(AnalysisDataType)); CHKERRQ(ierr);
  *array = anew;
  PetscFunctionReturn(0);
}
PetscErrorCode CreateAnalysisItemArray ( const char *  name,
int  size,
AnalysisItemArray array 
)

Definition at line 233 of file anamodutils.c.

References AnalysisItemArray_::alloc, AnalysisItemArray_::data, AnalysisItemArray_::fill, AnalysisItemArray_::has, NALLOC, and AnalysisItemArray_::name.

Referenced by NewFeatureValues().

{
  AnalysisItemArray anew; PetscErrorCode ierr;
  PetscFunctionBegin;
  ierr = PetscMalloc(sizeof(struct AnalysisItemArray_),&anew); CHKERRQ(ierr);
  ierr = PetscMemzero(anew,sizeof(struct AnalysisItemArray_)); CHKERRQ(ierr);
  if (name) anew->name = strdup(name);
  anew->fill = 0; anew->alloc = NALLOC;
  ierr = PetscMalloc(anew->alloc*sizeof(PetscTruth),&(anew->has)); CHKERRQ(ierr);
  ierr = PetscMemzero(anew->has,anew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr);
  ierr = PetscMalloc(anew->alloc*sizeof(AnalysisItem),&(anew->data)); CHKERRQ(ierr);
  ierr = PetscMemzero(anew->data,anew->alloc*sizeof(AnalysisItem)); CHKERRQ(ierr);
  *array = anew;
  PetscFunctionReturn(0);
}
PetscErrorCode CreateIntArray ( const char *  name,
int  size,
IntArray array 
)

Definition at line 13 of file anamodutils.c.

References IntArray_::alloc, IntArray_::data, IntArray_::fill, IntArray_::has, NALLOC, and IntArray_::name.

Referenced by NewFeatureSet().

{
  IntArray inew; PetscErrorCode ierr;
  PetscFunctionBegin;
  ierr = PetscMalloc(sizeof(struct IntArray_),&inew); CHKERRQ(ierr);
  ierr = PetscMemzero(inew,sizeof(struct IntArray_)); CHKERRQ(ierr);
  if (name) inew->name = strdup(name);
  inew->fill = 0; inew->alloc = NALLOC;
  ierr = PetscMalloc(inew->alloc*sizeof(PetscTruth),&(inew->has)); CHKERRQ(ierr);
  ierr = PetscMemzero(inew->has,inew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr);
  ierr = PetscMalloc(inew->alloc*sizeof(int),&(inew->data)); CHKERRQ(ierr);
  ierr = PetscMemzero(inew->data,inew->alloc*sizeof(int)); CHKERRQ(ierr);
  *array = inew;
  PetscFunctionReturn(0);
}
PetscErrorCode CreateStringArray ( const char *  name,
int  size,
StringArray array 
)

Definition at line 117 of file anamodutils.c.

References StringArray_::alloc, StringArray_::data, StringArray_::fill, StringArray_::has, NALLOC, and StringArray_::name.

Referenced by NewFeatureSet().

{
  StringArray snew; PetscErrorCode ierr;
  PetscFunctionBegin;
  ierr = PetscMalloc(sizeof(struct StringArray_),&snew); CHKERRQ(ierr);
  ierr = PetscMemzero(snew,sizeof(struct StringArray_)); CHKERRQ(ierr);
  if (name) snew->name = strdup(name);
  snew->fill = 0; snew->alloc = NALLOC;
  ierr = PetscMalloc(snew->alloc*sizeof(PetscTruth),&(snew->has)); CHKERRQ(ierr);
  ierr = PetscMemzero(snew->has,snew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr);
  ierr = PetscMalloc(snew->alloc*sizeof(char*),&(snew->data)); CHKERRQ(ierr);
  ierr = PetscMemzero(snew->data,snew->alloc*sizeof(char*)); CHKERRQ(ierr);
  *array = snew;
  PetscFunctionReturn(0);
}
PetscErrorCode DeleteAnalysisDataTypeArray ( AnalysisDataTypeArray  array)

Definition at line 356 of file anamodutils.c.

References AnalysisDataTypeArray_::data, AnalysisDataTypeArray_::has, and AnalysisDataTypeArray_::name.

Referenced by DeleteFeatureValues().

{
  PetscErrorCode ierr;
  PetscFunctionBegin;
  ierr = PetscFree(array->data); CHKERRQ(ierr);
  ierr = PetscFree(array->has); CHKERRQ(ierr);
  if (array->name) free(array->name);
  ierr = PetscFree(array); CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
PetscErrorCode DeleteAnalysisItemArray ( AnalysisItemArray  array)

Definition at line 251 of file anamodutils.c.

References AnalysisItemArray_::data, AnalysisItemArray_::has, and AnalysisItemArray_::name.

Referenced by DeleteFeatureValues().

{
  PetscErrorCode ierr;
  PetscFunctionBegin;
  ierr = PetscFree(array->data); CHKERRQ(ierr);
  ierr = PetscFree(array->has); CHKERRQ(ierr);
  if (array->name) free(array->name);
  ierr = PetscFree(array); CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
PetscErrorCode DeleteIntArray ( IntArray  array)

Definition at line 31 of file anamodutils.c.

References IntArray_::data, IntArray_::has, and IntArray_::name.

Referenced by DeleteFeatureSet().

{
  PetscErrorCode ierr;
  PetscFunctionBegin;
  ierr = PetscFree(array->data); CHKERRQ(ierr);
  ierr = PetscFree(array->has); CHKERRQ(ierr);
  if (array->name) free(array->name);
  ierr = PetscFree(array); CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
PetscErrorCode DeleteStringArray ( StringArray  array)

Definition at line 135 of file anamodutils.c.

References StringArray_::data, StringArray_::fill, StringArray_::has, and StringArray_::name.

Referenced by DeleteFeatureSet().

{
  int i; PetscErrorCode ierr;
  PetscFunctionBegin;
  for (i=0; i<array->fill; i++)
    if (array->has[i]) free(array->data[i]);
  ierr = PetscFree(array->data); CHKERRQ(ierr);
  ierr = PetscFree(array->has); CHKERRQ(ierr);
  if (array->name) free(array->name);
  ierr = PetscFree(array); CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
PetscErrorCode IntArrayAdd ( IntArray  array,
int  val,
int *  idx 
)

Add a new value and return the index. Right now we do not yet dynamically reallocate the array if there is no more space.

Definition at line 47 of file anamodutils.c.

References IntArray_::alloc, IntArray_::data, IntArray_::fill, and IntArray_::has.

{
  int ins;
  PetscFunctionBegin;
  if (array->fill>=array->alloc-1) SETERRQ(1,"No more space");
  ins = array->fill++;
  array->data[ins] = val;
  array->has[ins] = PETSC_TRUE;
  PetscFunctionReturn(0);
}
PetscErrorCode IntArrayGetAt ( IntArray  array,
int  idx,
int *  val 
)

As IntArrayTryGetAt(), except that it is an error to ask for an index where no value has been set.

Definition at line 99 of file anamodutils.c.

References IntArray_::alloc, IntArray_::data, and IntArray_::has.

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx);
  *val = array->data[idx];
  PetscFunctionReturn(0);
}
PetscErrorCode IntArraySetAt ( IntArray  array,
int  idx,
int  val 
)

Set a value at a given index. Right now we do not yet dynamically reallocate the array if the index is out of bound.

Definition at line 63 of file anamodutils.c.

References IntArray_::alloc, IntArray_::data, IntArray_::fill, and IntArray_::has.

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  array->data[idx] = val; array->has[idx] = PETSC_TRUE;
  if (idx>array->fill) array->fill = idx;
  PetscFunctionReturn(0);
}
PetscErrorCode IntArrayTryGetAt ( IntArray  array,
int  idx,
int *  val,
PetscTruth *  has 
)

Retrieve data from a given index.

Arguments:

  • array : the IntArray object
  • idx : the index; it is an error to ask out of bounds, but not to ask beyond the highest position filled; in that case failure will be reported
  • val (output) : the value retrieved. This argument is allowed to be null.
  • has (output) : true if a value was stored at this index. This argument is allowed to be null.

Definition at line 85 of file anamodutils.c.

References IntArray_::alloc, IntArray_::data, and IntArray_::has.

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  if (has) *has = array->has[idx];
  if (array->has[idx] && val) *val = array->data[idx];
  PetscFunctionReturn(0);
}
PetscErrorCode StringArrayAdd ( StringArray  array,
const char *  val,
int *  idx 
)

Add a new value and return the index. Right now we do not yet dynamically reallocate the array if there is no more space.

Definition at line 153 of file anamodutils.c.

References StringArray_::alloc, StringArray_::data, StringArray_::fill, and StringArray_::has.

Referenced by AddToFeatureSet().

{
  int ins;
  PetscFunctionBegin;
  if (array->fill>=array->alloc-1) SETERRQ(1,"No more space");
  ins = array->fill++;
  array->data[ins] = strdup(val);
  array->has[ins] = PETSC_TRUE;
  PetscFunctionReturn(0);
}
PetscErrorCode StringArrayGetAt ( StringArray  array,
int  idx,
char **  val 
)

As StringArrayTryGetAt(), except that it is an error to ask for an index where no value has been set.

Definition at line 214 of file anamodutils.c.

References StringArray_::alloc, StringArray_::data, and StringArray_::has.

Referenced by InstantiateFeatureSet().

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx);
  *val = array->data[idx];
  PetscFunctionReturn(0);
}
PetscErrorCode StringArrayGetFill ( StringArray  array,
int *  idx 
)

Definition at line 166 of file anamodutils.c.

References StringArray_::fill.

Referenced by InstantiateFeatureSet().

{
  PetscFunctionBegin;
  *idx = array->fill;
  PetscFunctionReturn(0);
}
PetscErrorCode StringArraySetAt ( StringArray  array,
int  idx,
const char *  val 
)

Set a value at a given index. Right now we do not yet dynamically reallocate the array if the index is out of bound.

Definition at line 178 of file anamodutils.c.

References StringArray_::alloc, StringArray_::data, StringArray_::fill, and StringArray_::has.

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  array->data[idx] = strdup(val); array->has[idx] = PETSC_TRUE;
  if (idx>array->fill) array->fill = idx;
  PetscFunctionReturn(0);
}
PetscErrorCode StringArrayTryGetAt ( StringArray  array,
int  idx,
char **  val,
PetscTruth *  has 
)

Retrieve data from a given index.

Arguments:

  • array : the StringArray object
  • idx : the index; it is an error to ask out of bounds, but not to ask beyond the highest position filled; in that case failure will be reported
  • val (output) : the value retrieved. This argument is allowed to be null.
  • has (output) : true if a value was stored at this index. This argument is allowed to be null.

Definition at line 200 of file anamodutils.c.

References StringArray_::alloc, StringArray_::data, and StringArray_::has.

{
  PetscFunctionBegin;
  if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
  if (has) *has = array->has[idx];
  if (array->has[idx] && val) *val = array->data[idx];
  PetscFunctionReturn(0);
}