21 #ifndef RECORD_MAP_IMPL_H 22 #define RECORD_MAP_IMPL_H 24 #ifndef SHEAF_DLL_SPEC_H 25 #include "SheafSystem/sheaf_dll_spec.h" 29 #include "SheafSystem/record_map.h" 32 #ifndef ASSERT_CONTRACT_H 33 #include "SheafSystem/assert_contract.h" 36 #ifndef INDEX_TRAITS_H 37 #include "SheafSystem/index_traits.h" 41 #include "SheafSystem/std_iomanip.h" 53 template<
typename internal_index_type,
typename external_index_type>
61 _internal_ids_sequential =
false;
62 _external_ids_sequential =
false;
70 _entry_removed =
false;
75 ensure(!internal_ids_sequential());
76 ensure(!external_ids_sequential());
88 template <
typename internal_index_type,
typename external_index_type>
101 ensure(unexecutable((*
this) == xother));
108 template <
typename internal_index_type,
typename external_index_type>
121 _to_external = lother._to_external;
122 _to_internal = lother._to_internal;
123 _internal_ids_sequential = lother._internal_ids_sequential;
124 _external_ids_sequential = lother._external_ids_sequential;
126 _scratch_internal_id = lother._scratch_internal_id;
127 _scratch_external_id = lother._scratch_external_id;
129 _internal_id_ub = lother._internal_id_ub;
130 _external_id_ub = lother._external_id_ub;
132 _entry_removed = lother._entry_removed;
138 ensure((*
this) == xother);
145 template <
typename internal_index_type,
typename external_index_type>
158 template <
typename internal_index_type,
typename external_index_type>
167 invariance(_to_internal.size() == _to_external.size());
172 invariance(_internal_ids_sequential ? !_external_ids_sequential :
true);
173 invariance(_external_ids_sequential ? !_internal_ids_sequential :
true);
177 invariance(unexecutable(
"for all internal ids i: i <= internal_id_ub()"));
178 invariance(unexecutable(
"ub_is_max() ? there exists entry (int_id, ext_id) such that int_id= internal_id_ub()"));
179 invariance(unexecutable(
"for all external ids i: i <= external_id_ub()"));
180 invariance(unexecutable(
"ub_is_max() ? there exists entry (int_id, ext_id) such that ext_id= external_id_ub()"));
185 template <
typename internal_index_type,
typename external_index_type>
194 typename unordered::unordered_map<internal_index_type, external_index_type>::const_iterator itr = _to_external.find(xinternal_id);
195 external_index_type result =
208 template <
typename internal_index_type,
typename external_index_type>
217 typename unordered::unordered_map<external_index_type, internal_index_type>::const_iterator itr = _to_internal.find(xexternal_id);
218 internal_index_type result =
230 template <
typename internal_index_type,
typename external_index_type>
233 put_ids(internal_index_type xinternal_id, external_index_type xexternal_id)
237 require(!is_empty() ? !internal_ids_sequential() && !external_ids_sequential() :
true);
238 require(!contains_internal_id(xinternal_id));
239 require(!contains_external_id(xexternal_id));
243 unguarded_put_ids(xinternal_id, xexternal_id);
248 ensure(external_id(xinternal_id) == xexternal_id);
249 ensure(internal_id(xexternal_id) == xinternal_id);
256 template <
typename internal_index_type,
typename external_index_type>
259 unguarded_put_ids(internal_index_type xinternal_id, external_index_type xexternal_id)
265 _to_external.insert(
typename external_map_type::value_type(xinternal_id, xexternal_id));
266 _to_internal.insert(
typename internal_map_type::value_type(xexternal_id, xinternal_id));
268 _internal_id_ub = (xinternal_id > _internal_id_ub) ? xinternal_id : _internal_id_ub;
269 _external_id_ub = (xexternal_id > _external_id_ub) ? xexternal_id : _external_id_ub;
280 template <
typename internal_index_type,
typename external_index_type>
285 return _internal_ids_sequential;
288 template <
typename internal_index_type,
typename external_index_type>
293 return _external_ids_sequential;
296 template <
typename internal_index_type,
typename external_index_type>
301 external_index_type result;
305 require(!is_empty() ? external_ids_sequential() :
true);
306 require(!contains_internal_id(xinternal_id));
313 unguarded_put_ids(xinternal_id, result);
314 _external_ids_sequential =
true;
320 ensure(external_id(xinternal_id) == result);
321 ensure(external_ids_sequential());
328 template <
typename internal_index_type,
typename external_index_type>
333 internal_index_type result;
337 require(!is_empty() ? internal_ids_sequential() :
true);
338 require(!contains_external_id(xexternal_id));
346 unguarded_put_ids(result, xexternal_id);
347 _internal_ids_sequential =
true;
353 ensure(internal_id(xexternal_id) == result);
354 ensure(internal_ids_sequential());
361 template <
typename internal_index_type,
typename external_index_type>
373 typename external_map_type::const_iterator lresult = _to_external.find(xint_id);
375 result = lresult != _to_external.end();
386 template <
typename internal_index_type,
typename external_index_type>
398 typename internal_map_type::const_iterator lresult = _to_internal.find(xext_id);
400 result = lresult != _to_internal.end();
411 template <
typename internal_index_type,
typename external_index_type>
434 result = result && (_scratch_internal_id == lother._scratch_internal_id);
435 result = result && (_scratch_external_id == lother._scratch_external_id);
437 result = result && (_internal_id_ub == lother._internal_id_ub);
438 result = result && (_external_id_ub == lother._external_id_ub);
440 result = result && (_entry_removed == lother._entry_removed);
451 template <
typename internal_index_type,
typename external_index_type>
456 return _to_internal.size();
459 template <
typename internal_index_type,
typename external_index_type>
467 template <
typename internal_index_type,
typename external_index_type>
476 _to_external.clear();
477 _to_internal.clear();
479 _internal_ids_sequential =
false;
480 _external_ids_sequential =
false;
488 _entry_removed =
false;
493 ensure(!internal_ids_sequential());
494 ensure(!external_ids_sequential());
500 ensure(!ub_is_max());
507 template <
typename internal_index_type,
typename external_index_type>
516 typename external_map_type::iterator litr = _to_external.find(xinternal_id);
518 if(litr != _to_external.end())
520 _to_internal.erase(litr->second);
521 _to_external.erase(litr);
530 _entry_removed =
true;
535 ensure(!contains_internal_id(xinternal_id));
536 ensure(!ub_is_max());
543 template <
typename internal_index_type,
typename external_index_type>
552 typename internal_map_type::iterator litr = _to_internal.find(xexternal_id);
554 if(litr != _to_internal.end())
556 _to_external.erase(litr->second);
557 _to_internal.erase(litr);
558 _entry_removed =
true;
564 ensure(!contains_external_id(xexternal_id));
565 ensure(!ub_is_max());
572 template <
typename internal_index_type,
typename external_index_type>
585 return _scratch_internal_id;
589 template <
typename internal_index_type,
typename external_index_type>
598 _scratch_internal_id = xid;
602 ensure(scratch_internal_id() == xid);
609 template <
typename internal_index_type,
typename external_index_type>
622 return _scratch_external_id;
625 template <
typename internal_index_type,
typename external_index_type>
634 _scratch_external_id = xid;
638 ensure(scratch_external_id() == xid);
645 template <
typename internal_index_type,
typename external_index_type>
654 internal_index_type result = _internal_id_ub;
658 ensure(unexecutable(
"for all internal ids i: i <= result"));
659 ensure(unexecutable(
"if remove_internal_id has not been called result = maximum internal id"));
666 template <
typename internal_index_type,
typename external_index_type>
675 external_index_type result = _external_id_ub;
679 ensure(unexecutable(
"for all external ids i: i <= result"));
680 ensure(unexecutable(
"if remove_external_id has not been called result = maximum external id"));
687 template <
typename internal_index_type,
typename external_index_type>
702 result = (ct() > 0) && !_entry_removed;
706 ensure(unexecutable(
"result == (upper bounds are in fact maxima)"));
713 template <
typename internal_index_type,
typename external_index_type>
718 return _to_external.begin();
721 template <
typename internal_index_type,
typename external_index_type>
726 return _to_external.end();
729 template <
typename internal_index_type,
typename external_index_type>
738 print(std::cout, *
this);
745 template <
typename internal_index_type,
typename external_index_type>
761 xos << endl <<
"internal to external map:" << endl;
764 typename unordered_map<internal_index_type, external_index_type>::iterator itr0;
765 itr0 = lp._to_external.begin();
766 while(itr0 != lp._to_external.end())
768 xos << setw(6) << itr0->first;
773 itr0 = lp._to_external.begin();
774 while(itr0 != lp._to_external.end())
776 xos << setw(6) << itr0->second;
781 xos <<
"external to internal map:" << endl;
784 typename unordered_map<external_index_type, internal_index_type>::iterator itr1;
785 itr1 = lp._to_internal.begin();
786 while(itr1 != lp._to_internal.end())
788 xos << setw(6) << itr1->first;
793 itr1 = lp._to_internal.begin();
794 while(itr1 != lp._to_internal.end())
796 xos << setw(6) << itr1->second;
816 template<
typename internal_index_type,
typename external_index_type>
836 #endif // ifndef RECORD_MAP_IMPL_H internal_index_type internal_id(external_index_type xexternal_id) const
The internal id corresponding to xexternal_id.
static T invalid()
The invalid index value.
T pod_type
An integral type representing a relative index.
external_index_type external_id(internal_index_type xinternal_id) const
The external id corresponding to xinternal_id.
void put_scratch_external_id(external_index_type xid)
Sets the value of the external id scratch register to xid.
bool operator==(const record_map &xother) const
True if same external_id and internal_id.
void put_scratch_internal_id(internal_index_type xid)
Sets the value of the internal id scratch register to xid.
bool is_empty() const
True if there are no entries in the map.
const_iterator end() const
The end of the range of internal ids contained in this.
bool contains_internal_id(internal_index_type xint_id) const
True if this map contains an entry for internal index xint_id.
Features describing T as an index type.
record_map()
Default constructor.
external_index_type external_id_ub() const
The maximum external id in this map.
bool external_ids_sequential() const
True if sequentially assigning external ids.
size_type ct() const
The number of entries in the map.
internal_index_type internal_id_ub() const
The maximum internal id in this map.
const_iterator begin() const
The beginning of the range of internal ids contained in this.
internal_index_type scratch_internal_id() const
The value of the internal id scratch register. The scratch register is a convenient place for a clien...
bool ub_is_max() const
True if internal_id_ub and external_id_ub are in fact maxima; i.e. if there exists an entry (int_id...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
void clear()
Removes all entries.
bool internal_ids_sequential() const
True if sequentially assigning internal ids.
void remove_internal_id(internal_index_type xinternal_id)
Removes xinternal_id and its external image from the map.
virtual bool invariant() const
The class invariant.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
unordered::unordered_map< internal_index_type, external_index_type >::const_iterator const_iterator
The type of const iterator for this.
Namespace for the sheaves component of the sheaf system.
external_index_type scratch_external_id() const
The value of the external id scratch register. The scratch register is a convenient place for a clien...
void put_ids(internal_index_type xinternal_id, external_index_type xexternal_id)
Defines the mapping between xinternal_id and xexternal_id.
static T min()
The minimum valid value.
external_index_type put_internal_id(internal_index_type xinternal_id)
Defines a mapping between xinternal_id and a sequentially assigned external id. Returns the external ...
bool contains_external_id(external_index_type xext_id) const
True if this map contains an entry for external index xext_id.
Insert record_map& p into ostream& os.
void remove_external_id(external_index_type xexternal_id)
Removes xexternal_id and its internal image from the map.
static void put_pod(T &xindex, pod_type &xpod)
Sets the pod of index type xindex to xpod.
virtual ~record_map()
Destructor.
internal_index_type put_external_id(external_index_type xexternal_id)
Defines a mapping between xexternal_id and a sequentially assigned internal id.
void print() const
Prints the data members of this on cout. Intended for use debugging.
record_map & operator=(const record_map &xother)
Assignment operator.