ACT Library
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Array Class Reference

Dense arrays, sparse arrays, and array dereferences. More...

#include <act_array.h>

Classes

struct  _act_array_expr_pair
 A range specifier that can include parameters/etc. This is used during parsing, prior to expansion. More...
 
struct  _act_array_exprex_pair
 A range specifier post expansion where all parameters/etc. are substituted, resulting in a constant range. More...
 
struct  _act_array_internal
 Used to hold the result of an expanded array range reference. More...
 
struct  range
 

Public Member Functions

int isSparse ()
 
int isDeref ()
 
void mkArray ()
 
int nDims ()
 
int effDims ()
 
void Concat (Array *a)
 
void preConcat (Array *a)
 
int isEqual (Array *a, int strict)
 
int isDimCompatible (Array *a)
 
void Merge (Array *a)
 
 Array (Expr *e, Expr *f=NULL)
 
 Array (int lo, int hi)
 
 Array (int idx)
 
 ~Array ()
 
void Print (FILE *fp, int style=0)
 
void sPrint (char *buf, int sz, int style=0)
 
int sPrintOne (char *buf, int sz, int style=0)
 
void PrintOne (FILE *fp, int style=0)
 
ArrayNext ()
 
ArrayClone ()
 returns a deep copy of the entire array
 
ArrayCloneOne ()
 only return a deep copy of the current dense range
 
ArrayReduce ()
 
int isExpanded ()
 
int size ()
 
int range_size (int d)
 
void update_range (int d, int lo, int hi)
 
int isrange (int d)
 
Exprlo (int d)
 
Exprhi (int d)
 
ArrayExpand (ActNamespace *ns, Scope *s, int is_ref=0)
 
ArrayExpandRef (ActNamespace *ns, Scope *s)
 
ArrayExpandRefCHP (ActNamespace *ns, Scope *s)
 
int Validate (Array *a)
 
int isDynamicDeref ()
 
ExprgetDeref (int idx)
 
int Offset (Array *a)
 
int Offset (int *a)
 
ArrayunOffset (int offset)
 
Arraystepstepper (Array *sub=NULL)
 

Private Member Functions

 Array ()
 
int in_range (Array *a)
 offset within a range, -1 if missing
 
int in_range (int *a)
 offset within a range, -1 if missing
 
void dumprange (struct range *r)
 
void _merge_range (int idx, Array *prev, struct range *m)
 
int overlapping (struct range *a, struct range *b)
 

Private Attributes

int dims
 
struct Array::ranger
 
unsigned int range_sz
 
Arraynext
 
unsigned int deref:1
 
unsigned int expanded:1
 

Friends

class Arraystep
 

Detailed Description

Dense arrays, sparse arrays, and array dereferences.

Used to represent a set of dense ranges/derefs If a sub-range specifier is not used, then the "deref" field is set to 1—it means the user wrote [x] rather than [x..y] for every dimension of the array.

This class is also used to represent a sparse array. In this case, the array is represented as a list of dense sub-arrays. The next field is used to build the linked list of dense components of the sparse array.

This class is also used to represent a "de-reference" as part of an identifier. De-references are either constant values, or may contain a variable (e.g. a de-reference within a CHP body). De-references with variables are called "dynamic", because their value cannot be determined statically.

The elements within an array are also numbered sequentially. This provides a linear addressing mechanism for the array elements, making it simple to write loops that iterate over the array. The numbers are from 0 to size()-1. This numbering can be used once the array is expanded for arrays that are not de-references.

Constructor & Destructor Documentation

◆ Array() [1/4]

Array::Array ( Expr e,
Expr f = NULL 
)

Create a new one-dimensional dense unexpanded array.

Parameters
eis an integer expression corresponding to the size of the array
fis an integer expression. If f is not NULL, then the array range is e..f; otherwise it is 0..(e-1).

◆ Array() [2/4]

Array::Array ( int  lo,
int  hi 
)

Create a new one-dimensional dense expanded array.

Parameters
lois the low end of the range
hiis the high end of the range

◆ Array() [3/4]

Array::Array ( int  idx)

Create a de-reference corresponding to the specified index

Parameters
idxis the index of the de-reference

◆ ~Array()

Array::~Array ( )

◆ Array() [4/4]

Array::Array ( )
private

for deep copy only

