20 #ifndef RAGGED_ARRAY_IMPL_H 21 #define RAGGED_ARRAY_IMPL_H 23 #ifndef SHEAF_DLL_SPEC_H 24 #include "SheafSystem/sheaf_dll_spec.h" 27 #ifndef RAGGED_ARRAY_H 28 #include "SheafSystem/ragged_array.h" 31 #ifndef ASSERT_CONTRACT_H 32 #include "SheafSystem/assert_contract.h" 55 _col_cts.push_back(0);
58 _row_ptrs.push_back(0);
67 ensure(row_ct() == 1);
68 ensure(col_ct(0) == 0);
69 ensure(value_ct() == 0);
89 ensure((*
this) == xother);
101 require(xcol_cts != 0);
105 initialize(xcol_cts, xcol_cts_ub);
110 ensure(row_ct() == xcol_cts_ub);
111 ensure_for_all(i, 0, row_ct(), col_ct(i) == xcol_cts[i]);
118 template <
typename T>
124 require(xrow_ct > 0);
125 require(xvalue_ct > 0);
129 _col_cts.reserve(xrow_ct);
130 _col_cts.set_ct(xrow_ct);
132 _row_ptrs.reserve(xrow_ct);
133 _row_ptrs.set_ct(xrow_ct);
135 _values.reserve(xvalue_ct);
136 _values.set_ct(xvalue_ct);
142 _col_cts.assign(lcol_ct);
143 _col_cts.back() = lcol_ct + (xvalue_ct % xrow_ct);
147 _row_ptrs[i] = i*lcol_ct;
153 ensure(row_ct() == xrow_ct);
154 ensure(value_ct() == xvalue_ct);
155 ensure_for_all(i, 0, row_ct()-1, col_ct(i) == (value_ct()/row_ct()));
156 ensure(col_ct(row_ct()-1) == ((value_ct()/row_ct()) + (value_ct() % row_ct())));
163 template <
typename T>
180 template <
typename T>
193 _values[i] = xother.
_values[i];
199 ensure(row_ct() == xother.
row_ct());
200 ensure_for_all(i, 0, row_ct(), col_ct(i) == xother.
col_ct(i));
201 ensure_for_all(i, 0, value_ct(), values()[i] == xother.
values()[i]);
208 template <
typename T>
217 bool result = (row_ct() == xother.
row_ct());
219 for(
index_type i=0; result && i<row_ct(); i++)
221 result = (col_ct(i) == xother.
col_ct(i));
224 for(
index_type i=0; result && i<value_ct(); i++)
226 result = (_values[i] == xother.
_values[i]);
236 template <
typename T>
247 result = _col_cts.ct();
256 template <
typename T>
265 require(xrow_index < row_ct());
269 result = _col_cts[xrow_index];
278 template <
typename T>
289 result = _col_cts.base();
294 ensure(unexecutable(result contains at least row_ct() entries));
301 template <
typename T>
312 result = _values.base();
318 ensure(unexecutable(result contains value_ct() entries));
325 template <
typename T>
336 result = _values.ct();
345 template <
typename T>
354 require(xrow_index < row_ct());
358 result = _values.base() + _row_ptrs[xrow_index];
369 template <
typename T>
378 require(xrow_index < row_ct());
382 result = _values.base() + _row_ptrs[xrow_index];
393 template <
typename T>
407 _row_ptrs[i] = loffset;
408 loffset += _col_cts[i];
411 _values.reserve(loffset);
412 _values.set_ct(loffset);
416 ensure(value_ct() == sum_col_cts());
423 template <
typename T>
430 require(xcol_cts != 0);
434 initialize(xcol_cts, xcol_cts_ub);
439 ensure(row_ct() == xcol_cts_ub);
440 ensure_for_all(i, 0, row_ct(), col_ct(i) == xcol_cts[i]);
441 ensure(value_ct() == sum_col_cts());
448 template <
typename T>
459 result = sum_col_cts(_col_cts.base(), _col_cts.ct());
468 template <
typename T>
477 require(xcol_cts != 0);
483 result += xcol_cts[i];
493 template <
typename T>
504 _col_cts.reserve(xrow_ct);
505 _row_ptrs.reserve(xrow_ct);
511 _col_cts.push_back(0);
514 _row_ptrs.push_back(0);
518 _values.reserve(xvalue_ct);
523 ensure(back_row() == 0);
524 ensure(col_ct(back_row()) == 0);
525 ensure(value_ct() == 0);
532 template <
typename T>
545 ensure(result == (row_ct() - 1));
552 template <
typename T>
561 define_old_variable(
size_t old_value_ct = value_ct());
562 define_old_variable(
size_t old_col_ct = col_ct(back_row()));
563 define_old_variable(
index_type old_back_row = back_row());
565 _row_ptrs.push_back(_row_ptrs.back() + _col_cts.back());
566 _col_cts.push_back(0);
570 ensure(back_row() == old_back_row + 1);
571 ensure(col_ct(back_row()) == 0);
572 ensure(value_ct() == old_value_ct);
579 template <
typename T>
588 define_old_variable(
size_t old_value_ct = value_ct());
589 define_old_variable(
size_t old_col_ct = col_ct(back_row()));
590 define_old_variable(
index_type old_back_row = back_row());
592 _values.push_back(xvalue);
597 ensure(back_row() == old_back_row);
598 ensure(col_ct(back_row()) == old_col_ct + 1);
599 ensure(value_ct() == old_value_ct + 1);
608 template <
typename T>
616 require(xcol_cts != 0);
622 _col_cts.reserve(xcol_cts_ub);
625 _row_ptrs.reserve(xcol_cts_ub);
631 size_t lvalue_ct = 0;
634 _col_cts.push_back(xcol_cts[i]);
635 _row_ptrs.push_back(lvalue_ct);
636 lvalue_ct += xcol_cts[i];
641 _values.reserve(lvalue_ct);
642 _values.set_ct(lvalue_ct);
647 ensure(row_ct() == xcol_cts_ub);
648 ensure_for_all(i, 0, row_ct(), col_ct(i) == xcol_cts[i]);
664 template <
typename T>
679 ensure(result->
row_ct() == row_ct());
680 ensure_for_all(i, 0, row_ct(), result->
col_ct(i) == col_ct(i));
681 ensure_for_all(i, 0, value_ct(), result->
values()[i] == values()[i]);
689 template <
typename T>
700 invariance(col_cts() != 0);
701 invariance(sum_col_cts() == value_ct());
710 template <
typename T>
719 require(xother != 0);
741 template <
typename T>
743 operator << (std::ostream& xos, const ragged_array<T>& xra)
747 for(
size_type j=0; j< xra.col_ct(i); ++j)
749 xos <<
" " << xra[i][j];
757 template <
typename T>
767 result = xinclude_shallow ?
sizeof(xra) : 0;
792 #endif // ifndef RAGGED_ARRAY_IMPL_H size_type ct() const
The number of items currently in use.
void initialize(const index_type *xcol_cts, index_type xcol_cts_ub)
Creates an instance with xcol_cts_ub rows, with the number of columns in the i-th row given by xcol_c...
virtual bool operator==(const ragged_array &xother) const
True if this is equivalent to xother.
index_type value_ct() const
The number of values.
T * row(const index_type xrow_index) const
The row with index xrow_index.
index_type sum_col_cts() const
The sum of the column counts in col_cts().
index_type * col_cts() const
The naked, underlying storage for number of columns for each row.
ragged_array(size_t xct=0)
Default constructor; creates an empty array with one row and space reserved for xct values...
T * operator[](const index_type xrow_index) const
The row index operator; alias for row(index_type).
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
Abstract base class with useful features for all objects.
void push_back(const T &xvalue)
Add a value to the back of the back row.
pointer_type base() const
The underlying storage array.
block< index_type > _col_cts
The number of columns in each row.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
virtual bool invariant() const
Class invariant.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
index_type row_ct() const
The number of rows.
index_type back_row() const
The last row; the active row for push_back.
virtual ~ragged_array()
Destructor.
block< T > _values
The values stored in the array.
ragged_array & operator=(const ragged_array &xother)
Assignment operator.
block< index_type > _row_ptrs
Index of the first value in each row.
Namespace for the sheaves component of the sheaf system.
void new_back_row()
Creates a new last row.
void initialize_push_back(index_type xrow_ct, index_type xvalue_ct)
Reserves storage for xrow_ct rows containing xvalue_ct total values and initializes push_back into ro...
A two index array with variable length rows.
unsigned long index_type
The integer type used to index this.
virtual ragged_array * clone() const
Virtual constructor; makes a new instance of the same type as this.
index_type col_ct(const index_type xrow_index) const
The number of columns for the xrow_index-th row.
void reset_rows()
Reinitializes access by row index using the column counts in col_cts().
T * values() const
The naked, underlying storage for the values in the array.