Automatic generation produced by ISE Eiffel

Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:
indexing description: "Trees implemented using a two way linked list representation" status: "See notice at end of class" names: two_way_tree, tree, two_way_list representation: recursive, linked access: cursor, membership contents: generic date: "$Date: 2001-11-16 20:32:23 +0000 (Fri, 16 Nov 2001) $" revision: "$Revision: 51435 $" class TWO_WAY_TREE [G] create make feature -- Initialization make (v: like item) is -- Create single node with item v. do put (v) twl_make end feature {NONE} -- Initialization twl_make is -- Create an empty list. -- (from LINKED_LIST) do child_before := True ensure -- from LINKED_LIST is_before: child_before end feature -- Access child_cursor: CURSOR is -- Current cursor position -- (from LINKED_LIST) do create {LINKED_LIST_CURSOR [G]} Result.make (child, child_after, child_before) end first: like child_item is -- Item at first position -- (from LINKED_LIST) require -- from CHAIN not_empty: not is_leaf do Result := first_child.item end first_child: like parent -- Leftmost child i_th (i: INTEGER): like child_item is -- Item at i-th position -- Was declared in CHAIN as synonym of @. -- (from CHAIN) require -- from TABLE valid_key: valid_index (k) local pos: CURSOR do pos := child_cursor child_go_i_th (i) Result := child_item child_go_to (pos) end child_index: INTEGER is -- Index of current position -- (from LINKED_LIST) local p: LINKED_LIST_CURSOR [G] do if child_after then Result := arity + 1 elseif not child_before then p ?= child_cursor; check p /= void end; from child_start Result := 1 until p.active = child loop child_forth Result := Result + 1 end; child_go_to (p) end ensure -- from TREE valid_index: Result >= 0 and Result <= arity + 1 end index_of (v: like child_item; i: INTEGER): INTEGER is -- Index of i-th occurrence of item identical to v. -- (Reference or object equality, -- based on object_comparison.) -- 0 if none. -- (from CHAIN) require -- from LINEAR positive_occurrences: i > 0 local pos: CURSOR do pos := child_cursor Result := sequential_index_of (v, i) child_go_to (pos) ensure -- from LINEAR non_negative_result: Result >= 0 end child_item: G is -- Current item -- (from LINKED_LIST) require -- from TRAVERSABLE not_off: not child_off require -- from ACTIVE readable: child_readable require -- from TREE readable: child_readable do Result := child.item end item: G -- Content of cell. -- (from CELL) last: like child_item is -- Item at last position -- (from LINKED_LIST) require -- from CHAIN not_empty: not is_leaf do Result := last_child.item end last_child: like parent left_sibling: like Current -- Left neighbor -- (from BI_LINKABLE) sequential_occurrences (v: G): INTEGER is -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) do from child_start search_child (v) until exhausted loop Result := Result + 1 child_forth search_child (v) end ensure -- from BAG non_negative_occurrences: Result >= 0 end parent: TWO_WAY_TREE [G] -- Parent node right_sibling: like Current -- Right neighbor -- (from LINKABLE) sublist: like Current -- Result produced by last split -- (from TWO_WAY_LIST) infix "@" (i: INTEGER): like child_item is -- Item at i-th position -- Was declared in CHAIN as synonym of i_th. -- (from CHAIN) require -- from TABLE valid_key: valid_index (k) local pos: CURSOR do pos := child_cursor child_go_i_th (i) Result := child_item child_go_to (pos) end feature {NONE} -- Access twl_has (v: like child_item): BOOLEAN is -- Does chain include v? -- (Reference or object equality, -- based on object_comparison.) -- (from CHAIN) local pos: CURSOR do pos := child_cursor Result := sequential_has (v) child_go_to (pos) ensure -- from CONTAINER not_found_in_empty: Result implies not is_leaf end sequential_has (v: like child_item): BOOLEAN is -- Does structure include an occurrence of v? -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) do child_start if not child_off then search_child (v) end Result := not exhausted ensure -- from CONTAINER not_found_in_empty: Result implies not is_leaf end sequential_index_of (v: like child_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 child_start pos := 1 until child_off or (occur = i) loop if child_item /= void and then v.is_equal (child_item) then occur := occur + 1 end child_forth pos := pos + 1 end else from child_start pos := 1 until child_off or (occur = i) loop if child_item = v then occur := occur + 1 end child_forth pos := pos + 1 end end if occur = i then Result := pos - 1 end ensure -- from LINEAR non_negative_result: Result >= 0 end sequential_search (v: like child_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 (child_item /= void and then v.is_equal (child_item)) loop child_forth end else from until exhausted or else v = child_item loop child_forth end end ensure -- from LINEAR object_found: (not exhausted and object_comparison) implies equal (v, child_item) item_found: (not exhausted and not object_comparison) implies v = child_item end feature -- Measurement child_capacity: INTEGER is -- Maximal number of children -- (from TREE) do Result := arity end count: INTEGER is -- Number of items -- (from TREE) do Result := subtree_count + 1 end arity: INTEGER -- Number of items -- (from LINKED_LIST) index_set: INTEGER_INTERVAL is -- Range of acceptable indexes -- (from CHAIN) do create Result.make (1, arity) ensure -- from INDEXABLE not_void: Result /= void ensure then -- from CHAIN count_definition: Result.count = arity end occurrences (v: like child_item): INTEGER is -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from CHAIN) local pos: CURSOR do pos := child_cursor Result := sequential_occurrences (v) child_go_to (pos) ensure -- from BAG non_negative_occurrences: Result >= 0 end occurrences (v: like child_item): INTEGER is -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from CHAIN) local pos: CURSOR do pos := child_cursor Result := sequential_occurrences (v) child_go_to (pos) ensure -- from BAG non_negative_occurrences: Result >= 0 end feature -- Comparison is_equal (other: like Current): BOOLEAN is -- Does other contain the same elements? -- (Reference or object equality, -- based on object_comparison.) -- (from TREE) require -- from ANY other_not_void: other /= void do if Current = other then Result := True else Result := (is_leaf = other.is_leaf) and (object_comparison = other.object_comparison) and (child_capacity = other.child_capacity) if Result and not is_leaf then Result := tree_is_equal (Current, other) end end ensure -- from ANY symmetric: Result implies other.is_equal (Current) consistent: standard_is_equal (other) implies Result ensure then -- from LIST indices_unchanged: child_index = old child_index and other.child_index = old other.child_index true_implies_same_size: Result implies arity = other.arity end feature -- Status report child_after: BOOLEAN -- Is there no valid cursor position to the right of cursor? -- (from LINKED_LIST) child_before: BOOLEAN -- Is there no valid cursor position to the left of cursor? -- (from LINKED_LIST) changeable_comparison_criterion: BOOLEAN is -- May object_comparison be changed? -- (Answer: yes by default.) -- (from CONTAINER) do Result := True end child_isfirst: BOOLEAN is -- Is cursor under first child? -- (from TREE) do Result := not is_leaf and child_index = 1 ensure -- from CHAIN valid_position: Result implies not is_leaf ensure -- from TREE not_is_leaf: Result implies not is_leaf end child_islast: BOOLEAN is -- Is cursor under last child? -- (from TREE) do Result := not is_leaf and child_index = child_capacity ensure -- from CHAIN valid_position: Result implies not is_leaf ensure -- from TREE not_is_leaf: Result implies not is_leaf end child_readable: BOOLEAN is -- Is there a current child_item to be read? -- (from TREE) do Result := not child_off and then (child /= void) end child_writable: BOOLEAN is -- Is there a current child_item that may be modified? -- (from TREE) do Result := not child_off and then (child /= void) end empty: BOOLEAN is obsolete "ELKS 2000: Use `is_empty' instead" -- Is there no element? -- (from CONTAINER) do Result := is_leaf end exhausted: BOOLEAN is -- Has structure been completely explored? -- (from LINEAR) do Result := child_off ensure -- from LINEAR exhausted_when_off: child_off implies Result end Extendible: BOOLEAN is True -- May new items be added? -- (from DYNAMIC_TREE) Child_extendible: BOOLEAN is True -- May new items be added? (Answer: yes.) -- (from DYNAMIC_CHAIN) has (v: G): BOOLEAN is -- Does subtree include v? -- (Reference or object equality, -- based on object_comparison.) -- (from TREE) do if object_comparison then Result := (v /= void) and then (item /= void) and then (v.is_equal (item) or else subtree_has (v)) else Result := v = item or else subtree_has (v) end ensure -- from CONTAINER not_found_in_empty: Result implies not is_leaf end is_empty: BOOLEAN is -- Is structure empty of items? -- (from TREE) do Result := False end is_inserted (v: G): BOOLEAN is -- Has v been inserted at the end by the most recent put or -- extend? -- (from LINKED_LIST) do check put_constraint: (v /= last_child.item) implies not child_off end Result := (v = last_child.item) or else (v = child_item) end is_leaf: BOOLEAN is -- Are there no children? -- (from TREE) do Result := arity = 0 end is_root: BOOLEAN is -- Is there no parent? -- (from TREE) do Result := parent = void end is_sibling (other: like parent): BOOLEAN is -- Are current node and other siblings? -- (from TREE) require -- from TREE other_exists: other /= void do Result := not is_root and other.parent = parent ensure -- from TREE not_root: Result implies not is_root other_not_root: Result implies not other.is_root same_parent: Result = not is_root and other.parent = parent end object_comparison: BOOLEAN -- Must search operations use equal rather than = -- for comparing references? (Default: no, use =.) -- (from CONTAINER) child_off: BOOLEAN is -- Is there no current item? -- (from LINKED_LIST) do Result := child_after or child_before end prunable: BOOLEAN is -- May items be removed? (Answer: yes.) -- (from DYNAMIC_CHAIN) do Result := True end Readable: BOOLEAN is True -- (from TREE) readable_child: BOOLEAN is -- Is there a current child to be read? -- (from TREE) do Result := not child_off end valid_cursor (p: CURSOR): BOOLEAN is -- Can the cursor be moved to position p? -- (from LINKED_LIST) local ll_c: LINKED_LIST_CURSOR [G] temp, sought: like first_child do ll_c ?= p if ll_c /= void then from temp := first_child sought := ll_c.active Result := ll_c.after or else ll_c.before until Result or else temp = void loop Result := (temp = sought) temp := temp.right_sibling end end end valid_cursor_index (i: INTEGER): BOOLEAN is -- Is i correctly bounded for cursor movement? -- (from TREE) do Result := (i >= 0) and (i <= child_capacity + 1) ensure -- from CHAIN valid_cursor_index_definition: Result = ((i >= 0) and (i <= arity + 1)) ensure -- from TREE valid_cursor_index_definition: Result = (i >= 0) and (i <= child_capacity + 1) end valid_index (i: INTEGER): BOOLEAN is -- Is i within allowable bounds? -- (from CHAIN) do Result := (i >= 1) and (i <= arity) ensure then -- from INDEXABLE only_if_in_index_set: Result implies ((i >= index_set.lower) and (i <= index_set.upper)) ensure then -- from CHAIN valid_index_definition: Result = ((i >= 1) and (i <= arity)) end Writable: BOOLEAN is True -- Is there a current item that may be modified? -- (from TREE) writable_child: BOOLEAN is -- Is there a current child that may be modified? -- (from TREE) do Result := not child_off end feature {NONE} -- Status report Twl_full: BOOLEAN is False -- Is structured filled to capacity? (Answer: no.) -- (from LINKED_LIST) 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 child_back is -- Move cursor to previous position, if any. -- (from TWO_WAY_LIST) require -- from TREE True require -- from BILINEAR not_before: not child_before do if child_after then child_after := False if is_leaf then child_before := True end else child := child.left_sibling if child = void then child := first_child child_before := True end end end child_finish is -- Move cursor to last position. -- (Go before if empty) -- (from TWO_WAY_LIST) do if not is_leaf then child := last_child child_after := False child_before := False else child_after := False child_before := True end ensure then -- from CHAIN at_last: not is_leaf implies child_islast ensure then -- from LINKED_LIST empty_convention: is_leaf implies child_before ensure then -- from TREE is_last_child: not is_leaf implies child_islast ensure then -- from TWO_WAY_LIST not_after: not child_after end child_forth is -- Move cursor to next position, if any. -- (from TWO_WAY_LIST) require -- from TREE True require -- from LINEAR not_after: not child_after do if child_before then child_before := False if is_leaf then child_after := True end else child := child.right_sibling if child = void then child := last_child child_after := True end end ensure then -- from LIST moved_forth: child_index = old child_index + 1 end child_go_i_th (i: INTEGER) is -- Move cursor to i-th position. -- (from LINKED_LIST) require -- from CHAIN valid_cursor_index: valid_cursor_index (i) require else -- from TREE valid_cursor_index: valid_cursor_index (i) do if i = 0 then child_before := True child_after := False child := first_child elseif i = arity + 1 then child_before := False; child_after := True; child := last_child else move (i - child_index) end ensure -- from CHAIN position_expected: child_index = i ensure then -- from TREE position: child_index = i end child_go_to (p: CURSOR) is -- Move cursor to position p. -- (from LINKED_LIST) require -- from TREE True require -- from CURSOR_STRUCTURE cursor_position_valid: valid_cursor (p) local ll_c: LINKED_LIST_CURSOR [G] do ll_c ?= p check ll_c /= void end child_after := ll_c.after child_before := ll_c.before if child_before then child := first_child elseif child_after then child := last_child else child := ll_c.active end end move (i: INTEGER) is -- Move cursor i positions. The cursor -- may end up off if the offset is to big. -- (from TWO_WAY_LIST) local counter: INTEGER p: like first_child do if i > 0 then ll_move (i) elseif i < 0 then if child_after then child_after := False; counter := - 1 end; from p := child until (counter = i) or else (p = void) loop p := p.left_sibling counter := counter - 1 end; if p = void then child_before := True; child := first_child else child := p end end ensure -- from CHAIN too_far_right: (old child_index + i > arity) implies exhausted too_far_left: (old child_index + i < 1) implies exhausted expected_index: (not exhausted) implies (child_index = old child_index + i) ensure then -- from LINKED_LIST moved_if_inbounds: ((old child_index + i) >= 0 and (old child_index + i) <= (arity + 1)) implies child_index = (old child_index + i) before_set: (old child_index + i) <= 0 implies child_before after_set: (old child_index + i) >= (arity + 1) implies child_after end search_child (v: like child_item) is -- Move to first position (at or after current -- position) where item and v are equal. -- If structure does not include v ensure that -- exhausted will be true. -- (Reference or object equality, -- based on object_comparison.) -- (from BILINEAR) do if child_before and not is_leaf then child_forth end sequential_search (v) ensure -- from LINEAR object_found: (not exhausted and object_comparison) implies equal (v, child_item) item_found: (not exhausted and not object_comparison) implies v = child_item end child_start is -- Move cursor to first position. -- (from LINKED_LIST) do if first_child /= void then child := first_child child_after := False else child_after := True end child_before := False ensure then -- from CHAIN at_first: not is_leaf implies child_isfirst ensure then -- from TREE is_first_child: not is_leaf implies child_isfirst ensure then -- from LINKED_LIST empty_convention: is_leaf implies child_after end feature {NONE} -- Cursor movement ll_move (i: INTEGER) is -- Move cursor i positions. The cursor -- may end up off if the offset is too big. -- (from LINKED_LIST) local counter, new_index: INTEGER p: like first_child do if i > 0 then if child_before then child_before := False counter := 1 end from p := child until (counter = i) or else (p = void) loop child := p p := p.right_sibling counter := counter + 1 end if p = void then child_after := True else child := p end elseif i < 0 then new_index := child_index + i; child_before := True; child_after := False; child := first_child; if (new_index > 0) then move (new_index) end end ensure -- from CHAIN too_far_right: (old child_index + i > arity) implies exhausted too_far_left: (old child_index + i < 1) implies exhausted expected_index: (not exhausted) implies (child_index = old child_index + i) ensure then -- from LINKED_LIST moved_if_inbounds: ((old child_index + i) >= 0 and (old child_index + i) <= (arity + 1)) implies child_index = (old child_index + i) before_set: (old child_index + i) <= 0 implies child_before after_set: (old child_index + i) >= (arity + 1) implies child_after end feature {RECURSIVE_CURSOR_TREE} -- Element change set_child (n: like parent) is -- Set the child of parent to n. require -- from DYNAMIC_TREE non_void_argument: n /= void do child := n ensure then child_set: child = n end feature -- Element change append (s: SEQUENCE [G]) is -- Append a copy of s. -- (from SEQUENCE) require -- from SEQUENCE argument_not_void: s /= void local l: like s do if s = Current then l := deep_clone (s) else l := s end from l.start until l.exhausted loop child_extend (l.item) l.forth end ensure -- from SEQUENCE new_count: arity >= old arity end extend (v: like item) is -- Add v as new child. -- (from DYNAMIC_TREE) do child_extend (v) end child_extend (v: like child_item) is -- Add v to end. -- Do not move cursor. -- (from TWO_WAY_LIST) require -- from DYNAMIC_TREE True require -- from COLLECTION extendible: child_extendible local p: like first_child do p := new_cell (v) if is_leaf then first_child := p child := p else p.bl_put_left (last_child) end last_child := p if child_after then child := p end arity := arity + 1 ensure -- from COLLECTION item_inserted: is_inserted (v) ensure then -- from BAG one_more_occurrence: occurrences (v) = old (occurrences (v)) + 1 end fill (other: TREE [G]) is -- Fill with as many items of other as possible. -- The representations of other and current node -- need not be the same. -- (from TREE) do replace (other.item) fill_subtree (other) end force (v: like child_item) is -- Add v to end. -- (from SEQUENCE) require -- from SEQUENCE extendible: child_extendible do child_extend (v) ensure then -- from SEQUENCE new_count: arity = old arity + 1 item_inserted: has (v) end twl_merge_left (other: like Current) is -- Merge other into current structure before cursor -- position. Do not move cursor. Empty other. -- (from TWO_WAY_LIST) require -- from DYNAMIC_CHAIN extendible: child_extendible not_before: not child_before other_exists: other /= void local other_first_element: like first_child other_last_element: like first_child other_count: INTEGER do if not other.is_leaf then other_first_element := other.first_child other_last_element := other.last_child other_count := other.arity check other_first_element /= void other_last_element /= void end if is_leaf then last_child := other_last_element first_child := other_first_element if child_before then child := first_child else child := last_child end elseif child_isfirst then other_last_element.bl_put_right (first_child); first_child := other_first_element elseif child_after then other_first_element.bl_put_left (last_child); last_child := other_last_element; child := last_child else other_first_element.bl_put_left (child.left_sibling) child.bl_put_left (other_last_element) end arity := arity + other_count other.wipe_out end ensure -- from DYNAMIC_CHAIN new_count: arity = old arity + old other.arity new_index: child_index = old child_index + old other.arity other_is_empty: other.is_leaf ensure then -- from DYNAMIC_LIST other_empty: other.is_leaf end twl_merge_right (other: like Current) is -- Merge other into current structure after cursor -- position. Do not move cursor. Empty other. -- (from TWO_WAY_LIST) require -- from DYNAMIC_CHAIN extendible: child_extendible not_after: not child_after other_exists: other /= void do if is_leaf or else child_islast then last_child := other.last_child end ll_merge_right (other) ensure -- from DYNAMIC_CHAIN new_count: arity = old arity + old other.arity same_index: child_index = old child_index other_is_empty: other.is_leaf ensure then -- from DYNAMIC_LIST other_empty: other.is_leaf end merge_tree_after (other: like first_child) is -- Merge children of other into current structure -- after cursor position. Do not move cursor. -- Make other a leaf. require -- from DYNAMIC_TREE not_child_off: not child_off other_exists: (other /= void) do attach (other) twl_merge_right (other) ensure -- from DYNAMIC_TREE other_is_leaf: other.is_leaf end merge_tree_before (other: like first_child) is -- Merge children of other into current structure -- after cursor position. Do not move cursor. -- Make other a leaf. require -- from DYNAMIC_TREE not_child_off: not child_off other_exists: (other /= void) do attach (other) twl_merge_left (other) ensure -- from DYNAMIC_TREE other_is_leaf: other.is_leaf end prune (n: like first_child) is require -- from TREE is_child: n.parent = Current local l_child: like first_child do from l_child := first_child until l_child = void or l_child = n loop l_child := l_child.right_sibling end if l_child /= void then if l_child = first_child then first_child := first_child.right_sibling if child = n then child := first_child end if l_child = last_child then last_child := last_child.left_sibling end elseif l_child = last_child then last_child := last_child.left_sibling; if child = n then child := last_child end else l_child.right_sibling.bl_put_left (l_child.left_sibling) if child = n then child := l_child.left_sibling end end arity := arity - 1 if is_leaf and not child_before then first_child := void last_child := void child_after := True end n.attach_to_parent (void) n.simple_forget_left n.simple_forget_right end ensure -- from TREE n_is_root: n.is_root end put (v: like item) is -- Make v the cell's item. -- Was declared in CELL as synonym of replace. -- (from CELL) require -- from TREE is_writable: writable do item := v ensure -- from TREE item_inserted: item = v ensure -- from CELL item_inserted: item = v end child_put (v: like child_item) is -- Replace current item by v. -- (Synonym for replace) -- (from CHAIN) require -- from COLLECTION extendible: child_extendible require -- from TREE child_writable: child_writable do child_replace (v) ensure -- from COLLECTION item_inserted: is_inserted (v) ensure -- from TREE item_inserted: child_item = v ensure then -- from CHAIN same_count: arity = old arity end put_child (n: like parent) is -- Add n to the list of children. -- Do not move child cursor. require else -- from DYNAMIC_TREE non_void_argument: n /= void do if object_comparison then n.compare_objects else n.compare_references end if is_leaf then first_child := n child := n else last_child.bl_put_right (n) if child_after then child := n end end last_child := n n.attach_to_parent (Current) arity := arity + 1 end put_child_left (n: like parent) is -- Add n to the left of cursor position. -- Do not move cursor. require -- from DYNAMIC_TREE not_child_before: not child_before non_void_argument: n /= void do child_back put_child_right (n) child_forth child_forth end put_child_right (n: like parent) is -- Add n to the right of cursor position. -- Do not move cursor. require -- from DYNAMIC_TREE not_child_after: not child_after non_void_argument: n /= void do if object_comparison then n.compare_objects else n.compare_references end if child_before then if is_leaf then last_child := n end n.bl_put_right (first_child) first_child := n child := n elseif child_islast then child.bl_put_right (n); last_child := n else n.bl_put_right (child.right_sibling) n.bl_put_left (child) end n.attach_to_parent (Current) arity := arity + 1 end put_front (v: like child_item) is -- Add v to beginning. -- Do not move cursor. -- (from TWO_WAY_LIST) do ll_put_front (v) if arity = 1 then last_child := first_child end ensure -- from DYNAMIC_CHAIN new_count: arity = old arity + 1 item_inserted: first = v end put_i_th (v: like child_item; i: INTEGER) is -- Put v at i-th position. -- (from CHAIN) require -- from TABLE valid_key: valid_index (k) local pos: CURSOR do pos := child_cursor child_go_i_th (i) child_replace (v) child_go_to (pos) ensure then -- from INDEXABLE insertion_done: i_th (k) = v end child_put_left (v: like child_item) is -- Add v to the left of cursor position. -- Do not move cursor. -- (from TWO_WAY_LIST) require -- from DYNAMIC_CHAIN extendible: child_extendible not_before: not child_before require -- from DYNAMIC_TREE not_child_before: not child_before local p: like first_child do p := new_cell (v) if is_leaf then first_child := p last_child := p child := p child_before := False elseif child_after then p.bl_put_left (last_child); last_child := p; child := p elseif child_isfirst then p.bl_put_right (child); first_child := p else p.bl_put_left (child.left_sibling) p.bl_put_right (child) end arity := arity + 1 ensure -- from DYNAMIC_CHAIN new_count: arity = old arity + 1 new_index: child_index = old child_index + 1 ensure then -- from LINKED_LIST previous_exists: previous /= void item_inserted: previous.item = v end child_put_right (v: like child_item) is -- Add v to the right of cursor position. -- Do not move cursor. -- (from TWO_WAY_LIST) require -- from DYNAMIC_CHAIN extendible: child_extendible not_after: not child_after require -- from DYNAMIC_TREE not_child_after: not child_after local was_last: BOOLEAN do was_last := child_islast ll_put_right (v) if arity = 1 then last_child := child elseif was_last then last_child := child.right_sibling end ensure -- from DYNAMIC_CHAIN new_count: arity = old arity + 1 same_index: child_index = old child_index ensure then -- from LINKED_LIST next_exists: next /= void item_inserted: not old child_before implies next.item = v item_inserted_before: old child_before implies child.item = v end replace (v: like item) is -- Make v the cell's item. -- Was declared in CELL as synonym of put. -- (from CELL) require -- from TREE is_writable: writable do item := v ensure -- from TREE item_inserted: item = v ensure -- from CELL item_inserted: item = v end child_replace (v: like child_item) is -- Replace current item by v. -- (from LINKED_LIST) require -- from ACTIVE writable: child_writable require -- from TREE child_writable: child_writable do child.put (v) ensure -- from ACTIVE item_replaced: child_item = v ensure -- from TREE item_inserted: child_item = v end replace_child (n: like parent) is -- Replace current child by n. require -- from TREE writable_child: writable_child was_root: n.is_root do put_child_right (n) remove_child ensure -- from TREE child_replaced: child = n end sprout is -- Make current node a root. -- (from TREE) do if parent /= void then parent.prune (Current) end end feature {NONE} -- Element change twl_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 child_extendible local lin_rep: LINEAR [G] do lin_rep := other.linear_representation from lin_rep.start until not child_extendible or else lin_rep.off loop child_extend (lin_rep.item) lin_rep.forth end end ll_merge_right (other: like Current) is -- Merge other into current structure after cursor -- position. Do not move cursor. Empty other. -- (from LINKED_LIST) require -- from DYNAMIC_CHAIN extendible: child_extendible not_after: not child_after other_exists: other /= void local other_first_element: like first_child other_last_element: like first_child other_count: INTEGER do if not other.is_leaf then other_first_element := other.first_child other_last_element := other.last_child other_count := other.arity check other_first_element /= void other_last_element /= void end if is_leaf then first_child := other_first_element child := first_child else if not child_islast then other_last_element.bl_put_right (child.right_sibling) end child.bl_put_right (other_first_element) end arity := arity + other_count other.wipe_out end ensure -- from DYNAMIC_CHAIN new_count: arity = old arity + old other.arity same_index: child_index = old child_index other_is_empty: other.is_leaf ensure then -- from DYNAMIC_LIST other_empty: other.is_leaf end sequence_put (v: like child_item) is -- Add v to end. -- (from SEQUENCE) require -- from COLLECTION extendible: child_extendible do child_extend (v) ensure -- from COLLECTION item_inserted: is_inserted (v) ensure then -- from SEQUENCE new_count: arity = old arity + 1 end ll_put_front (v: like child_item) is -- Add v to beginning. -- Do not move cursor. -- (from LINKED_LIST) local p: like first_child do p := new_cell (v) p.bl_put_right (first_child) first_child := p if child_before or is_leaf then child := p end arity := arity + 1 ensure -- from DYNAMIC_CHAIN new_count: arity = old arity + 1 item_inserted: first = v end ll_put_right (v: like child_item) is -- Add v to the right of cursor position. -- Do not move cursor. -- (from LINKED_LIST) require -- from DYNAMIC_CHAIN extendible: child_extendible not_after: not child_after local p: like first_child do p := new_cell (v) check is_leaf implies child_before end if child_before then p.bl_put_right (first_child) first_child := p child := p else p.bl_put_right (child.right_sibling) child.bl_put_right (p) end arity := arity + 1 ensure -- from DYNAMIC_CHAIN new_count: arity = old arity + 1 same_index: child_index = old child_index ensure then -- from LINKED_LIST next_exists: next /= void item_inserted: not old child_before implies next.item = v item_inserted_before: old child_before implies child.item = v end feature -- Removal twl_prune (v: like child_item) is -- Remove first occurrence of v, if any, -- after cursor position. -- If found, move cursor to right neighbor; -- if not, make structure exhausted. -- (from DYNAMIC_CHAIN) require -- from COLLECTION prunable: prunable do search_child (v) if not exhausted then remove_child end end prune_all (v: like child_item) is -- Remove all occurrences of v. -- (Reference or object equality, -- based on object_comparison.) -- Leave structure exhausted. -- (from DYNAMIC_CHAIN) require -- from COLLECTION prunable do from child_start search_child (v) until exhausted loop remove_child search_child (v) end ensure -- from COLLECTION no_more_occurrences: not has (v) ensure then -- from DYNAMIC_CHAIN is_exhausted: exhausted end remove_child is -- Remove current item. -- Move cursor to right neighbor -- (or after if no right neighbor). -- (from TWO_WAY_LIST) require -- from ACTIVE prunable: prunable writable: child_writable require -- from DYNAMIC_TREE child_not_off: not child_off local succ, pred, removed: like first_child do removed := child if child_isfirst then child := first_child.right_sibling first_child.forget_right first_child := child if arity = 1 then check no_active: child = void end child_after := True last_child := void end elseif child_islast then child := last_child.left_sibling; last_child.forget_left; last_child := child; child_after := True else pred := child.left_sibling succ := child.right_sibling pred.forget_right succ.forget_left pred.bl_put_right (succ) child := succ end arity := arity - 1 cleanup_after_remove (removed) ensure then -- from DYNAMIC_LIST after_when_empty: is_leaf implies child_after ensure -- from DYNAMIC_TREE new_arity: arity = old arity - 1 new_child_index: child_index = old child_index end remove_left_child is -- Remove item to the left of cursor position. -- Do not move cursor. -- (from TWO_WAY_LIST) require -- from DYNAMIC_CHAIN left_exists: child_index > 1 require else -- from DYNAMIC_LIST not_before: not child_before require -- from DYNAMIC_TREE is_not_first: not child_isfirst do child_back remove_child ensure -- from DYNAMIC_CHAIN new_count: arity = old arity - 1 new_index: child_index = old child_index - 1 ensure -- from DYNAMIC_TREE new_arity: arity = old arity - 1 new_child_index: child_index = old child_index - 1 end remove_right_child is -- Remove item to the right of cursor position. -- Do not move cursor. -- (from TWO_WAY_LIST) require -- from DYNAMIC_CHAIN right_exists: child_index < arity require -- from DYNAMIC_TREE is_not_last: not child_islast do child_forth remove_child child_back ensure -- from DYNAMIC_CHAIN new_count: arity = old arity - 1 same_index: child_index = old child_index ensure -- from DYNAMIC_TREE new_arity: arity = old arity - 1 new_child_index: child_index = old child_index end remove_sublist is -- (from TWO_WAY_LIST) do sublist := void end split (n: INTEGER) is -- Remove from current list -- min (n, count - index - 1) items -- starting at cursor position. -- Move cursor right one position. -- Make extracted sublist accessible -- through attribute sublist. -- (from TWO_WAY_LIST) require -- from TWO_WAY_LIST not_off: not child_off valid_sublist: n >= 0 local actual_number, active_index: INTEGER p_elem, s_elem, e_elem, n_elem: like first_child do if n = 0 then create sublist.twl_make else active_index := child_index if active_index + n > arity + 1 then actual_number := arity + 1 - active_index else actual_number := n end s_elem := child p_elem := previous move (actual_number - 1) e_elem := child n_elem := next s_elem.forget_left e_elem.forget_right create sublist.make_sublist (s_elem, e_elem, actual_number) arity := arity - actual_number if p_elem /= void then p_elem.bl_put_right (n_elem) else first_child := n_elem end if n_elem /= void then child := n_elem else last_child := p_elem child := p_elem child_after := True end end end wipe_out is -- Remove all items. -- (from TWO_WAY_LIST) require -- from DYNAMIC_TREE True require -- from COLLECTION prunable do ll_wipe_out last_child := void ensure -- from COLLECTION wiped_out: is_leaf ensure then -- from DYNAMIC_LIST is_before: child_before end feature {NONE} -- Removal ll_wipe_out is -- Remove all items. -- (from LINKED_LIST) require -- from COLLECTION prunable do child := void first_child := void child_before := True child_after := False arity := 0 ensure -- from COLLECTION wiped_out: is_leaf ensure then -- from DYNAMIC_LIST is_before: child_before end chain_wipe_out is -- Remove all items. -- (from DYNAMIC_CHAIN) require -- from COLLECTION prunable do from child_start until is_leaf loop remove_child end ensure -- from COLLECTION wiped_out: is_leaf end feature -- Transformation swap (i: INTEGER) is -- Exchange item at i-th position with item -- at cursor position. -- (from CHAIN) require -- from CHAIN not_off: not child_off valid_index: valid_index (i) local old_item, new_item: like child_item pos: CURSOR do pos := child_cursor old_item := child_item child_go_i_th (i) new_item := child_item child_replace (old_item) child_go_to (pos) child_replace (new_item) ensure -- from CHAIN swapped_to_item: child_item = old i_th (i) swapped_from_item: i_th (i) = old child_item end feature -- Conversion binary_representation: BINARY_TREE [G] is -- Convert to binary tree representation: -- first child becomes left child, -- right sibling becomes right child. -- (from TREE) local current_sibling: BINARY_TREE [G] do create Result.make (item) if not is_leaf then Result.put_left_child (first_child.binary_representation) from child_start child_forth current_sibling := Result.left_child until child_after loop current_sibling.put_right_child (child.binary_representation) current_sibling := current_sibling.right_child child_forth end end ensure -- from TREE result_is_root: Result.is_root result_has_no_right_child: not Result.has_right end fill_from_binary (b: BINARY_TREE [G]) is -- Fill from a binary tree representation. -- Left child becomes first child. -- Right child becomes right sibling. -- Any right child of b is ignored. -- (from DYNAMIC_TREE) local current_node: BINARY_TREE [G] do replace (b.item) wipe_out if b.has_left then from current_node := b.left_child until current_node = void loop child_put_right (current_node.item) child_forth child.fill_from_binary (current_node) current_node := current_node.right_child end end end linear_representation: LINEAR [G] is -- Representation as a linear structure -- (from TREE) local al: ARRAYED_LIST [G] do create al.make (count) al.start al.extend (item) fill_list (al) Result := al end feature -- Duplication copy (other: like Current) is -- Copy contents from other. require -- from ANY other_not_void: other /= void type_identity: same_type (other) local tmp_tree: like Current do create tmp_tree.make (other.item) if not other.is_leaf then tree_copy (other, tmp_tree) end ensure -- from ANY is_equal: is_equal (other) end duplicate (n: INTEGER): like Current is -- Copy of sub-tree beginning at cursor position and -- having min (n, arity - child_index + 1) -- children -- (from DYNAMIC_TREE) require -- from TREE not_child_off: not child_off valid_sublist: n >= 0 local pos: CURSOR counter: INTEGER do from Result := new_tree pos := child_cursor until child_after or else (counter = n) loop Result.put_child (child.duplicate_all) child_forth counter := counter + 1 end child_go_to (pos) end feature {NONE} -- Duplication twl_duplicate (n: INTEGER): like Current is -- Copy of sub-chain beginning at current position -- and having min (n, from_here) items, -- where from_here is the number of items -- at or to the right of current position. -- (from DYNAMIC_CHAIN) require -- from CHAIN not_off_unless_after: child_off implies child_after valid_subchain: n >= 0 local pos: CURSOR counter: INTEGER do from Result := new_chain if object_comparison then Result.compare_objects end pos := child_cursor until (counter = n) or else exhausted loop Result.child_extend (child_item) child_forth counter := counter + 1 end child_go_to (pos) end feature {NONE} -- Inapplicable bag_put (v: G) is -- (from TABLE) require -- from COLLECTION extendible: child_extendible do ensure -- from COLLECTION item_inserted: is_inserted (v) end feature {LINKED_TREE} -- Implementation new_cell (v: like item): like first_child is -- New cell containing v do create Result.make (v) Result.attach_to_parent (Current) ensure -- from LINKED_LIST result_exists: Result /= void end new_tree: like Current is -- A newly created instance of the same type, with -- the same node value. -- This feature may be redefined in descendants so as to -- produce an adequately allocated and initialized object. do create Result.make (item) ensure -- from DYNAMIC_TREE result_exists: Result /= void result_item: Result.item = item end feature {NONE} -- Implementation attach (other: like first_child) is -- Attach all children of other to current node. local cursor: CURSOR do from other.child_start until other.child_off loop other.child.attach_to_parent (Current) other.child_forth end other.child_go_to (cursor) end child_remove is -- Remove item of current child -- (from TREE) do end remove is -- Remove current item -- (from TREE) do end tree_copy (other, tmp_tree: like Current) is -- Generic implementation of copy. other is copied onto -- Current. tmp_tree is used as temporary storage during -- copying. Since it cannot be created locally because of the -- generic implementation, it has to be passed in. -- (from TREE) require -- from TREE other_not_empty: other /= void and then not other.is_leaf other_not_leaf: not other.is_leaf tmp_tree_exists: tmp_tree /= void same_rule: object_comparison = other.object_comparison local i: INTEGER p1, p2: like Current other_stack, tmp_stack: LINKED_STACK [like Current] idx_stack, orgidx_stack: LINKED_STACK [INTEGER] do create other_stack.make create tmp_stack.make create idx_stack.make create orgidx_stack.make if other.object_comparison then tmp_tree.compare_objects end orgidx_stack.put (other.child_index) from i := 1 p1 := other p2 := tmp_tree invariant same_count: other_stack.count = tmp_stack.count and tmp_stack.count = idx_stack.count until i > p1.child_capacity and other_stack.is_empty loop p1.child_go_i_th (i) p2.child_go_i_th (i) if p1.child_readable then check source_tree_not_void: p1 /= void target_tree_not_void: p2 /= void source_child_not_void: p1.child /= void target_child_void: p2.child = void end p2.replace_child (clone (p1.child)) if other_stack.is_empty then p2.child.attach_to_parent (Current) end check comparison_mode_ok: p2.child.object_comparison = p1.child.object_comparison p1_consistent: p1.child.parent = p1 p2_consistent: p2.child.parent = p2 end if not p1.child.is_leaf then other_stack.put (p1) tmp_stack.put (p2) idx_stack.put (i + 1) p1 := p1.child p2 := p2.child orgidx_stack.put (p1.child_index) i := 0 end end if i <= p1.child_capacity then i := i + 1 else from invariant same_count: other_stack.count = tmp_stack.count and tmp_stack.count = idx_stack.count until other_stack.is_empty or else i <= p1.child_capacity loop p1.child_go_i_th (orgidx_stack.item) p1 := other_stack.item p2 := tmp_stack.item check p1_not_void: p1 /= void p2_not_void: p2 /= void end i := idx_stack.item other_stack.remove tmp_stack.remove idx_stack.remove orgidx_stack.remove end end end check tree_stacks_empty: other_stack.is_empty and tmp_stack.is_empty at_root: p1 = other and p2 = tmp_tree end standard_copy (tmp_tree) child_go_i_th (orgidx_stack.item) orgidx_stack.remove check index_stack_empty: orgidx_stack.is_empty end end tree_is_equal (t1, t2: like Current): BOOLEAN is -- Are t1 and t2 recursively equal? -- (from TREE) require -- from TREE trees_exist: t1 /= void and t2 /= void trees_not_empty: not t1.is_leaf and not t2.is_leaf same_rule: t1.object_comparison = t2.object_comparison local i: INTEGER p1, p2: like Current t1_stack, t2_stack: LINKED_STACK [like Current] idx_stack, orgidx1_stack, orgidx2_stack: LINKED_STACK [INTEGER] do if t1.is_leaf and t2.is_leaf then if t1.object_comparison then Result := equal (t1.item, t2.item) else Result := (t1.item = t2.item) end elseif t1.is_leaf xor t2.is_leaf then Result := False else create t1_stack.make create t2_stack.make create idx_stack.make create orgidx1_stack.make create orgidx2_stack.make orgidx1_stack.put (t1.child_index) orgidx2_stack.put (t2.child_index) from Result := True i := 1 p1 := t1 p2 := t2 invariant same_count: t1_stack.count = t2_stack.count and t2_stack.count = idx_stack.count until not Result or else (i > p1.child_capacity and t1_stack.is_empty) loop check p1_not_void: p1 /= void p2_not_void: p2 /= void end p1.child_go_i_th (i) p2.child_go_i_th (i) if p1.child_readable and p2.child_readable and p1.child_capacity = p2.child_capacity then check p1_consistent: p1.child.parent = p1 p2_consistent: p2.child.parent = p2 end if t1.object_comparison then Result := equal (p1.item, p2.item) else Result := (p1.item = p2.item) end if not (p1.child.is_leaf or p2.child.is_leaf) then t1_stack.put (p1) t2_stack.put (p2) idx_stack.put (i + 1) p1 := p1.child p2 := p2.child orgidx1_stack.put (p1.child_index) orgidx2_stack.put (p2.child_index) i := 0 elseif p1.child.is_leaf xor p2.child.is_leaf then Result := False end elseif p1.child_capacity /= p2.child_capacity or else (p1.child_readable xor p2.child_readable) then Result := False end if i <= p1.child_capacity then i := i + 1 else from invariant same_count: t1_stack.count = t2_stack.count and t2_stack.count = idx_stack.count until t1_stack.is_empty or else i <= p1.child_capacity loop p1.child_go_i_th (orgidx1_stack.item) p2.child_go_i_th (orgidx2_stack.item) p1 := t1_stack.item p2 := t2_stack.item i := idx_stack.item t1_stack.remove t2_stack.remove idx_stack.remove orgidx1_stack.remove orgidx2_stack.remove end end end if not Result then from invariant same_count: t1_stack.count = t2_stack.count and orgidx1_stack.count = orgidx2_stack.count until orgidx1_stack.count = 1 loop p1.child_go_i_th (orgidx1_stack.item) p2.child_go_i_th (orgidx2_stack.item) p1 := t1_stack.item p2 := t2_stack.item check p1_not_void: p1 /= void p2_not_void: p2 /= void end t1_stack.remove t2_stack.remove orgidx1_stack.remove orgidx2_stack.remove end check tree_stacks_empty: t1_stack.is_empty and t2_stack.is_empty at_root: p1 = t1 and p2 = t2 p1_not_void: p1 /= void p2_not_void: p2 /= void end p1.child_go_i_th (orgidx1_stack.item) p2.child_go_i_th (orgidx2_stack.item) orgidx1_stack.remove orgidx2_stack.remove check index_stacks_empty: orgidx1_stack.is_empty and orgidx2_stack.is_empty end end end end feature {DYNAMIC_TREE} -- Implementation duplicate_all: like Current is -- Copy of sub-tree including all children -- (from DYNAMIC_TREE) local pos: CURSOR do from Result := new_tree pos := child_cursor child_start until child_off loop Result.put_child (child.duplicate_all) Result.child_forth child_forth end child_go_to (pos) end fill_subtree (other: TREE [G]) is -- Fill children with children of other. -- (from DYNAMIC_TREE) do from other.child_start until other.child_off loop child_extend (other.item) other.child_forth end from child_start other.child_start until child_off loop child.fill_subtree (other.child) other.child_forth child_forth end end feature {TREE} -- Implementation attach_to_parent (n: like parent) is -- Make n parent of current node. -- (from TREE) do parent := n ensure -- from TREE new_parent: parent = n end fill_list (al: ARRAYED_LIST [G]) is -- Fill al with all the children's items. -- (from TREE) do from child_start until child_off loop if child /= void then al.extend (child_item) child.fill_list (al) end child_forth end end subtree_count: INTEGER is -- Number of items in children -- (from TREE) local pos: CURSOR do Result := arity from pos := child_cursor child_start until child_off loop if child /= void then Result := Result + child.subtree_count end child_forth end child_go_to (pos) end subtree_has (v: G): BOOLEAN is -- Do children include v? -- (Reference or object equality, -- based on object_comparison.) -- (from TREE) local cursor: CURSOR do cursor := child_cursor from child_start until child_off or else Result loop if child /= void then if object_comparison then Result := (v /= void) and then (child_item /= void) and then v.is_equal (child_item) else Result := v = child_item end end child_forth end from child_start until child_off or else Result loop if child /= void then Result := child.subtree_has (v) end child_forth end child_go_to (cursor) end feature {TWO_WAY_TREE} -- Implementation forget_left is -- Remove links with left neighbor. -- (from BI_LINKABLE) do if left_sibling /= void then left_sibling.simple_forget_right left_sibling := void end ensure -- from BI_LINKABLE left_not_chained: left_sibling = void or else (old left_sibling /= void) implies ((old left_sibling).right_sibling = void) end forget_right is -- Remove links with right neighbor. -- (from BI_LINKABLE) do if right_sibling /= void then right_sibling.simple_forget_left right_sibling := void end ensure -- from LINKABLE not_chained: right_sibling = void ensure then -- from BI_LINKABLE right_not_chained: (old right_sibling /= void) implies ((old right_sibling).left_sibling = void) end bl_put_left (other: like Current) is -- Put other to the left of current cell. -- (from BI_LINKABLE) do if left_sibling /= void then left_sibling.simple_forget_right end left_sibling := other if (other /= void) then other.simple_put_right (Current) end ensure -- from BI_LINKABLE chained: left_sibling = other end bl_put_right (other: like Current) is -- Put other to the right of current cell. -- (from BI_LINKABLE) do if right_sibling /= void then right_sibling.simple_forget_left end right_sibling := other if (other /= void) then other.simple_put_left (Current) end ensure -- from LINKABLE chained: right_sibling = other end feature {BI_LINKABLE, TWO_WAY_LIST} -- Implementation simple_forget_left is -- Remove left link (do nothing to left neighbor). -- (from BI_LINKABLE) do left_sibling := void ensure -- from BI_LINKABLE not_chained: left_sibling = void end simple_forget_right is -- Remove right link (do nothing to right neighbor). -- (from BI_LINKABLE) do right_sibling := void end simple_put_left (other: like Current) is -- set left to other is -- (from BI_LINKABLE) do if left_sibling /= void then left_sibling.simple_forget_right end left_sibling := other end simple_put_right (other: like Current) is -- set right to other -- (from BI_LINKABLE) do if right_sibling /= void then right_sibling.simple_forget_left end right_sibling := other end feature {TWO_WAY_LIST} -- Implementation make_sublist (first_item, last_item: like first_child; n: INTEGER) is -- Create sublist -- (from TWO_WAY_LIST) do twl_make first_child := first_item last_child := last_item child := first_child arity := n end new_chain: 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. -- (from TWO_WAY_LIST) do create Result.twl_make ensure -- from DYNAMIC_CHAIN result_exists: Result /= void end previous: like first_child is -- Element left of cursor -- (from TWO_WAY_LIST) do if child_after then Result := child elseif child /= void then Result := child.left_sibling end end feature {LINKED_LIST} -- Implementation cleanup_after_remove (v: like first_child) is -- Clean-up a just removed cell. -- (from LINKED_LIST) require -- from LINKED_LIST non_void_cell: v /= void do end next: like first_child is -- Element right of cursor -- (from LINKED_LIST) do if child_before then Result := child elseif child /= void then Result := child.right_sibling end end feature -- Implementation child: like first_child -- Element at cursor position -- (from LINKED_LIST) 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 LINEAR) require -- from TRAVERSABLE action_exists: action /= void local t: TUPLE [G] do create t.make from child_start until child_after loop t.put (child_item, 1) action.call (t) child_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 LINEAR) require -- from TRAVERSABLE action_exists: action /= void test_exits: test /= void local t: TUPLE [G] do create t.make from child_start until child_after loop t.put (child_item, 1) if test.item (t) then action.call (t) end child_forth end end 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 child_start Result := True until child_after or not Result loop t.put (child_item, 1) Result := test.item (t) child_forth end if cs /= void then cs.go_to (c) end end 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 child_start until child_after or Result loop t.put (child_item, 1) Result := test.item (t) child_forth end if cs /= void then cs.go_to (c) end end invariant off_constraint: (child = void) implies child_off -- from ANY reflexive_equality: standard_is_equal (Current) reflexive_conformance: conforms_to (Current) -- from DYNAMIC_TREE extendible_definition: extendible child_after_definition: child_after = (child_index = arity + 1) -- from TREE leaf_definition: is_leaf = (arity = 0) child_off_definition: child_off = child_before or child_after child_before_definition: child_before = (child_index = 0) child_isfirst_definition: child_isfirst = (not is_leaf and child_index = 1) child_islast_definition: child_islast = (not is_leaf and child_index = child_capacity) child_after_definition: child_after = (child_index >= child_capacity + 1) child_consistency: child_readable implies child.parent = Current -- from BI_LINKABLE right_symmetry: (right_sibling /= void) implies (right_sibling.left_sibling = Current) left_symmetry: (left_sibling /= void) implies (left_sibling.right_sibling = Current) -- from TWO_WAY_LIST non_empty_list_has_two_endpoints: not is_leaf implies (first_child /= void and last_child /= void) first_element_constraint: first_child /= void implies first_child.left_sibling = void last_element_constraint: last_child /= void implies last_child.right_sibling = void -- from LINKED_LIST prunable: prunable empty_constraint: is_leaf implies ((first_child = void) and (child = void)) not_void_unless_empty: (child = void) implies is_leaf before_constraint: child_before implies (child = first_child) after_constraint: child_after implies (child = last_child) -- from LIST before_definition: child_before = (child_index = 0) after_definition: child_after = (child_index = arity + 1) -- from CHAIN non_negative_index: child_index >= 0 index_small_enough: child_index <= arity + 1 off_definition: child_off = ((child_index = 0) or (child_index = arity + 1)) isfirst_definition: child_isfirst = ((not is_leaf) and (child_index = 1)) islast_definition: child_islast = ((not is_leaf) and (child_index = arity)) item_corresponds_to_index: (not child_off) implies (child_item = i_th (child_index)) index_set_has_same_count: index_set.count = arity -- from ACTIVE writable_constraint: child_writable implies child_readable empty_constraint: is_leaf implies (not child_readable) and (not child_writable) -- from INDEXABLE index_set_not_void: index_set /= void -- from BILINEAR not_both: not (child_after and child_before) before_constraint: child_before implies child_off -- from LINEAR after_constraint: child_after implies child_off -- from TRAVERSABLE empty_constraint: is_leaf implies child_off -- from FINITE empty_definition: is_leaf = (arity = 0) non_negative_count: arity >= 0 -- from DYNAMIC_CHAIN extendible: child_extendible 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 TWO_WAY_TREE
Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:

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