PULSAR  1.0.0
Parallel Ultra Light Systolic Array Runtime
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
prt_tuple.h File Reference

PRT tuple. More...

#include "prt.h"
Include dependency graph for prt_tuple.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define prt_tuple_new1(a)   prt_tuple_new(1,a)
 
#define prt_tuple_new2(a, b)   prt_tuple_new(2,a,b)
 
#define prt_tuple_new3(a, b, c)   prt_tuple_new(3,a,b,c)
 
#define prt_tuple_new4(a, b, c, d)   prt_tuple_new(4,a,b,c,d)
 
#define prt_tuple_new5(a, b, c, d, e)   prt_tuple_new(5,a,b,c,d,e)
 
#define prt_tuple_new6(a, b, c, d, e, f)   prt_tuple_new(6,a,b,c,d,e,f)
 

Functions

int * prt_tuple_new (int len,...)
 tuple constructor Allocates memory for the tuple plus the termination symbol (INT_MAX). More...
 
int prt_tuple_len (int *tuple)
 tuple length More...
 
int * prt_tuple_cat (int *first_tuple,...)
 tuple concatenate Join a variable length, NULL-terminated, list of tuples. More...
 
void prt_tuple_delete (int *tuple)
 tuple destructor More...
 
int * prt_tuple_copy (int *in_tuple)
 tuple copy constructor More...
 
int prt_tuple_compare (void *tuple_a, void *tuple_b)
 tuple comparison More...
 
int prt_tuple_equal (void *tuple_a, void *tuple_b)
 tuple equality check Check if tuples are identical in length and content. More...
 
void prt_tuple_print (int *tuple)
 tuple print More...
 
unsigned int prt_tuple_hash (void *tuple)
 tuple hash Required by the VSA's tuples hash table. Computes the lenght in characters and calls a string hash function. More...
 

Detailed Description

PRT tuple.

Author
Jakub Kurzak

Tuples uniquely identify VDPs in a VSA. Tuple is an array of integers terminated with INT_MAX. For all practical purposes a tuple behaves like a string.

PULSAR Runtime http://icl.eecs.utk.edu/pulsar/ Copyright (C) 2012-2013 University of Tennessee.

Definition in file prt_tuple.h.

Macro Definition Documentation

#define prt_tuple_new1 (   a)    prt_tuple_new(1,a)

Definition at line 34 of file prt_tuple.h.

#define prt_tuple_new2 (   a,
 
)    prt_tuple_new(2,a,b)

Definition at line 35 of file prt_tuple.h.

#define prt_tuple_new3 (   a,
  b,
 
)    prt_tuple_new(3,a,b,c)

Definition at line 36 of file prt_tuple.h.

#define prt_tuple_new4 (   a,
  b,
  c,
 
)    prt_tuple_new(4,a,b,c,d)

Definition at line 37 of file prt_tuple.h.

#define prt_tuple_new5 (   a,
  b,
  c,
  d,
 
)    prt_tuple_new(5,a,b,c,d,e)

Definition at line 38 of file prt_tuple.h.

#define prt_tuple_new6 (   a,
  b,
  c,
  d,
  e,
 
)    prt_tuple_new(6,a,b,c,d,e,f)

Definition at line 39 of file prt_tuple.h.

Function Documentation

int* prt_tuple_cat ( int *  first_tuple,
  ... 
)

tuple concatenate Join a variable length, NULL-terminated, list of tuples.

Parameters
first_tuple
...the other tuples
Returns
the combined tuple

Definition at line 64 of file prt_tuple.c.

References prt_assert, and prt_tuple_len().

65 {
66  int len;
67  int *tuple;
68  va_list ap;
69  va_start(ap, first_tuple);
70  len = prt_tuple_len(first_tuple);
71  while ((tuple = va_arg(ap, int*)) != NULL)
72  len += prt_tuple_len(tuple);
73  va_end(ap);
74 
75  int *out_tuple = (int*)malloc((len+1)*sizeof(int));
76  prt_assert(out_tuple != NULL, "malloc failed");
77  va_start(ap, first_tuple);
78  while(*first_tuple != INT_MAX)
79  *out_tuple++ = *first_tuple++;
80  while ((tuple = va_arg(ap, int*)) != NULL)
81  while(*tuple != INT_MAX)
82  *out_tuple++ = *tuple++;
83  va_end(ap);
84 
85  *out_tuple = INT_MAX;
86  return (out_tuple-len);
87 }
int prt_tuple_len(int *tuple)
tuple length
Definition: prt_tuple.c:47
#define prt_assert(cond, msg)
Definition: prt_assert.h:30

