20 #include "SheafSystem/depth_first_iterator.h" 21 #include "SheafSystem/index_space_iterator.h" 22 #include "SheafSystem/poset_state_handle.h" 23 #include "SheafSystem/assert_contract.h" 24 #include "SheafSystem/subposet.h" 25 #include "SheafSystem/zn_to_bool.h" 203 result = (
_anchor != 0) && (_has_visited != 0) && (_filter != 0);
345 result = (
_state == NOT_A_STATE);
419 #ifdef DIAGNOSTIC_OUTPUT 424 cout <<
"\t _index: " <<
_index;
431 case INIT_COVER_ITERATOR:
479 case TEST_HAS_VISITED:
502 case INC_COVER_ITERATOR:
527 case ERASE_COVER_ITERATOR:
537 #ifdef DIAGNOSTIC_OUTPUT 538 cout <<
"in depth_first_iterator::next::ERASE_COVER_ITERATOR " 678 case EXECUTE_PREVISIT_ACTION:
687 #ifdef DIAGNOSTIC_OUTPUT 689 cout <<
"index: " <<
_index 690 <<
" filter value: " << boolalpha <<
filter(
_index) << noboolalpha
717 case EXECUTE_LINK_ACTION:
719 #ifdef DIAGNOSTIC_OUTPUT 749 case EXECUTE_POSTVISIT_ACTION:
811 require(
anchor().state_is_read_accessible());
815 define_old_variable(
bool old_descending =
_descending);
816 define_old_variable(
bool old_strict =
_strict);
843 ensure(
strict() == old_strict);
866 require(xreset ?
anchor().state_is_read_accessible():
true);
897 require(
anchor().host()->contains_member(xhub_id,
true));
901 bool result = (*_has_visited)[xhub_id];
914 require(
anchor().host()->contains_member(xid,
true));
918 bool result = (*_has_visited)[xid.
hub_pod()];
931 require(
anchor().state_is_read_accessible());
934 require(
anchor().host()->is_same_state(xmbr->
host()));
951 require(
anchor().state_is_read_accessible());
952 require(
anchor().host()->contains_member(xhub_id));
956 _has_visited->
put(xhub_id, xvalue);
973 require(
anchor().state_is_read_accessible());
974 require(
anchor().host()->contains_member(xid));
1110 require(
action() == LINK_ACTION);
1114 _state = ERASE_COVER_ITERATOR;
1197 ensure(
order() == NOT_AN_ORDER);
1243 ensure(unexecutable(
this is
first member of iteration or
is_done()));
1275 delete _has_visited;
1371 require(
anchor().state_is_read_write_accessible());
1374 require(
anchor().host()->contains_member(xmbr));
1400 require(
anchor().state_is_read_accessible());
1401 require(
anchor().host()->contains_member(xmbr));
1463 ensure(
order() == xorder);
1482 define_old_variable(
bool old_descending =
_descending);
1483 define_old_variable(
bool old_strict =
_strict);
1498 #ifdef DIAGNOSTIC_OUTPUT 1500 cout <<
"in depth_first_iterator::initialize_traversal(xanchor): " << endl
1501 <<
"_anchor = " << *
_anchor << endl
1502 <<
"_filter = " << _filter << endl;
1510 ensure(
anchor().is_same_state(&xanchor));
1515 ensure(
strict() == old_strict);
1529 require(
anchor().state_is_read_accessible());
1530 require(
anchor().host()->contains_member(xanchor_hub_id));
1535 define_old_variable(
bool old_descending =
_descending);
1536 define_old_variable(
bool old_strict =
_strict);
1538 define_old_variable(
int old_anchor_version =
anchor().version());
1549 #ifdef DIAGNOSTIC_OUTPUT 1551 cout <<
"in depth_first_iterator::initialize_traversal(xanchor_hub_id): " << endl
1552 <<
"_anchor = " << *
_anchor << endl
1553 <<
"_filter = " << _filter << endl;
1562 ensure(
anchor().version() == old_anchor_version);
1565 ensure(
strict() == old_strict);
1579 require(
anchor().state_is_read_accessible());
1580 require(
anchor().host()->contains_member(xanchor_id));
1585 define_old_variable(
bool old_descending =
_descending);
1586 define_old_variable(
bool old_strict =
_strict);
1588 define_old_variable(
int old_anchor_version =
anchor().version());
1598 ensure(
anchor().version() == old_anchor_version);
1601 ensure(
strict() == old_strict);
1666 if(_has_visited != 0)
1668 delete _has_visited;
1679 ensure(_has_visited != 0);
1691 return _has_visited;
1698 _has_visited = xhas_visited;
1735 if(lversion == COARSEST_COMMON_REFINEMENT_VERSION)
1766 ensure(_filter != 0);
1787 define_old_variable(
bool old_descending =
_descending);
1788 define_old_variable(
bool old_strict =
_strict);
1797 ensure(_filter != 0);
1800 ensure(
strict() == old_strict);
1828 ensure(_filter != 0);
1854 ensure(_filter != 0);
1871 require(!xfilter_name.empty() ?
1878 if(xfilter_name.empty())
1891 ensure(_filter != 0);
1894 ensure(!xfilter_name.empty() ?
1961 "INIT_COVER_ITERATOR",
1963 "INC_COVER_ITERATOR",
1964 "ERASE_COVER_ITERATOR",
1968 "EXECUTE_PREVISIT_ACTION",
1969 "EXECUTE_LINK_ACTION",
1970 "EXECUTE_POSTVISIT_ACTION",
1981 EXECUTE_PREVISIT_ACTION, EXECUTE_PREVISIT_ACTION,
1982 TEST_HAS_VISITED, TEST_PATH_TAIL,
1983 INC_COVER_ITERATOR, DESCEND,
1984 TEST_HAS_VISITED, TEST_PATH_TAIL,
1985 NOT_A_STATE, NOT_A_STATE,
1986 EXECUTE_PREVISIT_ACTION, EXECUTE_PREVISIT_ACTION,
1988 INC_COVER_ITERATOR, INC_COVER_ITERATOR,
1989 INIT_COVER_ITERATOR, INIT_COVER_ITERATOR,
1990 NOT_A_STATE, NOT_A_STATE,
1991 NOT_A_STATE, NOT_A_STATE
2001 INIT_COVER_ITERATOR, INIT_COVER_ITERATOR,
2002 TEST_HAS_VISITED, EXECUTE_POSTVISIT_ACTION,
2003 INC_COVER_ITERATOR, DESCEND,
2004 TEST_HAS_VISITED, EXECUTE_POSTVISIT_ACTION,
2005 NOT_A_STATE, NOT_A_STATE,
2006 INIT_COVER_ITERATOR, INIT_COVER_ITERATOR,
2008 INC_COVER_ITERATOR, INC_COVER_ITERATOR,
2009 NOT_A_STATE, NOT_A_STATE,
2010 NOT_A_STATE, NOT_A_STATE,
2011 TEST_PATH_TAIL, TEST_PATH_TAIL
2020 INIT_COVER_ITERATOR, INIT_COVER_ITERATOR,
2021 TEST_HAS_VISITED, TEST_PATH_TAIL,
2022 EXECUTE_LINK_ACTION, DESCEND,
2023 TEST_HAS_VISITED, TEST_PATH_TAIL,
2024 TEST_HAS_VISITED, TEST_PATH_TAIL,
2025 INIT_COVER_ITERATOR, INIT_COVER_ITERATOR,
2027 EXECUTE_LINK_ACTION, EXECUTE_LINK_ACTION,
2028 NOT_A_STATE, NOT_A_STATE,
2029 INC_COVER_ITERATOR, INC_COVER_ITERATOR,
2030 NOT_A_STATE, NOT_A_STATE
2040 EXECUTE_PREVISIT_ACTION, EXECUTE_PREVISIT_ACTION,
2041 TEST_HAS_VISITED, EXECUTE_POSTVISIT_ACTION,
2042 INC_COVER_ITERATOR, DESCEND,
2043 TEST_HAS_VISITED, EXECUTE_POSTVISIT_ACTION,
2044 NOT_A_STATE, NOT_A_STATE,
2045 EXECUTE_PREVISIT_ACTION, EXECUTE_PREVISIT_ACTION,
2047 INC_COVER_ITERATOR, INC_COVER_ITERATOR,
2048 INIT_COVER_ITERATOR, INIT_COVER_ITERATOR,
2049 NOT_A_STATE, NOT_A_STATE,
2050 TEST_PATH_TAIL, TEST_PATH_TAIL
2059 EXECUTE_PREVISIT_ACTION, EXECUTE_PREVISIT_ACTION,
2060 TEST_HAS_VISITED, EXECUTE_POSTVISIT_ACTION,
2061 EXECUTE_LINK_ACTION, DESCEND,
2062 TEST_HAS_VISITED, EXECUTE_POSTVISIT_ACTION,
2063 TEST_HAS_VISITED, EXECUTE_POSTVISIT_ACTION,
2064 EXECUTE_PREVISIT_ACTION, EXECUTE_PREVISIT_ACTION,
2066 EXECUTE_LINK_ACTION, EXECUTE_LINK_ACTION,
2067 INIT_COVER_ITERATOR, INIT_COVER_ITERATOR,
2068 INC_COVER_ITERATOR, INC_COVER_ITERATOR,
2069 TEST_PATH_TAIL, TEST_PATH_TAIL
2072 const sheaf::depth_first_iterator::transition_fcn_type
virtual bool has_name(const std::string &xname, bool xauto_access=false) const
True if xname is a name for this.
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
poset_state_handle * host() const
The poset which this is a handle to a component of.
virtual void force_is_done()
Force the iterator to be done.
void mark_visited(abstract_poset_member *xmbr)
Mark xmbr as visited. Warning: this function can change the state of the iteration in unpredictable w...
A client handle for a subposet.
bool is_valid() const
True if this is a valid id.
zn_to_bool * members() const
Get the members of the subposet.
int version(bool xunalias=true) const
The (possibly aliased) version of this component. The version of the host used when evaluating proper...
static const iterator_state BIORDER_TRANSITION_FCN[NOT_A_STATE-1][FAIL+1]
The predefined transition function for biorder iteration. Defines the next state for each combination...
virtual bool is_initialized() const
True if this has been initialized for iteration with respect to a specific anchor.
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
bool visit_once() const
True if traversal should only visit a member once; that is, it should not revisit members it has alre...
index_space_iterator & get_cover_id_space_iterator(bool xlower, pod_index_type xmbr_hub_id) const
Allocates an iterator for the lower (xlower true) or upper (xlower false) cover id space of the membe...
void initialize_order(order_type xorder)
Initializes _order and _transition_fcn.
static const iterator_state TRIORDER_TRANSITION_FCN[NOT_A_STATE-1][FAIL+1]
The predefined transition function for triorder iteration. Defines the next state for each combinatio...
pod_index_type version_index() const
The subposet index for the filter associated with version().
void make_false_sa()
Constant function false, self-allocated. Note on terminology: "false" is a keyword, so this function can not be just "false"
void initialize_filter()
Initializes the filter subposet from the client filter.
action_type action() const
The type of action the client should take when the iterator returns control to the client...
abstract_poset_member * _anchor
The top member of the down set being iterated over.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
void erase_cover()
Schedules the lesser member entry in the cover of the greater member of the current link for deletion...
void clear_cover(bool xlower, pod_index_type xmbr_hub_id)
Clears the lower (xlower true) or upper (xlower false) cover set of the member with hub id xmbr_hub_i...
static const char * NULL_FILTER
Placeholder for null filter.
void put_visit_once(bool xvisit_once)
Set visit_once() to xvisit_once.
A client handle for a general, abstract partially order set.
virtual bool includes_subposet(pod_index_type xsubposet_hub_id, bool xauto_access=true) const
True if this poset includes subposet with hub id xsubposet_hub_id.
void initialize_anchor(const abstract_poset_member &xanchor)
Initializes the anchor.
action_type _action
The type of action the client should take; the state of the iterator.
std::stack< pod_index_type > _filtered_path_tail
The tail of the filtered path to the current member of the iteration. Contains only members which pas...
virtual bool anchor_is_ancestor_of(const abstract_poset_member &xmbr) const
True if xmbr conforms to the type of anchor of this.
bool is_same_state(const poset_state_handle *xhost, pod_index_type xhub_id) const
True is this is attached to state with hub id xhub_id in host xhost.
void put(int i, bool value)
Sets i-th member to value.
bool _visit_once
True if traversal should only visit a member once; that is, it should not revisit members it has alre...
void invalidate()
Make this id invalid.
size_t depth() const
The length of the path from anchor() to the current member.
order_type
The types of order in which the iterator will visit the members of the poset. Determines which action...
const scoped_index & index() const
The index of the component state this handle is attached to.
virtual void next()=0
Makes id() the next id in the iteration.
subposet _client_filter
The filter specified by the client.
depth_first_iterator()
Default constructor; creates an unattached iterator,.
bool is_maximal() const
True if the current member has no greater member within the subposet visited by this iterator...
void attach_to_state(const poset_state_handle *xhost, pod_index_type xhub_id)
Attach this handle to the state with hub id xhub_id in the current version of host xhost...
Abstract base class with useful features for all objects.
A map from Zn (the integers mod n) to bools. A characteristic function used to represent subsets of Z...
virtual void detach_item()
Detaches the item handle to the current index. Empty in this class; intended for redefinition in desc...
bool is_done() const
True if iteration is finished.
virtual abstract_poset_member & anchor()
The poset member whose downset is being iterated over; the top member of the domain of iteration (mut...
order_type order() const
The order of the iteration. Determines which actions are exported to the client.
const iterator_state(* _transition_fcn)[FAIL+1]
The current state transition function for the iterator finite state machine. Points to one of the pre...
virtual pod_index_type version_index(int xversion) const
The subposet hub id of the whole() subposet for version xversion.
action_type
The types of action a client should take when the iterator returns control to the client...
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 non-void state.
scoped_index _lesser_index
The index of the lesser member of the current link.
virtual void initialize_has_visited(const abstract_poset_member &xanchor)
Initializes the has_visited markers.
void release_cover_id_space_iterators()
Release the cover iterators back to the pool of iterators.
bool descending() const
True if iterating over down set of anchor.
bool _new_filter
True if this allocated a new filter;.
static const iterator_state PREORDER_TRANSITION_FCN[NOT_A_STATE-1][FAIL+1]
The predefined transition function for postorder iteration. Defines the next state for each combinati...
void next()
Makes this the next member of the subset.
depth_first_iterator & operator=(const depth_first_iterator &xother)
Assignment operator.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
scoped_index _greater_index
The index of the greater member of the current link.
virtual void release_access(bool xall=false) const
Release access. If xall is true, release all levels of access. Otherwise, release one level of access...
const scoped_index & lesser_index() const
The index of the lesser member of the current link.
const scoped_index & greater_index() const
The index of the greater member of the current link.
zn_to_bool * members() const
The characteristic function for the members of this.
index_space_iterator * _path_head
The head of the path to the current member of the iteration lesser_index() == this->index() == **_pat...
void mark_not_visited(abstract_poset_member *xmbr)
Mark xmbr as not visited. Warning: this function can change the state of the iteration in unpredictab...
abstract_poset_member * clone(bool xnew_state, bool xauto_access=true) const
Virtual constructor; makes a new handle of the same type as this, attached to a new state (xnew_state...
static const char * iterator_state_names[NOT_A_STATE+1]
The names of the iterator states, convenient for debugging.
const bool NO_RESET
Iteration marker reset control.
static const transition_fcn_type STD_TRANSITION_FCNS[NOT_AN_ORDER+1]
The set of predefined transition functions.
bool is_done() const
True if iteration finished.
index_space_iterator * _path_head_lc
The lower cover iterator for the head of the path to the current member of the iteration.
static const iterator_state LINKORDER_TRANSITION_FCN[NOT_A_STATE-1][FAIL+1]
The predefined transition function for linkorder iteration. Defines the next state for each combinati...
virtual void detach_from_state()
Detach this handle from its state, if any.
void first()
Moves this to the first member of the iteration.
bool _descending
True if iterating over the up/down set of anchor.
iterator_state _state
The current state of iteration.
virtual void reset(bool xreset_markers=true)
Restarts the iteration over the down set of anchor().
void put_has_visited(pod_index_type xhub_id, bool xvalue)
Set the visited marker for hub id xhub_id to xvalue. Intended for use reseting iterator without havin...
bool invariant_check() const
True if invariant checking is enabled.
virtual ~depth_first_iterator()
Destructor.
std::stack< index_space_iterator * > _path_tail
The tail of the path to the current member of the iteration greater_index() == **(_path_tail.top()) == greater member of current link.
void initialize_traversal(const abstract_poset_member &xanchor)
Initializes the anchor, has_visited markers and filter.
int_type pod_index_type
The plain old data index type.
zn_to_bool * has_visited() const
The marker bit vector. /.
virtual scoped_index member_index_ub() const
The upper bound on the member_index;.
iterator_state
The states for the finite state machine that controls iteration.
bool invariant() const
The class invariant.
int ct(bool xreset=false)
The number of members of the iteration set, from the current member to the end, inclusive. If xreset, reset before computing the count.
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
bool _strict
True if iterating over the strict up/down set of anchor.
void b_and_sa(const zn_to_bool *other)
This AND other, self-allocated.
subposet_state & member(pod_index_type xindex)
The subposet with index xindex (mutable version).
void attach_to_state(const namespace_poset *xns, const poset_path &xpath, bool xauto_access=true)
Attach to the state specified by path xpath in the namespace xns.
virtual depth_first_iterator * clone() const
Make a new instance of the same type as this.
virtual void get_read_access() const
Get read access to the state associated with this.
An abstract client handle for a member of a poset.
void extend_to(int xub)
Make the upper bound at least xub.
subposet & filter()
The subposet which is the filter; Defines what is passed, not what is blocked.
static const iterator_state POSTORDER_TRANSITION_FCN[NOT_A_STATE-1][FAIL+1]
The predefined transition function for postorder iteration. Defines the next state for each combinati...
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
std::string version_name() const
The subposet name for the filter associated with version().
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
bool is_same_type(const any *other) const
True if other is the same type as this.
virtual void attach_item()
Attaches the item handle to the current index. Empty in this class; intended for redefinition in desc...
void enable_invariant_check() const
Enable invariant checking.
void force_is_done()
Makes is_done() true.
bool strict() const
True if iterating over xstrict up/down set of anchor.
void release_cover_id_space_iterator(index_space_iterator &xcover_itr) const
Returns xcover_itr to the pool of id space iterators.
poset_powerset_state & powerset() const
The set of subposets of this poset.
scoped_index _index
The index of the lesser end of the current link; the current item in the iteration.
pod_type hub_pod() const
The current unglued hub id in the iteration. synonym for unglued_hub_pod().
order_type _order
The order of the iteration.
virtual const scoped_index & member_id(bool xauto_access) const
An id in the member hub id space; intended for copying to initialize ids to the member id space...
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
const scoped_index & index() const
The index of the current member of the iteration.