Automatic generation produced by ISE Eiffel

Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:
indexing description: "Compact trees as active structures that may be traversed using a cursor" status: "See notice at end of class" names: compact_cursor_tree, cursor_tree representation: array access: cursor, membership size: resizable contents: generic date: "$Date: 2001-11-16 20:32:23 +0000 (Fri, 16 Nov 2001) $" revision: "$Revision: 51435 $" class COMPACT_CURSOR_TREE [G] create make feature -- Initialization make (i: INTEGER) is -- Create an empty tree. -- i is an estimate of the number of nodes. do last := 1 active := 1 above := True create item_table.make (1, i + 1) create next_sibling_table.make (1, i + 1) create first_child_table.make (1, i + 1) ensure is_above: above is_empty: is_empty end feature -- Access child_item (i: INTEGER): G is -- Item in i-th child -- (from CURSOR_TREE) require -- from CURSOR_TREE argument_within_bounds: i >= 1 and then i <= arity not_off: not off local pos: CURSOR do pos := cursor down (i) Result := item go_to (pos) end cursor: CURSOR is -- Current cursor position do create {COMPACT_TREE_CURSOR} Result.make (active, after, before, below, above) end has (v: like item): BOOLEAN is -- Does structure include an occurrence of v? -- (Reference or object equality, -- based on object_comparison.) do if object_comparison then item_table.compare_objects else item_table.compare_references end Result := item_table.has (v) ensure -- from CONTAINER not_found_in_empty: Result implies not is_empty end index_of (v: like item; i: INTEGER): INTEGER is -- Index of i-th occurrence of v. -- 0 if none. -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) require -- from LINEAR positive_occurrences: i > 0 local occur, pos: INTEGER do if object_comparison and v /= void then from start pos := 1 until off or (occur = i) loop if item /= void and then v.is_equal (item) then occur := occur + 1 end preorder_forth pos := pos + 1 end else from start pos := 1 until off or (occur = i) loop if item = v then occur := occur + 1 end preorder_forth pos := pos + 1 end end if occur = i then Result := pos - 1 end ensure -- from LINEAR non_negative_result: Result >= 0 end item: G is -- Current item require -- from TRAVERSABLE not_off: not off require -- from ACTIVE readable: readable do Result := item_table.item (active) end occurrences (v: G): INTEGER is -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) do if object_comparison then item_table.compare_objects else item_table.compare_references end Result := item_table.occurrences (v) ensure -- from BAG non_negative_occurrences: Result >= 0 end parent_item: G is -- Item in parent. -- (from CURSOR_TREE) require -- from CURSOR_TREE not_on_root: not is_root local pos: CURSOR do pos := cursor up Result := item go_to (pos) end search (v: like item) is -- Move to first position (at or after current -- position) where item and v are equal. -- (Reference or object equality, -- based on object_comparison.) -- If no such position ensure that exhausted will be true. -- (from LINEAR) do if object_comparison and v /= void then from until exhausted or else (item /= void and then v.is_equal (item)) loop preorder_forth end else from until exhausted or else v = item loop preorder_forth end end ensure -- from LINEAR object_found: (not exhausted and object_comparison) implies equal (v, item) item_found: (not exhausted and not object_comparison) implies v = item end feature {NONE} -- Access linear_has (v: like item): BOOLEAN is -- Does structure include an occurrence of v? -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) do start if not off then search (v) end Result := not exhausted ensure -- from CONTAINER not_found_in_empty: Result implies not is_empty end linear_occurrences (v: G): INTEGER is -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) do from start search (v) until exhausted loop Result := Result + 1 preorder_forth search (v) end end feature -- Measurement arity: INTEGER is -- Number of children require -- from HIERARCHICAL not_off: not off local index: INTEGER do index := first_child_table.item (active) from until index <= 0 loop Result := Result + 1 index := next_sibling_table.item (index) end end breadth: INTEGER is -- Breadth of current level -- (from CURSOR_TREE) local l: INTEGER pos: CURSOR do l := level if l > 0 then pos := cursor go_above Result := breadth_of_level_from_active (l + 1) go_to (pos) end end count: INTEGER is -- Number of items in subtree do Result := last - free_list_count - 1 end depth: INTEGER is -- Depth of the tree -- (from CURSOR_TREE) local pos: CURSOR do if not is_empty then pos := cursor go_above Result := depth_from_active - 1 go_to (pos) end end level: INTEGER is -- Level of current node in tree -- (Root is on level 1) -- (from CURSOR_TREE) local pos: CURSOR do from pos := cursor until above loop Result := Result + 1 up end go_to (pos) end feature -- Status report above: BOOLEAN -- Is there no valid cursor position above the cursor? after: BOOLEAN -- Is there no valid cursor position to the right of cursor? before: BOOLEAN -- Is there no valid cursor position to the left of cursor? below: BOOLEAN -- Is there no valid cursor position below cursor? -- (from CURSOR_TREE) changeable_comparison_criterion: BOOLEAN is -- May object_comparison be changed? -- (Answer: yes by default.) -- (from CONTAINER) do Result := True end empty: BOOLEAN is obsolete "ELKS 2000: Use `is_empty' instead" -- Is there no element? -- (from CONTAINER) do Result := is_empty end exhausted: BOOLEAN is -- Has structure been completely explored? -- (from LINEAR) do Result := off ensure -- from LINEAR exhausted_when_off: off implies Result end extendible: BOOLEAN is -- May new items be added? -- (from CURSOR_TREE) do Result := not above and then (level = 1) implies is_empty end Full: BOOLEAN is False -- Is tree filled to capacity? (Answer: no.) is_empty: BOOLEAN is do Result := count = 0 end is_inserted (v: G): BOOLEAN is -- Has v been inserted by the most recent insertion? -- (By default, the value returned is equivalent to calling -- `has (v)'. However, descendants might be able to provide more -- efficient implementations.) -- (from COLLECTION) do Result := has (v) end is_leaf: BOOLEAN is -- Is cursor on a leaf? -- (from CURSOR_TREE) do if not off then Result := (arity = 0) end end is_root: BOOLEAN is -- Is cursor on root? do if not off then Result := next_sibling_table.item (active) = 0 end end isfirst: BOOLEAN is -- Is cursor on first sibling? local index: INTEGER do if not off then from index := next_sibling_table.item (active) until index <= 0 loop index := next_sibling_table.item (index) end Result := (index = 0) or else (first_child_table.item (- index) = active) end end islast: BOOLEAN is -- Is cursor on last sibling? do if not off then Result := (next_sibling_table.item (active) <= 0) end end object_comparison: BOOLEAN -- Must search operations use equal rather than = -- for comparing references? (Default: no, use =.) -- (from CONTAINER) off: BOOLEAN is -- Is there no current item? -- (True if is_empty) -- (from CURSOR_TREE) do Result := (after or before or below or above) end prunable: BOOLEAN is do Result := True end readable: BOOLEAN is -- Is there a current item that may be read? -- (from CURSOR_TREE) do Result := not off end valid_cursor (p: CURSOR): BOOLEAN is -- Can the cursor be moved to position p? local temp: COMPACT_TREE_CURSOR do temp ?= p if temp /= void then Result := (first_child_table.item (temp.active) /= removed_mark) end end valid_cursor_index (i: INTEGER): BOOLEAN is -- Can cursor be moved to i-th child? -- 0 is before and arity + 1 is after. -- (from CURSOR_TREE) do Result := i >= 0 and i <= (arity + 1) end writable: BOOLEAN is -- Is there a current item that may be modified? -- (from CURSOR_TREE) do Result := not off end feature {NONE} -- Status report linear_off: BOOLEAN is -- Is there no current item? -- (from LINEAR) do Result := is_empty or after end feature -- Status setting compare_objects is -- Ensure that future search operations will use equal -- rather than = for comparing references. -- (from CONTAINER) require -- from CONTAINER changeable_comparison_criterion do object_comparison := True ensure -- from CONTAINER object_comparison end compare_references is -- Ensure that future search operations will use = -- rather than equal for comparing references. -- (from CONTAINER) require -- from CONTAINER changeable_comparison_criterion do object_comparison := False ensure -- from CONTAINER reference_comparison: not object_comparison end feature -- Cursor movement back is -- Move cursor one position backward. local index, next: INTEGER do if below then check after end after := False before := True elseif after then after := False else from index := next_sibling_table.item (active) until index <= 0 loop index := next_sibling_table.item (index) end if index = 0 then before := True elseif first_child_table.item (- index) = active then before := True else from index := first_child_table.item (- index) next := next_sibling_table.item (index) until next = active loop index := next next := next_sibling_table.item (index) end active := index end end end breadth_forth is -- Move cursor to next position in breadth-first order. -- If the active node is the last in -- breadth-first order, the cursor ends up off. -- (from CURSOR_TREE) require -- from CURSOR_TREE not_off: not off local l: INTEGER do l := level level_forth if above and (l < depth) then start_on_level (l + 1) end end down (i: INTEGER) is -- Move cursor one level downward: -- to i-th child if there is one, -- or after if i = arity + 1, -- or before if i = 0. require -- from HIERARCHICAL not_off: not off argument_within_bounds: i >= 1 and i <= arity require else -- from CURSOR_TREE not_before: not before not_after: not after not_below: not below valid_cursor_index: (above and i = 0) or else valid_cursor_index (i) require else True local index, next, counter: INTEGER do index := first_child_table.item (active) if above then above := False below := is_empty before := is_empty after := False elseif index <= 0 then below := True; if i = 0 then before := True; after := False else after := True; before := False end else from next := next_sibling_table.item (index) until counter = i or next <= 0 loop index := next next := next_sibling_table.item (index) counter := counter + 1 end active := index if i = 0 then before := True after := False elseif counter < i then after := True; before := False end end ensure then -- from CURSOR_TREE gone_before: (i = 0) implies before end forth is -- Move cursor one position forward. do if below then check before end before := False after := True elseif before then before := False elseif islast then after := True else active := next_sibling_table.item (active) end end go_last_child is -- Go to the last child of current parent. -- No effect if below -- (from CURSOR_TREE) require -- from LINEAR True require else -- from CURSOR_TREE not_above: not above do up down (arity) end go_to (p: CURSOR) is -- Move cursor to position p. require -- from CURSOR_STRUCTURE cursor_position_valid: valid_cursor (p) local temp: COMPACT_TREE_CURSOR do temp ?= p check temp /= void end active := temp.active after := temp.after before := temp.before below := temp.below above := temp.above end level_back is -- Move cursor to previous position of current level. -- (from CURSOR_TREE) do if not isfirst then back elseif not above then from up level_back until above or else not is_leaf loop level_back end; if not above then down (arity) end end end level_forth is -- Move cursor to next position of current level. -- (from CURSOR_TREE) do if not above and then not islast then forth elseif not above then from up level_forth until above or else not is_leaf loop level_forth end; if not above then down (1) end end end postorder_forth is -- Move cursor to next position in postorder. -- If the active node is the last in -- postorder, the cursor ends up off. -- (from CURSOR_TREE) require -- from CURSOR_TREE not_off: not off do if islast then up else forth from until is_leaf loop down (1) end end end postorder_start is -- Move cursor to first position in postorder. -- Leave cursor off if tree is empty. -- (from CURSOR_TREE) do from go_above until arity = 0 loop down (1) end end preorder_forth is -- Move cursor to next position in preorder. -- If the active node is the last in -- preorder, the cursor ends up off. -- (from CURSOR_TREE) require -- from LINEAR not_after: not after do if is_leaf then from until not islast loop up end if not above then forth end else down (1) end end start is -- Move cursor to root. -- Leave cursor off if is_empty. -- (from CURSOR_TREE) do go_above if not is_empty then down (1) end ensure then -- from CURSOR_TREE on_root_unless_empty: not is_empty implies is_root end start_on_level (l: INTEGER) is -- Move the cursor to the first position -- of the l-th level counting from root. -- (from CURSOR_TREE) require -- from CURSOR_TREE argument_within_bounds: l >= 1 and then depth >= l do go_above start_on_level_from_active (l + 1) ensure -- from CURSOR_TREE level_expected: level = l is_first: isfirst end up is -- Move cursor one level upward, to parent -- or above if is_root holds. require -- from HIERARCHICAL not_off: not off require else -- from CURSOR_TREE not_above: not above local index: INTEGER do if below then below := False else from index := next_sibling_table.item (active) until index <= 0 loop index := next_sibling_table.item (index) end if index = 0 then above := True else active := - index end end after := False before := False ensure then -- from CURSOR_TREE not_before: not before not_after: not after not_below: not below coherency: (not old off and above) = (old is_root) end feature -- Element change extend (v: G) is require -- from COLLECTION extendible: extendible local new, index, next: INTEGER do new := new_cell_index item_table.put (v, new) if below then first_child_table.put (0, new) next_sibling_table.put (- active, new) if first_child_table.item (active) = 0 then first_child_table.put (new, active) end active := new else from index := active next := next_sibling_table.item (index) until next <= 0 loop index := next next := next_sibling_table.item (index) end check next < 0 end next_sibling_table.put (next, new) next_sibling_table.put (new, index) end ensure -- from COLLECTION item_inserted: is_inserted (v) ensure then -- from BAG one_more_occurrence: occurrences (v) = old (occurrences (v)) + 1 end container_fill (other: CONTAINER [G]) is -- Fill with as many items of other as possible. -- The representations of other and current structure -- need not be the same. -- (from COLLECTION) require -- from COLLECTION other_not_void: other /= void extendible local lin_rep: LINEAR [G] do lin_rep := other.linear_representation from lin_rep.start until not extendible or else lin_rep.off loop extend (lin_rep.item) lin_rep.forth end end fill (other: CURSOR_TREE [G]) is -- Fill with as many items of other -- as possible. -- The representations of other and current structure -- need not be the same. -- (from CURSOR_TREE) require -- from CURSOR_TREE is_empty: is_empty do go_above if not other.is_empty then other.start down (0) put_right (other.item) forth fill_from_active (other) end end fill_from_active (other: CURSOR_TREE [G]) is -- Copy subtree of other's active node -- onto active node of current tree. -- (from CURSOR_TREE) require -- from CURSOR_TREE cursor_on_leaf: is_leaf do if not other.is_leaf then from other.down (1) down (0) until other.after loop put_right (other.item) forth fill_from_active (other) other.forth end other.up up end end merge_left (other: CURSOR_TREE [G]) is -- Merge the items of other into current structure to -- the left of cursor position. -- (from CURSOR_TREE) require -- from CURSOR_TREE other_exists: other /= void not_before: not before not_above: not above only_one_root: (level = 1) implies is_empty do back merge_right (other) end merge_right (other: CURSOR_TREE [G]) is -- Merge the items of other into current structure to -- the right of cursor position. -- (from CURSOR_TREE) require -- from CURSOR_TREE other_exists: other /= void not_after: not after not_above: not above only_one_root: (level = 1) implies is_empty local pos: CURSOR do if not other.is_empty then pos := other.cursor other.start put_right (other.item) forth if not other.is_leaf then down (0) other.down (0) from until other.islast loop other.forth merge_right (other.subtree) end up end other.go_to (pos) end end put (v: G) is -- Put v at cursor position. -- (Synonym for replace) -- (from CURSOR_TREE) require -- from COLLECTION extendible: extendible do replace (v) ensure -- from COLLECTION item_inserted: is_inserted (v) end put_front (v: G) is -- Add a leaf v as first child. -- If above and is_empty, make v the root value local old_active: like active new: INTEGER do new := new_cell_index if below then item_table.put (v, new) first_child_table.put (0, new) next_sibling_table.put (- active, new) active := new elseif before then item_table.put (item_table.item (active), new); next_sibling_table.put (next_sibling_table.item (active), new); first_child_table.put (first_child_table.item (active), new); item_table.put (v, active); next_sibling_table.put (new, active); first_child_table.put (0, active); active := new else old_active := active up item_table.put (v, new) next_sibling_table.put (first_child_table.item (active), new) first_child_table.put (new, active) active := old_active end end put_left (v: G) is -- Add v to the left of current position. require -- from CURSOR_TREE not_before: not before not_above: not above only_one_root: (level = 1) implies is_empty require else not_above: not above local new: INTEGER do new := new_cell_index if below then first_child_table.put (new, active) next_sibling_table.put (- active, new) item_table.put (v, new) else item_table.put (item_table.item (active), new) next_sibling_table.put (next_sibling_table.item (active), new) first_child_table.put (first_child_table.item (active), new) item_table.put (v, active) next_sibling_table.put (new, active) first_child_table.put (0, active) end active := new end put_parent (v: G) is -- insert a new node, with value v, as parent of -- current node and -- with the same position --if above or on root, add a new root require not after not before local new, old_index: INTEGER do new := new_cell_index old_index := active if is_empty then active := new item_table.put (v, new) next_sibling_table.put (0, new) first_child_table.put (0, new) else item_table.put (item, new) first_child_table.put (first_child_table.item (active), new) next_sibling_table.put (- active, new) item_table.put (v, active) end end put_right (v: G) is -- Add a leaf v to the right of cursor position. require -- from CURSOR_TREE not_after: not after not_above: not above only_one_root: (level = 1) implies is_empty local new: INTEGER do new := new_cell_index first_child_table.put (0, new) if below then first_child_table.put (new, active) next_sibling_table.put (- active, new) item_table.put (v, new) active := new elseif before then item_table.put (item_table.item (active), new); next_sibling_table.put (next_sibling_table.item (active), new); first_child_table.put (first_child_table.item (active), new); item_table.put (v, active); next_sibling_table.put (new, active); first_child_table.put (0, active); active := new else next_sibling_table.put (next_sibling_table.item (active), new) next_sibling_table.put (new, active) end end replace (v: G) is -- Replace current item by v require -- from ACTIVE writable: writable require else is_writable: writable do item_table.put (v, active) ensure -- from ACTIVE item_replaced: item = v end feature -- Removal remove is -- Remove node at cursor position -- (and consequently the corresponding subtree). -- Move cursor to next sibling, or after if none. require -- from ACTIVE prunable: prunable writable: writable local removed, index, next: INTEGER do removed := active up if first_child_table.item (active) = removed then index := next_sibling_table.item (removed) if index > 0 then first_child_table.put (index, active) active := index else first_child_table.put (0, active) below := True after := True end else from index := first_child_table.item (active) next := next_sibling_table.item (index) until next = removed loop index := next next := next_sibling_table.item (index) end next_sibling_table.put (next_sibling_table.item (removed), index) if next_sibling_table.item (removed) > 0 then active := next_sibling_table.item (removed) else active := index after := True end end remove_subtree (removed) ensure then not_before: not before end remove_node is -- Remove node at cursor position; insert children into -- parent's children at current position; move cursor up. -- If node is root, it must not have more than one child. require not_off: not off is_root implies arity <= 1 local old_active, next, index, first_child_index: INTEGER default_value: G do old_active := active first_child_index := first_child_table.item (old_active) up next := first_child_table.item (active) if next = old_active then first_child_table.put (next_sibling_table.item (old_active), active) else from until next = old_active loop index := next next := next_sibling_table.item (index) end next_sibling_table.put (first_child_index, index) from next := first_child_index until next <= 0 loop index := next next := next_sibling_table.item (index) end next_sibling_table.put (next_sibling_table.item (old_active), index) end if old_active = last then last := last - 1 else item_table.put (default_value, old_active) first_child_table.put (removed_mark, old_active) next_sibling_table.put (free_list_index, old_active) free_list_index := old_active free_list_count := free_list_count + 1 end end wipe_out is -- Remove all items. require -- from COLLECTION prunable do item_table.resize (1, block_threshold + 1) next_sibling_table.resize (1, block_threshold + 1) first_child_table.resize (1, block_threshold + 1) item_table.clear_all next_sibling_table.clear_all first_child_table.clear_all last := 1 active := 1 free_list_count := 0 free_list_index := 0 above := True after := False before := False below := False ensure -- from COLLECTION wiped_out: is_empty ensure then cursor_above: above end feature {NONE} -- Removal prune_all (v: G) is -- Remove all occurrences of v. -- (Reference or object equality, -- based on object_comparison.) -- (from COLLECTION) require -- from COLLECTION prunable do from until not has (v) loop prune (v) end ensure -- from COLLECTION no_more_occurrences: not has (v) end feature -- Conversion linear_representation: LINEAR [G] is -- Representation as a linear structure -- (from LINEAR) do Result := Current end feature -- Duplication child_tree (i: INTEGER): like Current is -- Subtree rooted at i-th child -- (from CURSOR_TREE) require -- from CURSOR_TREE argument_within_bounds: i >= 1 and then i <= arity not_off: not off local pos: CURSOR do pos := cursor down (i) Result := subtree go_to (pos) end parent_tree: like Current is -- Subtree rooted at parent -- (from CURSOR_TREE) require -- from CURSOR_TREE not_on_root: not is_root not_off: not off local pos: CURSOR do pos := cursor up Result := subtree go_to (pos) end subtree: like Current is -- Subtree rooted at current node -- (from CURSOR_TREE) require -- from CURSOR_TREE not_off: not off do Result := new_tree Result.go_above Result.down (0) Result.put_right (item) Result.forth Result.fill_from_active (Current) end feature {NONE} -- Inapplicable prune (v: G) is -- Remove item v. -- (from CURSOR_TREE) require -- from COLLECTION prunable: prunable do end feature {COMPACT_CURSOR_TREE} -- Implementation new_tree: like Current is -- A newly created instance of the same type. -- This feature may be redefined in descendants so as to -- produce an adequately allocated and initialized object. do create Result.make (block_threshold) ensure -- from CURSOR_TREE result_exists: Result /= void result_is_empty: Result.is_empty end feature {NONE} -- Implementation active: INTEGER -- Index of current item block_threshold: INTEGER is do Result := 10 end breadth_of_level_from_active (a_level: INTEGER): INTEGER is -- Breadth of level level of subtree starting at current node -- (from CURSOR_TREE) do if (a_level = 2) or else is_leaf then Result := arity else from down (1) until after loop Result := Result + breadth_of_level_from_active (a_level - 1) forth end up end end depth_from_active: INTEGER is -- Depth of subtree starting at active -- (from CURSOR_TREE) do if not off and then arity = 0 then Result := 1 else from down (1) until after loop Result := Result.max (depth_from_active + 1) forth end up end end first_child_table: ARRAY [INTEGER] -- Indices to the first child free_list_count: INTEGER -- Number of empty spaces in item_table free_list_index: INTEGER -- Index to first empty space in item_table item_table: ARRAY [G] -- Array containing the items last: INTEGER -- Index into item_table; yields last item new_cell_index: INTEGER is local default_value: like item do if free_list_index > 0 then Result := free_list_index free_list_index := next_sibling_table.item (Result) free_list_count := free_list_count - 1 else last := last + 1 item_table.force (default_value, last) next_sibling_table.force (0, last) first_child_table.force (0, last) Result := last end end next_sibling_table: ARRAY [INTEGER] -- Indices to siblings remove_subtree (i: INTEGER) is local index, next: INTEGER default_value: G do from index := first_child_table.item (i) until index <= 0 loop next := next_sibling_table.item (index) remove_subtree (index) index := next end if i = last then last := last - 1 else item_table.put (default_value, i) first_child_table.put (removed_mark, i) next_sibling_table.put (free_list_index, i) free_list_index := i free_list_count := free_list_count + 1 end end Removed_mark: INTEGER is -1 -- Mark for removed child in first_child_table start_on_level_from_active (l: INTEGER) is -- Move the cursor to the first position -- of the l-th level counting from active. -- (from CURSOR_TREE) require -- from CURSOR_TREE deep_enough: depth_from_active >= l do from down (1) until depth_from_active >= l - 1 loop forth end if (l > 2) then start_on_level_from_active (l - 1) end end feature {CURSOR_TREE} -- Implementation go_above is -- Move the cursor above the tree -- (from CURSOR_TREE) do from until above loop up end end feature -- Iteration do_all (action: PROCEDURE [ANY, TUPLE [G]]) is -- Apply action to every item. -- Semantics not guaranteed if action changes the structure; -- in such a case, apply iterator to clone of structure instead. -- (from TRAVERSABLE) require -- from TRAVERSABLE action_exists: action /= void do linear_representation.do_all (action) end linear_do_all (action: PROCEDURE [ANY, TUPLE [G]]) is -- Apply action to every item. -- Semantics not guaranteed if action changes the structure; -- in such a case, apply iterator to clone of structure instead. -- (from LINEAR) require -- from TRAVERSABLE action_exists: action /= void local t: TUPLE [G] do create t.make from start until after loop t.put (item, 1) action.call (t) preorder_forth end end do_if (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- Apply action to every item that satisfies test. -- Semantics not guaranteed if action or test changes the structure; -- in such a case, apply iterator to clone of structure instead. -- (from TRAVERSABLE) require -- from TRAVERSABLE action_exists: action /= void test_exits: test /= void do linear_representation.do_if (action, test) end linear_do_if (action: PROCEDURE [ANY, TUPLE [G]]; test: FUNCTION [ANY, TUPLE [G], BOOLEAN]) is -- Apply action to every item that satisfies test. -- Semantics not guaranteed if action or test changes the structure; -- in such a case, apply iterator to clone of structure instead. -- (from LINEAR) require -- from TRAVERSABLE action_exists: action /= void test_exits: test /= void local t: TUPLE [G] do create t.make from start until after loop t.put (item, 1) if test.item (t) then action.call (t) end preorder_forth end end linear_for_all (test: FUNCTION [ANY, TUPLE [G], BOOLEAN]): BOOLEAN is -- Is test true for all items? -- (from LINEAR) require -- from TRAVERSABLE test_exits: test /= void local cs: CURSOR_STRUCTURE [G] c: CURSOR t: TUPLE [G] do create t.make cs ?= Current if cs /= void then c := cs.cursor end from start Result := True until after or not Result loop t.put (item, 1) Result := test.item (t) preorder_forth end if cs /= void then cs.go_to (c) end end for_all (test: FUNCTION [ANY, TUPLE [G], BOOLEAN]): BOOLEAN is -- Is test true for all items? -- (from TRAVERSABLE) require -- from TRAVERSABLE test_exits: test /= void do Result := linear_representation.for_all (test) end there_exists (test: FUNCTION [ANY, TUPLE [G], BOOLEAN]): BOOLEAN is -- Is test true for at least one item? -- (from TRAVERSABLE) require -- from TRAVERSABLE test_exits: test /= void do Result := linear_representation.there_exists (test) end linear_there_exists (test: FUNCTION [ANY, TUPLE [G], BOOLEAN]): BOOLEAN is -- Is test true for at least one item? -- (from LINEAR) require -- from TRAVERSABLE test_exits: test /= void local cs: CURSOR_STRUCTURE [G] c: CURSOR t: TUPLE [G] do create t.make cs ?= Current if cs /= void then c := cs.cursor end from start until after or Result loop t.put (item, 1) Result := test.item (t) preorder_forth end if cs /= void then cs.go_to (c) end end feature {NONE} -- Not applicable linear_index: INTEGER is -- (from CURSOR_TREE) do end invariant -- from ANY reflexive_equality: standard_is_equal (Current) reflexive_conformance: conforms_to (Current) -- from CURSOR_TREE non_negative_depth: depth >= 0 non_negative_breadth: breadth >= 0 is_leaf_definition: not off implies is_leaf = (arity = 0) above_property: above implies (arity <= 1) on_tree: (isfirst or islast or is_leaf or is_root) implies not off off_definition: off = after or before or above or below below_constraint: below implies ((after or before) and not above) above_constraint: above implies not (before or after or below) after_constraint: after implies not (before or above) before_constaint: before implies not (after or above) empty_below_constraint: (is_empty and (after or before)) implies below -- from HIERARCHICAL non_negative_successor_count: arity >= 0 -- from TRAVERSABLE empty_constraint: is_empty implies off -- from ACTIVE writable_constraint: writable implies readable empty_constraint: is_empty implies (not readable) and (not writable) -- from LINEAR after_constraint: after implies off indexing library: "[ EiffelBase: Library of reusable components for Eiffel. ]" status: "[ Copyright 1986-2001 Interactive Software Engineering (ISE). For ISE customers the original versions are an ISE product covered by the ISE Eiffel license and support agreements. ]" license: "[ EiffelBase may now be used by anyone as FREE SOFTWARE to develop any product, public-domain or commercial, without payment to ISE, under the terms of the ISE Free Eiffel Library License (IFELL) at http://eiffel.com/products/base/license.html. ]" source: "[ Interactive Software Engineering Inc. ISE Building 360 Storke Road, Goleta, CA 93117 USA Telephone 805-685-1006, Fax 805-685-6869 Electronic mail <info@eiffel.com> Customer support http://support.eiffel.com ]" info: "[ For latest info see award-winning pages: http://eiffel.com ]" end -- class COMPACT_CURSOR_TREE
Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:

-- Generated by ISE Eiffel --
For more details: www.eiffel.com