Member Function Documentation

◆ _merge_range()

void Array::_merge_range ( int  idx,
Array prev,
struct range m 
)
private

Used to merge a range into the current array. This is the ordered merge algorithm used to have a canonical representation of a sparse array as a collection of dense blocks.

Parameters
idxis the dimension to be merged
previs the previous (if any) pointer for the array
mis the new range to be merged in

◆ Clone()

Array * Array::Clone ( )

returns a deep copy of the entire array

◆ CloneOne()

Array * Array::CloneOne ( )

only return a deep copy of the current dense range

◆ Concat()

void Array::Concat ( Array a)

Append array dimensions from the argument into the current array. The current array must be dense.

Parameters
acontains the arguments to be merged, which must be a dense array

Updates the current array with the additional dimensions from parameter a

◆ dumprange()

void Array::dumprange ( struct range r)
private

used for debugging

◆ effDims()

int Array::effDims ( )
Returns
the effective number of dimensions, taking partial de-references into account. If this is a sparse array, it is just nDims()

◆ Expand()

Array * Array::Expand ( ActNamespace ns,
Scope s,
int  is_ref = 0 
)

Return expanded array.

Parameters
nsis the namespace
sis the scope for evaluation
is_ref1 if it is on the rhs of an ID, 0 if it is for a type.

◆ ExpandRef()

Array * Array::ExpandRef ( ActNamespace ns,
Scope s 
)
inline

Returns an expanded array for an Array that is part of an ActId. This simply calls Expand() with is_ref set to 1.

Parameters
nsis the namespace
sis the evaluation scope
Returns
new expanded array

◆ ExpandRefCHP()

Array * Array::ExpandRefCHP ( ActNamespace ns,
Scope s 
)

Returns an expanded array for an Array that is part of an ActId in a CHP body. This permits dynamic references.

Parameters
nsis the namespace
sis the evaluation scope
Returns
the expanded array

◆ getDeref()

Expr * Array::getDeref ( int  idx)

Must be called on an expanded array that is in fact an array dereference.

Parameters
idxis the dimension of the array of interest
Returns
the Expr corresponding to the de-reference at the specified dimension

◆ hi()

Expr * Array::hi ( int  d)
inline

Returns the hi expression for dimension d This only works for unexpanded arrays.

Parameters
dis the dimension of interest

◆ in_range() [1/2]

int Array::in_range ( Array a)
private

offset within a range, -1 if missing

◆ in_range() [2/2]

int Array::in_range ( int *  a)
private

offset within a range, -1 if missing

◆ isDeref()

int Array::isDeref ( )
inline
Returns
1 if this is an array dereference, rather than a sub-array specification

◆ isDimCompatible()

int Array::isDimCompatible ( Array a)

Check if two arrays have compatible parameters (matching dimensions)

◆ isDynamicDeref()

int Array::isDynamicDeref ( )

Checks to see if this array includes a dynamic de-reference

Returns
1 if this is a dynamic de-reference, 0 otherwise

◆ isEqual()

int Array::isEqual ( Array a,
int  strict 
)

Check if two array derefs are identical. If the arrays are not expanded, then the syntax of the expressions are checked in a strict manner. If the arrays are expanded, then the values are checked.

Parameters
ais the other array for comparison
strictis 1 if the low and high indices must match; 0 means the sizes must match.

◆ isExpanded()

int Array::isExpanded ( )
inline

returns 1 if this is an expanded array, 0 otherwise

◆ isrange()

int Array::isrange ( int  d)
inline
Returns
1 if dimension d is in fact a range, 0 otherwise

◆ isSparse()

int Array::isSparse ( )
inline
Returns
1 if this is a sparse array specification, 0 otherwise

◆ lo()

Expr * Array::lo ( int  d)
inline

Returns the lo expression for dimension d This only works for unexpanded arrays.

Parameters
dis the dimension of interest

◆ Merge()

void Array::Merge ( Array a)

Merge a second array into this one. Used to construct sparse array types. Both must be expanded.

Parameters
ais the other array that has to be combined with the current one.

◆ mkArray()

void Array::mkArray ( )
inline

Force this to be an array, not a deref. Used to override type specifier for compact foo f[n] which is shorthand for foo[0..n-1]

◆ nDims()