Here is the call graph for this function:

int prt_tuple_compare ( void *  tuple_a,
void *  tuple_b 
)

tuple comparison

Parameters
tuple_a
tuple_b
Return values
-1tuple_a is less than tuple_b.
0tuple_a is equal to tuple_b.
1tuple_a is greater than tuple_b.

Definition at line 135 of file prt_tuple.c.

136 {
137  int *tupa = (int*)tuple_a;
138  int *tupb = (int*)tuple_b;
139  while (*tupa != INT_MAX && *tupb != INT_MAX) {
140  if (*tupa < *tupb) return -1;
141  else if (*tupa > *tupb) return 1;
142  tupa++;
143  tupb++;
144  }
145  if (*tupa == INT_MAX && *tupb == INT_MAX) return 0;
146  else if (*tupa == INT_MAX) return -1;
147  else if (*tupb == INT_MAX) return 1;
148 }

Here is the caller graph for this function:

int* prt_tuple_copy ( int *  in_tuple)

tuple copy constructor

Parameters
in_tuple
Returns
new copy

Definition at line 109 of file prt_tuple.c.

References prt_assert.

110 {
111  int i;
112  int len = 0;
113  int *out_tuple;
114  while (in_tuple[len] != INT_MAX)
115  len++;
116  out_tuple = (int*)malloc((len+1)*sizeof(int));
117  prt_assert(out_tuple != NULL, "malloc failed");
118  for (i = 0; i < len; i++)
119  out_tuple[i] = in_tuple[i];
120  out_tuple[len] = INT_MAX;
121  return out_tuple;
122 }
#define prt_assert(cond, msg)
Definition: prt_assert.h:30
void prt_tuple_delete ( int *  tuple)

tuple destructor

Parameters
tuple

Definition at line 95 of file prt_tuple.c.

96 {
97  // Free the tuple.
98  free(tuple);
99 }

Here is the caller graph for this function:

int prt_tuple_equal ( void *  tuple_a,
void *  tuple_b 
)

tuple equality check Check if tuples are identical in length and content.

Parameters
tuple_a
tuple_b
Return values
0Tuples differ.
1Tuples are identical.

Definition at line 161 of file prt_tuple.c.

162 {
163  return (prt_tuple_compare(tuple_a, tuple_b) == 0);
164 }
int prt_tuple_compare(void *tuple_a, void *tuple_b)
tuple comparison
Definition: prt_tuple.c:135
unsigned int prt_tuple_hash ( void *  tuple)

tuple hash Required by the VSA's tuples hash table. Computes the lenght in characters and calls a string hash function.

Parameters
tuple
Returns
hash

Definition at line 188 of file prt_tuple.c.

189 {
190  int len = 0;
191  int *tup = (int*)tuple;
192  while (tup[len] != INT_MAX)
193  len++;
194  return fnv_hash(tuple, len*sizeof(int));
195 }
int prt_tuple_len ( int *  tuple)

tuple length

Parameters
tuple
Returns
tuple length without the terminating symbol

Definition at line 47 of file prt_tuple.c.

48 {
49  int *p = tuple;
50  while (*p++ != INT_MAX);
51  return (p-tuple-1);
52 }

Here is the caller graph for this function:

int* prt_tuple_new ( int  len,
  ... 
)

tuple constructor Allocates memory for the tuple plus the termination symbol (INT_MAX).

Parameters
lenlength of the tuple
...list of elements of type int
Returns
pointer to an integer array terminated with INT_MAX

Definition at line 25 of file prt_tuple.c.

References prt_assert.

26 {
27  int *tuple = (int*)malloc((len+1)*sizeof(int));
28  prt_assert(tuple != NULL, "malloc failed");
29  int i;
30  va_list ap;
31  va_start(ap, len);
32  for (i = 0; i < len; i++)
33  tuple[i] = va_arg(ap, int);
34  va_end(ap);
35  tuple[len] = INT_MAX;
36  return tuple;
37 }
#define prt_assert(cond, msg)
Definition: prt_assert.h:30
void prt_tuple_print ( int *  tuple)

tuple print

Parameters
tuple

Definition at line 172 of file prt_tuple.c.

173 {
174  while (*tuple != INT_MAX)
175  printf("%3d", *tuple++);
176 }

Here is the caller graph for this function: