Automatic generation produced by ISE Eiffel

Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:
indexing description: "Trees where the children of each node are kept in an array" status: "See notice at end of class" names: tree representation: recursive, array access: cursor, membership contents: generic date: "$Date: 2001/11/16 20:34:23 $" revision: "$Revision: 1.1.1.1 $" class interface ARRAYED_TREE [G] create make (n: INTEGER; v: G) -- Create node with item v. -- Allocate space for n children. require valid_number_of_children: n >= 0 ensure node_item: item = v feature -- Initialization make (n: INTEGER; v: G) -- Create node with item v. -- Allocate space for n children. require valid_number_of_children: n >= 0 ensure node_item: item = v make_filled (n: INTEGER) -- Allocate list with n items. -- (n may be zero for empty list.) -- This list will be full. -- (from ARRAYED_LIST) require -- from ARRAYED_LIST valid_number_of_items: n >= 0 ensure -- from ARRAYED_LIST correct_position: child_before filled: al_full make_from_array (a: ARRAY [ARRAYED_TREE [G]]) -- Create list from array a. -- (from ARRAYED_LIST) require -- from ARRAY array_exists: a /= void feature -- Access child_item: like item -- Item in current child node -- (from TREE) require -- from TREE readable: child_readable child_cursor: CURSOR -- Current cursor position -- (from ARRAYED_LIST) first_child: ARRAYED_TREE [G] -- Item at first position -- (from ARRAYED_LIST) require -- from CHAIN not_empty: not is_leaf require -- from TREE is_not_leaf: not is_leaf child_index: INTEGER -- Index of item, if valid. -- (from ARRAYED_LIST) index_of (v: like child; i: INTEGER): INTEGER -- 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 ensure -- from LINEAR non_negative_result: Result >= 0 item: G -- Content of cell. -- (from CELL) child: like first_child -- Current item -- (from ARRAYED_LIST) require -- from TRAVERSABLE not_off: not child_off require -- from ACTIVE readable: readable_child require -- from TREE readable: readable_child require else -- from ARRAYED_LIST index_is_valid: valid_index (child_index) array_item (i: INTEGER): ARRAYED_TREE [G] -- Entry at index i, if in index interval -- Was declared in ARRAY as synonym of @. -- (from ARRAY) require -- from TABLE valid_key: array_valid_index (k) last_child: like first_child -- Item at last position -- (from ARRAYED_LIST) require -- from CHAIN not_empty: not is_leaf require -- from TREE is_not_leaf: not is_leaf left_sibling: like parent -- Left neighbor if any require -- from TREE is_not_root: not is_root ensure -- from TREE is_sibling: Result /= void implies is_sibling (Result) right_is_current: (Result /= void) implies (Result.right_sibling = Current) sequential_occurrences (v: ARRAYED_TREE [G]): INTEGER -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from LINEAR) ensure -- from BAG non_negative_occurrences: Result >= 0 parent: ARRAYED_TREE [G] -- Parent of current node right_sibling: like parent -- Right neighbor if any require -- from TREE is_not_root: not is_root ensure -- from TREE is_sibling: Result /= void implies is_sibling (Result) left_is_current: (Result /= void) implies (Result.left_sibling = Current) infix "@" (i: INTEGER): ARRAYED_TREE [G] -- Entry at index i, if in index interval -- Was declared in ARRAY as synonym of item. -- (from ARRAY) require -- from TABLE valid_key: array_valid_index (k) feature -- Measurement child_capacity: INTEGER -- Maximal number of children -- (from TREE) count: INTEGER -- Number of items -- (from TREE) arity: INTEGER -- Number of items. -- (from ARRAYED_LIST) index_set: INTEGER_INTERVAL -- Range of acceptable indexes -- (from CHAIN) ensure -- from INDEXABLE not_void: Result /= void ensure then -- from CHAIN count_definition: Result.count = arity occurrences (v: like child): INTEGER -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from CHAIN) ensure -- from BAG non_negative_occurrences: Result >= 0 occurrences (v: like child): INTEGER -- Number of times v appears. -- (Reference or object equality, -- based on object_comparison.) -- (from CHAIN) ensure -- from BAG non_negative_occurrences: Result >= 0 feature -- Measurement capacity: INTEGER -- Number of available indices -- Was declared in ARRAY as synonym of count. -- (from ARRAY) ensure then -- from ARRAY consistent_with_bounds: Result = upper - lower + 1 feature -- Comparison is_equal (other: like Current): BOOLEAN -- Does other contain the same elements? -- (Reference or object equality, -- based on object_comparison.) -- (from TREE) require -- from ANY other_not_void: other /= void 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 feature -- Status report child_after: BOOLEAN -- Is there no valid cursor position to the right of cursor? -- (from LIST) child_before: BOOLEAN -- Is there no valid cursor position to the left of cursor? -- (from LIST) changeable_comparison_criterion: BOOLEAN -- May object_comparison be changed? -- (Answer: yes by default.) -- (from CONTAINER) child_isfirst: BOOLEAN -- Is cursor under first child? -- (from TREE) ensure -- from CHAIN valid_position: Result implies not is_leaf ensure -- from TREE not_is_leaf: Result implies not is_leaf child_islast: BOOLEAN -- Is cursor under last child? -- (from TREE) ensure -- from CHAIN valid_position: Result implies not is_leaf ensure -- from TREE not_is_leaf: Result implies not is_leaf child_readable: BOOLEAN -- Is there a current child_item to be read? -- (from TREE) child_writable: BOOLEAN -- Is there a current child_item that may be modified? -- (from TREE) exhausted: BOOLEAN -- Has structure been completely explored? -- (from LINEAR) ensure -- from LINEAR exhausted_when_off: child_off implies Result Extendible: BOOLEAN is True -- May new items be added? -- (from DYNAMIC_TREE) Al_extendible: BOOLEAN is True -- May new items be added? (Answer: yes.) -- (from DYNAMIC_CHAIN) has (v: G): BOOLEAN -- Does subtree include v? -- (Reference or object equality, -- based on object_comparison.) -- (from TREE) ensure -- from CONTAINER not_found_in_empty: Result implies not is_leaf is_empty: BOOLEAN -- Is structure empty of items? -- (from TREE) is_inserted (v: ARRAYED_TREE [G]): BOOLEAN -- Has v been inserted at the end by the most recent put or -- extend? -- (from ARRAYED_LIST) is_leaf: BOOLEAN -- Are there no children? -- (from TREE) is_root: BOOLEAN -- Is there no parent? -- (from TREE) is_sibling (other: like parent): BOOLEAN -- Are current node and other siblings? -- (from TREE) require -- from TREE other_exists: other /= void 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 object_comparison: BOOLEAN -- Must search operations use equal rather than = -- for comparing references? (Default: no, use =.) -- (from CONTAINER) child_off: BOOLEAN -- Is there no current item? -- (from CHAIN) prunable: BOOLEAN -- May items be removed? (Answer: yes.) -- (from ARRAYED_LIST) Readable: BOOLEAN is True -- (from TREE) readable_child: BOOLEAN -- Is there a current item that may be read? -- (from SEQUENCE) valid_cursor (p: CURSOR): BOOLEAN -- Can the cursor be moved to position p? -- (from ARRAYED_LIST) valid_cursor_index (i: INTEGER): BOOLEAN -- Is i correctly bounded for cursor movement? -- (from TREE) 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) valid_index (i: INTEGER): BOOLEAN -- Is i a valid index? -- (from ARRAYED_LIST) 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)) valid_index (i: INTEGER): BOOLEAN -- Is i a valid index? -- (from ARRAYED_LIST) 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)) Writable: BOOLEAN is True -- Is there a current item that may be modified? -- (from TREE) writable_child: BOOLEAN -- Is there a current item that may be modified? -- (from SEQUENCE) feature -- Status setting compare_objects -- Ensure that future search operations will use equal -- rather than = for comparing references. -- (from CONTAINER) require -- from CONTAINER changeable_comparison_criterion ensure -- from CONTAINER object_comparison compare_references -- Ensure that future search operations will use = -- rather than equal for comparing references. -- (from CONTAINER) require -- from CONTAINER changeable_comparison_criterion ensure -- from CONTAINER reference_comparison: not object_comparison feature -- Cursor movement child_back -- Move cursor one position backward. -- (from ARRAYED_LIST) require -- from TREE True require -- from BILINEAR not_before: not child_before child_finish -- Move cursor to last position if any. -- (from ARRAYED_LIST) ensure then -- from CHAIN at_last: not is_leaf implies child_islast ensure then -- from TREE is_last_child: not is_leaf implies child_islast ensure then -- from ARRAYED_LIST before_when_empty: is_leaf implies child_before child_forth -- Move cursor one position forward. -- (from ARRAYED_LIST) require -- from TREE True require -- from LINEAR not_after: not child_after ensure then -- from LIST moved_forth: child_index = old child_index + 1 child_go_i_th (i: INTEGER) -- Move cursor to i-th position. -- (from ARRAYED_LIST) require -- from CHAIN valid_cursor_index: valid_cursor_index (i) require else -- from TREE valid_cursor_index: valid_cursor_index (i) ensure -- from CHAIN position_expected: child_index = i ensure then -- from TREE position: child_index = i child_go_to (p: CURSOR) -- Move cursor to position p. -- (from ARRAYED_LIST) require -- from TREE True require -- from CURSOR_STRUCTURE cursor_position_valid: valid_cursor (p) move (i: INTEGER) -- Move cursor i positions. -- (from ARRAYED_LIST) 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) search_child (v: like child) -- 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) ensure -- from LINEAR object_found: (not exhausted and object_comparison) implies equal (v, child) item_found: (not exhausted and not object_comparison) implies v = child child_start -- Move cursor to first position if any. -- (from ARRAYED_LIST) 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 ARRAYED_LIST after_when_empty: is_leaf implies child_after feature -- Element change append (s: SEQUENCE [ARRAYED_TREE [G]]) -- Append a copy of s. -- (from SEQUENCE) require -- from SEQUENCE argument_not_void: s /= void ensure -- from SEQUENCE new_count: arity >= old arity child_extend (v: like item) -- Add v at end. -- Do not move child cursor. child_put (v: like item) -- Replace current child item with v. -- Was declared in ARRAYED_TREE as synonym of child_replace. require -- from TREE child_writable: child_writable ensure -- from TREE item_inserted: child_item = v child_put_left (v: like item) -- Add v to the left of cursor position. -- Do not move child cursor. require -- from DYNAMIC_TREE not_child_before: not child_before child_put_right (v: like item) -- Add v to the right of cursor position. -- Do not move child cursor. require -- from DYNAMIC_TREE not_child_after: not child_after child_replace (v: like item) -- Replace current child item with v. -- Was declared in ARRAYED_TREE as synonym of child_put. require -- from TREE child_writable: child_writable ensure -- from TREE item_inserted: child_item = v fill (other: TREE [G]) -- Fill with as many items of other as possible. -- The representations of other and current node -- need not be the same. -- (from TREE) force (v: like child) -- Add v to end. -- Do not move cursor. -- Was declared in ARRAYED_LIST as synonym of extend. -- (from ARRAYED_LIST) require -- from SEQUENCE extendible: al_extendible ensure then -- from SEQUENCE new_count: arity = old arity + 1 item_inserted: has (v) merge_tree_after (other: like first_child) -- 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) ensure -- from DYNAMIC_TREE other_is_leaf: other.is_leaf merge_tree_before (other: like first_child) -- Merge children of other into current structure -- before cursor position. Do not move cursor. -- Make other a leaf. require -- from DYNAMIC_TREE not_child_off: not child_off other_exists: (other /= void) ensure -- from DYNAMIC_TREE other_is_leaf: other.is_leaf put_i_th (v: like array_item; i: INTEGER) -- Replace i-th entry, if in index interval, by v. -- (from ARRAY) require -- from TABLE valid_key: array_valid_index (k) ensure then -- from INDEXABLE insertion_done: array_item (k) = v put (v: like item) -- Make v the cell's item. -- Was declared in CELL as synonym of replace. -- (from CELL) require -- from TREE is_writable: writable ensure -- from TREE item_inserted: item = v ensure -- from CELL item_inserted: item = v put_child (n: like parent) -- Add n to the list of children. -- Do not move child cursor. require else -- from DYNAMIC_TREE non_void_argument: n /= void put_child_left (n: like parent) -- 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 put_child_right (n: like parent) -- Add n to the right of the cursor position. -- Do not move cursor. require -- from DYNAMIC_TREE not_child_after: not child_after non_void_argument: n /= void put_front (v: like child) -- Add v to the beginning. -- Do not move cursor. -- (from ARRAYED_LIST) ensure -- from DYNAMIC_CHAIN new_count: arity = old arity + 1 item_inserted: first_child = v replace (v: like item) -- Make v the cell's item. -- Was declared in CELL as synonym of put. -- (from CELL) require -- from TREE is_writable: writable ensure -- from TREE item_inserted: item = v ensure -- from CELL item_inserted: item = v replace_child (n: like parent) -- Make n the node's current child. require -- from TREE writable_child: writable_child was_root: n.is_root ensure -- from TREE child_replaced: child = n ensure then child_replaced: n.parent = Current sprout -- Make current node a root. -- (from TREE) feature -- Removal prune (v: like child) -- Remove first occurrence of v, if any, -- after cursor position. -- Move cursor to right neighbor. -- (or after if no right neighbor or v does not occur) -- (from ARRAYED_LIST) require -- from COLLECTION prunable: prunable require -- from TREE is_child: n.parent = Current ensure -- from TREE n_is_root: n.is_root prune_all (v: like