21 #include "SheafSystem/interval_index_space_state.h" 22 #include "SheafSystem/assert_contract.h" 23 #include "SheafSystem/interval_index_space_handle.h" 24 #include "SheafSystem/interval_index_space_iterator.h" 25 #include "SheafSystem/deep_size.h" 26 #include "SheafSystem/hub_index_space_handle.h" 27 #include "SheafSystem/scoped_index.h" 38 const std::string& xname,
44 require(!xname.empty());
45 require(!xid_spaces.
contains(xname));
50 lstate->new_state(xid_spaces, xname, xis_persistent);
52 lstate->_merge_mode = xmerge_mode;
58 ensure(&result.
id_spaces() == &xid_spaces);
63 ensure(result.
name() == xname);
76 const std::string& xname,
84 require(!xname.empty());
85 require(!xid_spaces.
contains(xname));
90 lstate->new_state(xid_spaces, xid, xname, xis_persistent);
92 lstate->_merge_mode = xmerge_mode;
98 ensure(&result.
id_spaces() == &xid_spaces);
102 ensure(result.
index() == xid);
104 ensure(result.
name() == xname);
132 std::map<pod_type, pod_type>& xmap,
197 is_valid(xrange_begin) ? xrange_begin - 1 : xrange_begin;
199 map_type::iterator litr = xmap.find(xdomain_begin - 1);
200 if(litr != xmap.end())
204 pod_type lold_range_end = litr->second;
206 if(xmerge_mode && (lold_range_end == left_of_xrange_begin))
224 if(xmerge_mode && (lold_range_begin == xrange_begin))
233 xmap[xdomain_begin-1] =
234 is_valid(lold_range_begin) ? lold_range_begin - 1 : lold_range_begin;
242 litr = xmap.find(xdomain_end);
243 if(litr != xmap.end())
247 if(xmerge_mode && (xrange_end == litr->second))
259 lold_range_end =
map_value(xdomain_end, xmap);
260 if(xmerge_mode && (xrange_end == lold_range_end))
269 xmap[xdomain_end] = xrange_end;
277 if(xmerge_mode && (xrange_end == lold_range_end))
287 xmap[xdomain_end] = xrange_end;
293 litr = xmap.lower_bound(xdomain_begin);
294 while(litr != xmap.end() && litr->first < xdomain_end)
297 litr = xmap.lower_bound(xdomain_begin);
317 map_type::const_iterator itr = xmap.lower_bound(xid);
318 if(itr != xmap.end() &&
is_valid(itr->second))
324 result = itr->second - (itr->first - xid);
429 require(xhub_begin <= xhub_end);
430 require(xbegin <= xend);
431 require((xhub_end - xhub_begin) == (xend - xbegin));
471 _ct += old_invalid_entry_ct;
475 ensure(
ct() >= old_ct);
476 ensure_for_range(
pod_type i=xhub_begin, i<=xhub_end, ++i,
pod(i) == xbegin+(i-xhub_begin));
477 ensure_for_range(
pod_type i=xbegin, i<=xend, ++i,
hub_pod(i) == xhub_begin+(i-xbegin));
515 require(xhub_begin <= xhub_end);
526 xhub_begin, xhub_end);
530 ensure(
ct() == old_ct + (xhub_end - xhub_begin + 1));
531 ensure(
next_id() == old_next_id + (xhub_end - xhub_begin + 1));
532 ensure_for_range(
pod_type i=xhub_begin, i<=xhub_end, ++i,
pod(i) == old_next_id+(i-xhub_begin));
572 require(xhub_begin <= xhub_end);
603 require(xbegin <= xend);
660 to_domain_type::const_iterator itr =
_to_domain.lower_bound(xhub_id);
667 result = itr->first + 1;
718 to_domain_type::const_iterator itr =
_to_domain.lower_bound(xhub_id);
754 ensure(is_basic_query);
790 size_type result = xhub_end - xhub_begin + 1;
792 pod_type lold_range_id = xhub_begin - 1;
794 to_domain_type::const_iterator itr =
_to_domain.lower_bound(xhub_begin);
796 while(itr !=
_to_domain.end() && itr->first <= xhub_end)
803 if(itr->first < xhub_end)
808 result -= (itr->first - lold_range_id);
815 result -= (xhub_end - lold_range_id);
822 lold_range_id = itr->first;
876 to_range_type::const_iterator itr =
_to_range.begin();
890 to_range_type::reverse_iterator ritr =
_to_range.rbegin();
895 _end = ritr->first + 1;
941 ensure(is_basic_query);
969 xos <<
"_to_range: " << endl;
973 xos <<
" (" << litr->first <<
", " << litr->second <<
")";
977 xos <<
"_to_domain: " << endl;
981 xos <<
" (" << litr->first <<
", " << litr->second <<
")";
987 ensure(is_basic_query);
1005 require(xrange_begin <= xrange_end);
1006 require(xdomain_begin <= xdomain_end);
1007 require((xrange_end - xrange_begin) == (xdomain_end - xdomain_begin));
1012 xrange_begin, xrange_end,
1016 xdomain_begin, xdomain_end,
1021 ensure_for_range(
pod_type i=0, i<xrange_end-xrange_begin+1, ++i,
pod(xrange_begin+i) == xdomain_begin+i);
1022 ensure_for_range(
pod_type i=0, i<xdomain_end-xdomain_begin+1, ++i,
hub_pod(xdomain_begin+i) == xrange_begin+i);
1035 require(xbegin <= xend);
1052 to_domain_type::iterator litr =
_to_domain.lower_bound(lrange_begin);
1053 while((lrange_begin <= lend) && (litr !=
_to_domain.end()))
1058 if(litr->first <= lend)
1063 lrange_end = litr->first;
1064 ldomain_end = litr->second;
1072 ldomain_end = lmapped_range_end;
1080 pod_type ldomain_begin = ldomain_end - (lrange_end - lrange_begin);
1086 result += lrange_end - lrange_begin + 1;
1089 lrange_begin = lrange_end + 1;
1119 ensure(
contains(xdomain_id, xrange_id));
1144 ensure(
contains(old_next_id, xrange_id));
1162 define_old_variable(
pod_type old_itr_pod = xitr.
pod());
1173 ensure(
contains(old_itr_pod, xrange_id));
1174 ensure(xitr.
pod() == old_itr_pod+1);
1175 ensure(xitr.
hub_pod() == old_itr_hub_pod);
1217 define_old_variable(
pod_type old_itr_id = xitr.
pod());
1228 ensure(xitr.
is_done() || xitr.
pod() > old_itr_id);
1251 ensure(unexecutable(
"map rep is empty"));
1278 to_range_type::iterator litr =
_to_range.begin();
1279 assertion(!
is_valid(litr->second));
1284 pod_type lrange_end = litr->second;
1297 lrange_end = litr->second;
1301 lct = (litr->first - lold_domain_end);
1307 lrange_begin = (lrange_end - lct);
1317 lold_domain_end = litr->first;
1321 to_range_type::iterator lerase_itr = litr;
1329 if(ldomain_end != lold_domain_end)
1335 ensure(unexecutable(
"map rep is gathered"));
1389 ensure(result >= 0);
1416 (void) scattered_insertion_index_space_state::operator=(xother);
1421 ensure((*
this) == xother);
1445 to_range_type::const_iterator itr =
_to_range.lower_bound(xid);
1451 ensure(is_basic_query);
1466 to_domain_type::const_iterator itr =
_to_domain.lower_bound(xhub_id);
1472 ensure(is_basic_query);
1540 ensure(result >= 0);
1559 ensure(result >= 0);
1602 handles().release(reinterpret_cast<interval_index_space_handle&>(xid_space));
1606 ensure(is_basic_query);
1624 bool result = (lid_space != 0) && handles().allocated(*lid_space);
1628 ensure(is_basic_query);
1640 sheaf::interval_index_space_state::
1651 ensure(is_basic_query);
1677 ensure(result >= 0);
1696 ensure(result >= 0);
1739 iterators().release(reinterpret_cast<interval_index_space_iterator&>(xitr));
1743 ensure(is_basic_query);
1761 bool result = (litr != 0) && iterators().allocated(*litr);
1765 ensure(is_basic_query);
1777 sheaf::interval_index_space_state::
1788 ensure(is_basic_query);
1806 static const std::string result(
"interval_index_space_state");
1822 ensure(result != 0);
1835 sheaf::interval_index_space_state::
1866 require(other != 0);
1926 size_t result = xinclude_shallow ?
sizeof(xn) : 0;
1938 result += deep_size<pod_type, pod_type, map_policy_type>(xn.
_to_domain,
1943 result += deep_size<pod_type, pod_type, map_policy_type>(xn.
_to_range,
1948 ensure(result >= 0);
An implementation of class scattered_insertion_index_space_handle that has a interval id space state...
virtual pod_type unglued_hub_pod(pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in this id space.
An STL map implementation of class scattered_insertion_index_space_state optimized to efficiently rep...
bool contains_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the unglued hub id space. synonym for contains...
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
size_type invalid_entry_ct(pod_type xhub_begin, pod_type xhub_end) const
The number of entries in the interval [xhub_begin, xhub_end] that have invalid map values...
size_type ct() const
The number of members.
virtual pod_type index() const
Index of this space.
bool in_scope() const
True if and only if scope() contains an entry for pod().
An abstract iterator over the ids of an id space.
to_range_type _to_range
The representation of the domain id to range id map.
pod_type interval_end(const scoped_index &xid) const
The end of the interval containing xid.hub_pod. synonym for internval_end(xid.hub_pod()).
virtual void map_rep_clear()
Removes all entrires from the map representation.
virtual bool conforms_to_state(const index_space_collection &xhost, pod_type xlocal_id) const
True if this conforms to the handle type required by the state with local scope id xlocal_id in the h...
virtual bool allocated_id_space(const index_space_handle &xid_space) const
True if and only if id space handle xid_space was allocated by the handle pool.
pod_type pod() const
The current id in the iteration.
size_type remove_hub_interval(pod_type xhub_begin, pod_type xhub_end)
Removes the equivalance associated with the interval [xhub_begin, xhub_end]. Returns the number of en...
static size_type iterator_pool_ct()
The number of iterators in the pool.
virtual bool is_persistent() const
True if this id space should be written to disk.
bool merge_mode() const
True if and only if compatible intervals should be merged.
static interval_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, bool xis_persistent, bool xmerge_mode)
Create a new interval id space in the id space family xid_space at the next available id space index ...
void put_merge_mode(bool xvalue)
Sets merge_mode() to xvalue.
to_domain_type _to_domain
The representation of the range id to domain id map.
virtual void detach()=0
Detach this handle form its state, if any.
An implementation of class explicit_index_space_state that supports either gathered or scattered inse...
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
virtual const index_space_family & id_spaces() const
The id space family for this (const version).
std::map< pod_type, pod_type > map_type
The type of the id maps.
virtual void detach()=0
Detach this handle form its state, if any.
pod_type interval_begin(const scoped_index &xid) const
The beginning of the interval containing xid.hub_pod(). synonym for internval_begin(xid.hub_pod()).
void print_map_rep(std::ostream &xos) const
Inserts the map representation into ostream xos.
friend SHEAF_DLL_SPEC size_t deep_size(const interval_index_space_state &xn, bool xinclude_shallow)
The deep size of interval_index_space_state& xn.
void attach(explicit_index_space_handle &xid_space) const
Attach the id space handle xid_space to this state.
pod_type _end
Ending id of this space.
virtual size_type capacity() const
The number of ids reserved in memory.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
virtual interval_index_space_state * clone() const
Virtual constructor; create a new instance of the same type at this.
bool merge_mode() const
True if and only if compatible intervals should be merged.
bool is_done() const
True if iteration is finished.
virtual bool invariant() const
Class invariant.
virtual void map_rep_gather()
Gathers the map representation into an interval.
An immutable abstract state for a space of alternate integer identifiers (aliases) for a subset of th...
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
virtual index_space_iterator & get_iterator() const
Allocates an id space iterator from the iterator pool.
std::string name() const
Name of this space.
Do not call deep_size on either the key or value.
virtual bool allocated_iterator(const index_space_iterator &xitr) const
True if and only if id space iterator xitr was allocated by the iterator pool.
An index within the external ("client") scope of a given id space.
virtual bool is_attached() const
True if this handle is attached to a state.
void insert_interval(pod_type xbegin, pod_type xend, const scoped_index &xhub_begin, const scoped_index &xhub_end)
Make the closed interval [xbegin, xend] equivalent to [xbegin.hub_pod(), xhub_end.hub_pod()]. synonym for insert_interval(xbegin, xend, xhub_begin.hub_pod(), xhub_end.hub_pod()).
void invalidate_extrema()
Invalidate the extrema.
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 void map_rep_push_back(pod_type xrange_id)
Inserts entry (next_id(), xrange_id) into the map representation.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
virtual interval_index_space_state & operator=(const explicit_index_space_state &xother)
Assignment operator.
An iterator over an id space in which the equivalence between the ids in the space and the hub id spa...
bool is_explicit_interval(pod_type xid)
True, if and only if the id space interval that contains index xid is an explicit interval...
static pod_type map_value(pod_type xid, const std::map< pod_type, pod_type > &xmap)
The value of map xmap at id xid.
virtual ~interval_index_space_state()
Destructor.
pod_type _capacity
The capacity of this map.
virtual void update_extrema_after_remove()
Update the id extrema after a remove operation.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
static void insert_map_interval(pod_type xdomain_begin, pod_type xdomain_end, pod_type xrange_begin, pod_type xrange_end, std::map< pod_type, pod_type > &xmap, bool xmerge_mode)
Maps the interval [xdomain_begin, xdomain_end] to.
virtual index_space_handle & get_id_space() const
The id space handle with this state.
void map_rep_insert_interval(pod_type xdomain_begin, pod_type xdomain_end, pod_type xrange_begin, pod_type xrange_end)
Inserts the intervals [xdomain_begin, xdomain_end] and [xrange_begin, xrange_end] into the map repres...
virtual size_type map_rep_remove_entry(pod_type xid, bool xis_range_id)
Removes the entry containing range id xid (xis_range_id true) or domain id xid (xis_range_id false) f...
virtual void update_extrema()
Update the id extrema.
virtual bool operator==(const explicit_index_space_state &xother) const
True if this is equivalent to xother.
virtual void release_id_space(index_space_handle &xid_space) const
Release the id space handle xid_space.
virtual pod_type pod(pod_type xid) const
The pod index in this space equivalent to xid in the hub id space.
size_type _ct
The number of members.
bool invariant_check() const
True if invariant checking is enabled.
virtual void map_rep_insert_entry(pod_type xdomain_id, pod_type xrange_id)
Inserts entry (xdomain_id, xrange_id) into the map representation.
pod_index_type pod_type
The "plain old data" index type for this.
virtual bool contains_unglued_hub(pod_type xid) const
True if this space contains an id equivalent to xid in the unglued hub id space.
int_type pod_index_type
The plain old data index type.
bool _merge_mode
True if and only if compatible intervals should be merged.
virtual void reserve(size_type xcapacity)
Reserve enough memory for xcapacity number of ids.
static size_type handle_pool_ct()
The number of handles in the pool.
virtual void release_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
static size_type handle_pool_deep_size()
The deep size of the handle pool.
bool is_empty() const
True if there are no ids in the space.
virtual void map_rep_push(index_space_iterator &xitr, pod_type xrange_id)
Inserts entry (xitr.pod(), xrange_id) into the map representation. Increments all domain ids greater ...
Factory and container for a family of id spaces.
virtual const std::string & class_name() const
The name of this class.
interval_index_space_state()
Default constructor.
virtual bool contains(pod_type xid) const
True if this space contains id xid.
void push_interval(const scoped_index &xhub_begin, const scoped_index &xhub_end)
Push the closed interval [xhub_begin.hub_pod(), xhub_end.hub_pod()] to the end of this space...
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
static factory< explicit_index_space_state > & id_space_factory()
A factory for making descendants of this class.
pod_type _begin
Beginning id of this space.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
pod_type next_id() const
The id inserted by the next call to push_back.
bool is_same_type(const any *other) const
True if other is the same type as this.
void enable_invariant_check() const
Enable invariant checking.
size_type remove_interval(const scoped_index &xhub_begin, const scoped_index &xhub_end)
Removes the equivalance associated with the interval [xhub_begin.hub_pod(), xhub_end.hub_pod()]. synonym for remove_hub_interval(xhub_begin.hub_pod(), xhub_end.hub_pod()). Returns the number of entries actually removed, if any.
virtual bool is_attached() const
True if this iterator is attached to a state.
pod_type hub_pod(pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in this id space. synonym for unglued_hub...
A reallocated pool of objects of type T. Objects in the pool are either allocated or stored in a free...
size_type map_rep_remove_interval(pod_type xbegin, pod_type xend, bool xis_range_id)
Makes the interval [xbegin, xend) and its image unmapped in the map representation. Returns the number of entries actually unmapped, if any.
pod_type hub_pod() const
The current unglued hub id in the iteration. synonym for unglued_hub_pod().
static size_type iterator_pool_deep_size()
The deep size of the iterator pool.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.