20 #ifndef BINARY_INDEX_BLOCK_IMPL_H 21 #define BINARY_INDEX_BLOCK_IMPL_H 23 #ifndef SHEAF_DLL_SPEC_H 24 #include "SheafSystem/sheaf_dll_spec.h" 27 #ifndef BINARY_INDEX_BLOCK_H 28 #include "SheafSystem/binary_index_block.h" 32 #include "SheafSystem/block.impl.h" 43 binary_index_block<T>&
75 result = result && ( _i_ub >= 0 );
76 result = result && ( _i_ct >= 0 );
77 result = result && ( _i_ct <= _i_ub );
78 result = result && ((_i_ub > 0) == (this->_base != 0));
80 result = result && ( _j_ub >= 0 );
81 result = result && ( _j_ct >= 0 );
82 result = result && ( _j_ct <= _j_ub );
83 result = result && ((_j_ub > 0) == (this->_base != 0));
103 define_old_variable(
int old_ct = this->ct());
106 for(
int i=0; i<xother.
ct(); ++i)
108 push_back(xother.
item(i));
113 ensure(this->ct() == old_ct + xother.
ct());
114 ensure_for_all(i, 0, xother.
ct(), ((*this)[i + old_ct] == xother[i]) );
125 template <
typename T>
140 this->_ub = xi_ub*xj_ub;
146 reserve(xi_ub, xj_ub);
152 ensure(i_ub( )>= xi_ub);
153 ensure(j_ub( )>= xj_ub);
154 ensure(this->ub() >= xi_ub*xj_ub);
155 ensure((xi_ub*xj_ub > 0) == (this->base() != 0));
159 ensure(this->ct() == 0);
166 template <
typename T>
173 require(precondition_of(block_xother));
180 ensure(postcondition_of(
block(xother)));
188 template <
typename T>
194 template <
typename T>
202 require((0 <= xi_ct) && (xi_ct <= xi_ub));
203 require((xi_ct > 0) == (xitems != 0));
205 require((0 <= xj_ct) && (xj_ct <= xj_ub));
206 require((xj_ct > 0) == (xitems != 0));
207 require(unexecutable(xitems != 0 implies xitems points to array of
length >= xi_ct*xj_ct));
218 for(
int i = 0; i < xi_ct*xj_ct; ++i)
220 this->
_base[i] = xitems[i];
229 ensure(
i_ub() >= xi_ub);
230 ensure(
j_ub() >= xj_ub);
231 ensure((xi_ub*xj_ub > 0) == (this->
base() != 0));
232 ensure(
i_ct() == xi_ct);
233 ensure(
j_ct() == xj_ct);
238 template <
typename T>
261 template <
typename T>
283 template <
typename T>
305 template <
typename T>
327 template <
typename T>
335 require(xi >= 0 && xi <
i_ub());
336 require(xj >= 0 && xj <
j_ub());
340 int index = xj + xi*
j_ub();
341 T & result = *(this->
_base+index);
353 template <
typename T>
361 require(xi >= 0 && xi <
i_ub());
362 require(xj >= 0 && xj <
j_ub());
366 int index = xj + xi*
j_ub();
367 T & result = *(this->
_base+index);
379 template <
typename T>
387 require(xi >= 0 && xi <
i_ub());
391 int index = xi*
_j_ub;
392 T* result = this->
_base+index;
404 template <
typename T>
421 int new_i_ub =
_i_ub*2 > xi ?
_i_ub*2 : xi + 1;
422 int new_j_ub =
_j_ub*2 > xj ?
_j_ub*2 : xj + 1;
436 ensure(
item(xi, xj)==xitem);
440 template <
typename T>
453 define_old_variable(
int old_i_ct =
_i_ct);
454 define_old_variable(
int old_i_ub =
_i_ub);
455 define_old_variable(
int old_j_ct =
_j_ct);
456 define_old_variable(
int old_j_ub =
_j_ub);
473 ensure(
i_ct() == old_i_ct);
474 ensure(
i_ub() >= old_i_ub);
475 ensure(
i_ub() >= xi_ub);
476 ensure((
i_ub() > 0) == (this->
base() != 0));
477 ensure(
j_ct() == old_j_ct);
478 ensure(
j_ub() >= old_j_ub);
479 ensure(
j_ub() >= xj_ub);
480 ensure((
j_ub() > 0) == (this->
base() != 0));
481 ensure(this->
ub() >= xi_ub*xj_ub);
486 template <
typename T>
494 require(0 <= xi_ct && xi_ct <=
i_ub());
495 require(0 <= xj_ct && xj_ct <=
j_ub());
505 ensure(
i_ct() == xi_ct);
506 ensure(
j_ct() == xj_ct);
510 template <
typename T>
518 require(0 <= xi && xi <
i_ub());
519 require(0 <= xj && xj <
j_ub());
523 int index = xj + xi*
j_ub();
524 *(this->
_base+index) = xitem;
529 ensure(
item(xi, xj)==xitem);
534 template <
typename T>
543 define_old_variable(
int old_ct =
i_ct()*
j_ct());
547 this->
_base[i] = xitem;
563 template <
typename T>
565 operator << (std::ostream& xos, const binary_index_block<T>& xblk)
567 for(
int i=0; i<xblk.i_ct(); ++i)
569 for(
int j=0; j<xblk.j_ct(); ++j)
571 xos <<
" " << xblk.item(i,j);
581 #endif // ifndef BINARY_INDEX_BLOCK_IMPL_H
index_type ub() const
The upper bound on the storage array. The number of items current allocated in the storage array...
size_type ct() const
The number of items currently in use.
void put_item(int xi, int xj, const T &xitem)
Sets the item xitem at index xi, xj to xitem, but will not resize.
bool invariant() const
The class invariant.
block & operator=(const block &xother)
Assignment operator.
int i_ct() const
The number of i index values currently in use.
block(index_type xub=0)
Creates an instance with ub() == xub; storage is uninitialized.
SHEAF_DLL_SPEC vd_value_type length(const ed &x0, bool xauto_access)
The Euclidean length (magnitude) of x0 (version for persistent types).
void push_back(const binary_index_block &xother)
Appends xother to the back of this.
T * operator[](int xi) const
The address of the first item in row xi. /.
pointer_type base() const
The underlying storage array.
void reserve(int xi_ub, int xj_ub)
Makes i_ub() at least xi_ub and j_ub() at least xj_ub.
int j_ub() const
The upper bound for the second index.
void assign(const T &xitem)
Sets the values of all items to xitem.
int j_ct() const
The number of j index values currently in use.
int _j_ub
The upper bound for the second index.
size_type _ct
The number of items currently stored.
int _i_ub
The upper bound for the first index.
void set_ct(int xi_ct, int xj_ct)
Sets i_ct() == xi_ct and j_ct() == xj_ct.
index_type _ub
The index upper bound.
A block which can be accessed using two indices, similarly to a two index array.
void force_item(int xi, int xj, const T &xitem)
Puts the item xitem at index xi,xj, resizing if necessary.
int _i_ct
The number of i index values currently in use.
int i_ub() const
The upper bound for the first index.
Namespace for the sheaves component of the sheaf system.
~binary_index_block()
Destructor.
pointer_type _base
Start of storage for this.
binary_index_block & operator=(const binary_index_block &xother)
Sets the contents of this to the contents of xother.
T & item(int xi, int xj)
The item at index xi, xj (mutable version).
An auto_block with a no-initialization initialization policy.
int _j_ct
The number of j index values currently in use.
binary_index_block(int xi_ub=0, int xj_ub=0)
Default constructor.