Lolly 1.4.28
Loading...
Searching...
No Matches
Macros | Functions
array.ipp File Reference
#include "array.hpp"
Include dependency graph for array.ipp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ARRAY_CC
 

Functions

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_ostreamoperator<< (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< tappend (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.
 

Macro Definition Documentation

◆ ARRAY_CC

#define ARRAY_CC

Definition at line 13 of file array.ipp.

Function Documentation

◆ round_length()

int round_length ( int n,
size_t s )
inline

Definition at line 21 of file array.ipp.

21 {
22 (void) s;
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.
Definition list.hpp:48

◆ operator==()

template<class T >
bool operator== ( array< T > a,
array< T > b )

Check if two arrays are equal.

Template Parameters
TType of elements in the arrays.
Parameters
aThe first array.
bThe 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.
Definition array.hpp:170
blackbox b[13]

◆ operator!=()

template<class T >
bool operator!= ( array< T > a,
array< T > b )

Check if two arrays are not equal.

Template Parameters
TType of elements in the arrays.
Parameters
aThe first array.
bThe 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]

template<class T >
tm_ostream & operator<< ( tm_ostream & out,
array< T > a )

Output the array to an output stream.

Template Parameters
TType of elements in the array.
Parameters
outThe output stream.
aThe 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]

template<class T >
array< T > & operator<< ( array< T > & a,
T x )

Append an element to the end of the array.

Template Parameters
TType of elements in the array.
Parameters
aThe array.
xThe element to be appended.
Returns
The updated array.

Definition at line 119 of file array.ipp.

134 {
135 a->resize (N (a) + 1);
136 a[N (a) - 1]= x;
137 return a;
138}

◆ operator<<() [3/3]

template<class T >
array< T > & operator<< ( array< T > & a,
array< T > b )

Append an array to the end of another array.

Template Parameters
TType of elements in the array.
Parameters
aThe first array.
bThe second array.
Returns
The updated array.

Definition at line 119 of file array.ipp.

142 {
143 int i, k= N (a);
144 a->resize (N (a) + N (b));
145 for (i= 0; i < N (b); i++)
146 a[i + k]= b[i];
147 return a;
148}

◆ contains()

template<class t >
bool contains ( t a,
array< t > b )

Definition at line 152 of file array.ipp.

152 {
153 int i, l= N (b);
154 for (i= 0; i < l; i++)
155 if (a == b[i]) return true;
156 return false;
157}

◆ append() [1/2]

template<class t >
array< t > append ( t a,
array< t > b )

Definition at line 161 of file array.ipp.

161 {
162 int i, l= N (b);
163 array<t> c (l + 1);
164 c[0]= a;
165 for (i= 0; i < l; i++)
166 c[i + 1]= b[i];
167 return c;
168}

◆ append() [2/2]

template<class T >
array< T > append ( array< T > a,
array< T > b )

Append an array to the end of another array.

Template Parameters
TType of elements in the array.
Parameters
aThe first array.
bThe second array.
Returns
The updated array.

Definition at line 172 of file array.ipp.

172 {
173 int i, k= N (a), l= N (b);
174 array<T> c (k + l);
175 for (i= 0; i < k; i++)
176 c[i]= a[i];
177 for (i= 0; i < l; i++)
178 c[i + k]= b[i];
179 return c;
180}

◆ range()

template<class T >
array< T > range ( array< T > a,
int i,
int j )

Get a subarray of an array.

Template Parameters
TType of elements in the array.
Parameters
aThe array.
iThe start index of the subarray.
jThe end index of the subarray.
Returns
The subarray.

Definition at line 184 of file array.ipp.

184 {
185 int k;
186 ASSERT (i >= 0 && j <= N (a), "out of range");
187 array<T> r (j - i);
188 for (k= i; k < j; k++)
189 r[k - i]= a[k];
190 return r;
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...
Definition basic.hpp:85

◆ reverse()

template<class T >
array< T > reverse ( array< T > a)

Reverse an array.

Template Parameters
TType of elements in the array.
Parameters
aThe array.
Returns
The reversed array.

Definition at line 195 of file array.ipp.

195 {
196 int i, n= N (a);
197 array<T> r (n);
198 for (i= 0; i < n; i++)
199 r[i]= a[n - 1 - i];
200 return r;
201}

◆ hash()

template<class T >
int hash ( array< T > a)

This function computes the hash of an array object a.

Parameters
aThe array object.
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.
Definition array.ipp:205

◆ operator*()

template<class T >
array< T > operator* ( array< T > a,
T c )

Multiply an array object by a scalar value of type T.

Parameters
aThe target array.
cThe 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 {
215 int i, n= N (a);
216 array<T> r (n);
217 for (i= 0; i < n; i++)
218 r[i]= a[i] * c;
219 return r;
220}

◆ operator/()

template<class T >
array< T > operator/ ( array< T > a,
T c )

Divide an array object by a scalar value of type T.

Parameters
aThe target array.
cThe 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 {
225 int i, n= N (a);
226 array<T> r (n);
227 for (i= 0; i < n; i++)
228 r[i]= a[i] / c;
229 return r;
230}