int Array::nDims ( )
inline
Returns
the number of dimensions of this array/sub-array/dereference

◆ Next()

Array * Array::Next ( )
inline
Returns
the next section of the sparse array, NULL if there isn't one.

◆ Offset() [1/2]

int Array::Offset ( Array a)

Given an array deference or subrange, returns the offset for the first element of the sub-range/dereference in the standard linear numbering of the elements of the array

Parameters
ais the de-reference/sub-range specifier to look for
Returns
the integer offset in the array numbering, or -1 if the specified array reference is out of range

◆ Offset() [2/2]

int Array::Offset ( int *  a)

Same as the other Offset() function, except the de-reference corresponds to a set of constant indices.

Parameters
ais the de-reference index
Returns
-1 if not found, or the offset in the linear numbering of the array

◆ overlapping()

int Array::overlapping ( struct range a,
struct range b 
)
private

Checks if two ranges have a non-empty intersection

Parameters
ais one of the two ranges
bis one of the two ranges
Returns
1 if the ranges are overlapping, 0 otherwise

◆ preConcat()

void Array::preConcat ( Array a)

Same as Concat(), except append dimensions starting from position 0, rather than adding to the dimensions at the end

Parameters
acontains the argument to be merged into the current array

◆ Print()

void Array::Print ( FILE *  fp,
int  style = 0 
)

Print the array out to the specified file. Arrays can be printed in two styles: [num][num] (style=0), or [num,num] (style=1).

Parameters
fpis the output file
styleis the printing style

◆ PrintOne()

void Array::PrintOne ( FILE *  fp,
int  style = 0 
)

This is similar to sPrintOne(), except it prints the output to a file.

Parameters
fpis the output file
styleis the printing style

◆ range_size()

int Array::range_size ( int  d)

returns size of a particular dimension. Only works for expanded arrays.

◆ Reduce()

Array * Array::Reduce ( )

return a deep copy, but elide dimensions that are derefs

◆ size()

int Array::size ( )

returns total number of elements. Only works for expanded arrays

◆ sPrint()

void Array::sPrint ( char *  buf,
int  sz,
int  style = 0 
)

Similar to Print(), but writes the output to a buffer.

Parameters
bufis the output buffer
szis the size of the output buffer
styleis the printing style

◆ sPrintOne()

int Array::sPrintOne ( char *  buf,
int  sz,
int  style = 0 
)

This prints out the first dense component of a sparse array.

Parameters
bufis the output buffer
szis the size of the output buffer
styleis the printing style
Returns
the number of characters of the buffer that were used

◆ stepper()

Arraystep * Array::stepper ( Array sub = NULL)

Stepper/iterator functionality. This returns an array "stepper" that allows you to step through the elements of the array. If a sub-range specifier is included, then the stepper only steps through the subrange within the array.

Parameters
subis the sub-range specifier, NULL if not needed
Returns
An Arraystep class that can be used to step through the elements of the array.

◆ unOffset()

Array * Array::unOffset ( int  offset)

Convert a linear offset into an array into the corresponding array de-reference

Parameters
offsetis the offset for the element of interest
Returns
the array de-reference corresponding to the offset

◆ update_range()

void Array::update_range ( int  d,
int  lo,
int  hi 
)

Set the range for dimension d to lo .. hi. Only works for expanded arrays.

Parameters
dis the dimension of the range to be updated
lois the new low range
hiis the new high range

◆ Validate()

int Array::Validate ( Array a)

Validate that the array indices specified in the argument are valid indicies for the array. This must be called on an expanded array.

Parameters
ais the Array that contains the indices of interest
Returns
1 if the de-reference is valid, 0 otherwise

Friends And Related Function Documentation

◆ Arraystep

friend class Arraystep
friend

Member Data Documentation

◆ deref

unsigned int Array::deref
private

1 if this is a dereference, 0 otherwise

◆ dims

int Array::dims
private

number of dimensions

◆ expanded

unsigned int Array::expanded
private

1 if this is expanded, 0 otherwise

◆ next

Array* Array::next
private

for sparse arrays, used to link together dense blocks for each component of the sparse array.

◆ r

struct Array::range * Array::r
private

range for each dimension

◆ range_sz

unsigned int Array::range_sz
private

cache: size of the range; only for expanded arrays


The documentation for this class was generated from the following file: