Go to the source code of this file.
|
int | round_length (int n, size_t s) |
|
template<class T > |
bool | operator== (array< T > a, array< T > b) |
| Check if two arrays are equal.
|
|
template<class T > |
bool | operator!= (array< T > a, array< T > b) |
| Check if two arrays are not equal.
|
|
template<class T > |
tm_ostream & | operator<< (tm_ostream &out, array< T > a) |
| Output the array to an output stream.
|
|
template<class T > |
array< T > & | operator<< (array< T > &a, T x) |
| Append an element to the end of the array.
|
|
template<class T > |
array< T > & | operator<< (array< T > &a, array< T > b) |
| Append an array to the end of another array.
|
|
template<class t > |
bool | contains (t a, array< t > b) |
|
template<class t > |
array< t > | append (t a, array< t > b) |
|
template<class T > |
array< T > | append (array< T > a, array< T > b) |
| Append an array to the end of another array.
|
|
template<class T > |
array< T > | range (array< T > a, int i, int j) |
| Get a subarray of an array.
|
|
template<class T > |
array< T > | reverse (array< T > a) |
| Reverse an array.
|
|
template<class T > |
int | hash (array< T > a) |
| This function computes the hash of an array object a.
|
|
template<class T > |
array< T > | operator* (array< T > a, T c) |
| Multiply an array object by a scalar value of type T.
|
|
template<class T > |
array< T > | operator/ (array< T > a, T c) |
| Divide an array object by a scalar value of type T.
|
|
◆ ARRAY_CC
◆ round_length()
int round_length |
( |
int | n, |
|
|
size_t | s ) |
|
inline |
Definition at line 21 of file array.ipp.
21 {
23 if (n < 6) return n;
24 int i= 8;
25 while (n > i)
26 i<<= 1;
27 return i;
28}
The list class represents a linked list.
◆ operator==()
Check if two arrays are equal.
- Template Parameters
-
T | Type of elements in the arrays. |
- Parameters
-
a | The first array. |
b | The second array. |
- Returns
- True if the two arrays are equal, false otherwise.
Definition at line 100 of file array.ipp.
100 {
101 int i;
102 if (
N (a) !=
N (
b))
return false;
103 for (i= 0; i <
N (a); i++)
104 if (a[i] !=
b[i])
return false;
105 return true;
106}
int N(array< T > a)
Get the length of the array.
◆ operator!=()
Check if two arrays are not equal.
- Template Parameters
-
T | Type of elements in the arrays. |
- Parameters
-
a | The first array. |
b | The second array. |
- Returns
- True if the two arrays are not equal, false otherwise.
Definition at line 110 of file array.ipp.
110 {
111 int i;
112 if (
N (a) !=
N (
b))
return true;
113 for (i= 0; i <
N (a); i++)
114 if (a[i] !=
b[i])
return true;
115 return false;
116}
◆ operator<<() [1/3]
Output the array to an output stream.
- Template Parameters
-
T | Type of elements in the array. |
- Parameters
-
out | The output stream. |
a | The array to be output. |
- Returns
- The output stream.
Definition at line 119 of file array.ipp.
120 {
121 int i;
122
123 if (
N (a) == 0)
return out <<
"[ ]";
124 out << "[ ";
125 for (i= 0; i <
N (a) - 1; i++)
126 out << a[i] << ", ";
127 if (
N (a) != 0) out << a[i];
128 out << " ]";
129 return out;
130}
◆ operator<<() [2/3]
Append an element to the end of the array.
- Template Parameters
-
T | Type of elements in the array. |
- Parameters
-
a | The array. |
x | The element to be appended. |
- Returns
- The updated array.
Definition at line 119 of file array.ipp.
134 {
135 a->resize (
N (a) + 1);
137 return a;
138}
◆ operator<<() [3/3]
Append an array to the end of another array.
- Template Parameters
-
T | Type of elements in the array. |
- Parameters
-
a | The first array. |
b | The second array. |
- Returns
- The updated array.
Definition at line 119 of file array.ipp.
142 {
144 a->resize (
N (a) +
N (
b));
145 for (i= 0; i <
N (
b); i++)
147 return a;
148}
◆ contains()
bool contains |
( |
t | a, |
|
|
array< t > | b ) |
Definition at line 152 of file array.ipp.
152 {
154 for (i= 0; i < l; i++)
155 if (a ==
b[i])
return true;
156 return false;
157}
◆ append() [1/2]
Definition at line 161 of file array.ipp.
161 {
165 for (i= 0; i < l; i++)
168}
◆ append() [2/2]
Append an array to the end of another array.
- Template Parameters
-
T | Type of elements in the array. |
- Parameters
-
a | The first array. |
b | The second array. |
- Returns
- The updated array.
Definition at line 172 of file array.ipp.
172 {
173 int i,
k=
N (a), l=
N (
b);
175 for (i= 0; i <
k; i++)
177 for (i= 0; i < l; i++)
180}
◆ range()
Get a subarray of an array.
- Template Parameters
-
T | Type of elements in the array. |
- Parameters
-
a | The array. |
i | The start index of the subarray. |
j | The end index of the subarray. |
- Returns
- The subarray.
Definition at line 184 of file array.ipp.
184 {
186 ASSERT (i >= 0 &&
j <=
N (a),
"out of range");
188 for (
k= i;
k <
j;
k++)
191}
#define ASSERT(cond, msg)
Macro used to assert that a condition is true, and throw an exception with an error message if the co...
◆ reverse()
Reverse an array.
- Template Parameters
-
T | Type of elements in the array. |
- Parameters
-
- Returns
- The reversed array.
Definition at line 195 of file array.ipp.
195 {
198 for (i= 0; i < n; i++)
201}
◆ hash()
This function computes the hash of an array object a.
- Parameters
-
- Returns
- Return an integer hash value.
Definition at line 205 of file array.ipp.
205 {
206 int i, n=
N (a), h= 0;
207 for (i= 0; i < n; i++)
208 h=
hash (a[i]) ^ ((h << 7) + (h >> 25));
209 return h;
210}
int hash(array< T > a)
This function computes the hash of an array object a.
◆ operator*()
Multiply an array object by a scalar value of type T.
- Parameters
-
a | The target array. |
c | The scalar value. |
- Returns
- Return a new array object whose elements are the elements of a multiplied by c.
Definition at line 214 of file array.ipp.
214 {
217 for (i= 0; i < n; i++)
220}
◆ operator/()
Divide an array object by a scalar value of type T.
- Parameters
-
a | The target array. |
c | The scalar value. |
- Returns
- Return a new array object whose elements are the elements of a divided by c.
Definition at line 224 of file array.ipp.
224 {
227 for (i= 0; i < n; i++)
230}