Automatic generation produced by ISE Eiffel

Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:
indexing description: "Contiguous integer intervals" status: "See notice at end of class" date: "$Date: 2001-11-16 20:32:23 +0000 (Fri, 16 Nov 2001) $" revision: "$Revision: 51435 $" class INTEGER_INTERVAL create make feature {NONE} -- Initialization make (min_index, max_index: INTEGER) is -- Set up interval to have bounds min_index and -- max_index (empty if min_index > max_index) do lower_defined := True upper_defined := True if min_index <= max_index then lower_internal := min_index upper_internal := max_index else lower_internal := 1 upper_internal := 0 end ensure lower_defined: lower_defined upper_defined: upper_defined set_if_non_empty: (min_index <= max_index) implies ((lower = min_index) and (upper = max_index)) empty_if_not_in_order: (min_index > max_index) implies is_empty end feature -- Initialization adapt (other: INTEGER_INTERVAL) is -- Reset to be the same interval as other. require other_not_void: other /= void do lower_internal := other.lower_internal upper_internal := other.upper_internal lower_defined := other.lower_defined upper_defined := other.upper_defined ensure same_lower: lower = other.lower same_upper: upper = other.upper same_lower_defined: lower_defined = other.lower_defined same_upper_defined: upper_defined = other.upper_defined end feature -- Access has (v: INTEGER): BOOLEAN is -- Does v appear in interval? -- Was declared in INTEGER_INTERVAL as synonym of valid_index. do Result := (upper_defined implies v <= upper) and (lower_defined implies v >= lower) ensure -- from CONTAINER not_found_in_empty: Result implies not is_empty ensure then iff_within_bounds: Result = ((upper_defined implies v <= upper) and (lower_defined implies v >= lower)) end item (i: INTEGER): INTEGER is -- Entry at index i, if in index interval -- Was declared in INTEGER_INTERVAL as synonym of @. require -- from TABLE valid_key: valid_index (k) do Result := i end lower: INTEGER is -- Smallest value in interval require lower_defined: lower_defined do Result := lower_internal end lower_defined: BOOLEAN -- Is there a lower bound? upper: INTEGER is -- Largest value in interval require upper_defined: upper_defined do Result := upper_internal end upper_defined: BOOLEAN -- Is there an upper bound? valid_index (v: INTEGER): BOOLEAN is -- Does v appear in interval? -- Was declared in INTEGER_INTERVAL as synonym of has. do Result := (upper_defined implies v <= upper) and (lower_defined implies v >= lower) ensure then -- from INDEXABLE only_if_in_index_set: Result implies ((i >= index_set.lower) and (i <= index_set.upper)) ensure then iff_within_bounds: Result = ((upper_defined implies v <= upper) and (lower_defined implies v >= lower)) end infix "@" (i: INTEGER): INTEGER is -- Entry at index i, if in index interval -- Was declared in INTEGER_INTERVAL as synonym of item. require -- from TABLE valid_key: valid_index (k) do Result := i end feature -- Measurement additional_space: INTEGER is -- Proposed number of additional items -- (from RESIZABLE) do Result := (capacity * growth_percentage // 100).max (minimal_increase) ensure -- from RESIZABLE at_least_one: Result >= 1 end capacity: INTEGER is -- Maximum number of items in interval -- (here the same thing as count) do check terminal: upper_defined and lower_defined end Result := count end count: INTEGER is -- Number of items in interval do check finite: upper_defined and lower_defined end if upper_defined and lower_defined then Result := upper - lower + 1 end ensure then definition: Result = upper - lower + 1 end Growth_percentage: INTEGER is 50 -- Percentage by which structure will grow automatically -- (from RESIZABLE) index_set: INTEGER_INTERVAL is -- Range of acceptable indexes -- (here: the interval itself) do Result := Current ensure -- from INDEXABLE not_void: Result /= void ensure then index_set_is_range: equal (Result, Current) end Minimal_increase: INTEGER is 5 -- Minimal number of additional items -- (from RESIZABLE) occurrences (v: INTEGER): INTEGER is -- Number of times v appears in structure do if has (v) then Result := 1 end ensure -- from BAG non_negative_occurrences: Result >= 0 ensure then one_iff_in_bounds: Result = 1 implies has (v) zero_otherwise: Result /= 1 implies Result = 0 end feature -- Comparison is_equal (other: like Current): BOOLEAN is -- Is array made of the same items as other? require -- from ANY other_not_void: other /= void do Result := (lower_defined implies (other.lower_defined and lower = other.lower)) and (upper_defined implies (other.upper_defined and upper = other.upper)) ensure -- from ANY symmetric: Result implies other.is_equal (Current) consistent: standard_is_equal (other) implies Result ensure then iff_same_bounds: Result = ((lower_defined implies (other.lower_defined and lower = other.lower)) and (upper_defined implies (other.upper_defined and upper = other.upper))) end feature -- Status report all_cleared: BOOLEAN is -- Are all items set to default values? do Result := ((lower = 0) and (upper = 0)) ensure then iff_at_zero: Result = ((lower = 0) and (upper = 0)) end empty: BOOLEAN is obsolete "ELKS 2000: Use `is_empty' instead" -- Is there no element? -- (from CONTAINER) do Result := is_empty end extendible: BOOLEAN is -- May new items be added? -- Answer: yes do Result := True end full: BOOLEAN is -- Is structure full? -- (from BOUNDED) do Result := (count = capacity) end is_empty: BOOLEAN is -- Is structure empty? -- (from FINITE) do Result := (count = 0) end is_inserted (v: INTEGER): 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 object_comparison: BOOLEAN -- Must search operations use equal rather than = -- for comparing references? (Default: no, use =.) -- (from CONTAINER) prunable: BOOLEAN is -- May individual items be removed? -- Answer: no do Result := False end resizable: BOOLEAN is -- May capacity be changed? (Answer: yes.) -- (from RESIZABLE) do Result := True 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 -- Element change extend (v: INTEGER) is -- Make sure that interval goes all the way -- to v (up or down). -- Was declared in INTEGER_INTERVAL as synonym of put. require -- from COLLECTION extendible: extendible do if v < lower then lower_internal := v elseif v > upper then upper_internal := v end ensure -- from COLLECTION item_inserted: is_inserted (v) ensure then -- from SET in_set_already: old has (v) implies (count = old count) added_to_set: not old has (v) implies (count = old count + 1) ensure then -- from BAG one_more_occurrence: occurrences (v) = old (occurrences (v)) + 1 ensure then extended_down: lower = (old lower).min (v) extended_up: upper = (old upper).max (v) end fill (other: CONTAINER [INTEGER]) 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 [INTEGER] 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 put (v: INTEGER) is -- Make sure that interval goes all the way -- to v (up or down). -- Was declared in INTEGER_INTERVAL as synonym of extend. require -- from COLLECTION extendible: extendible do if v < lower then lower_internal := v elseif v > upper then upper_internal := v end ensure -- from COLLECTION item_inserted: is_inserted (v) ensure then -- from SET in_set_already: old has (v) implies (count = old count) added_to_set: not old has (v) implies (count = old count + 1) ensure then extended_down: lower = (old lower).min (v) extended_up: upper = (old upper).max (v) end feature -- Removal changeable_comparison_criterion: BOOLEAN is -- May object_comparison be changed? -- (Answer: only if set empty; otherwise insertions might -- introduce duplicates, destroying the set property.) -- (from SET) do Result := is_empty ensure then -- from SET only_on_empty: Result = is_empty end prune_all (v: INTEGER) 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 wipe_out is -- Remove all items. require -- from COLLECTION prunable do lower_defined := True upper_defined := True lower_internal := 1 upper_internal := 0 ensure -- from COLLECTION wiped_out: is_empty end feature -- Resizing automatic_grow is -- Change the capacity to accommodate at least -- Growth_percentage more items. -- (from RESIZABLE) do grow (capacity + additional_space) ensure -- from RESIZABLE increased_capacity: capacity >= old capacity + old capacity * growth_percentage // 100 end grow (i: INTEGER) is -- Ensure that capacity is at least i. do if capacity < i then resize (lower, lower + i - 1) end ensure -- from RESIZABLE new_capacity: capacity >= i ensure then no_loss_from_bottom: lower <= old lower no_loss_from_top: upper >= old upper end resize (min_index, max_index: INTEGER) is -- Rearrange interval to go from at most -- min_index to at least max_index, -- encompassing previous bounds. do lower_internal := min_index.min (lower) upper_internal := max_index.max (upper) end resize_exactly (min_index, max_index: INTEGER) is -- Rearrange interval to go from -- min_index to max_index. do lower_internal := min_index upper_internal := max_index end feature -- Conversion as_array: ARRAY [INTEGER] is -- Plain array containing interval's items require finite: upper_defined and lower_defined local i: INTEGER do create Result.make (lower, upper) from i := lower until i > upper loop Result.put (i, i) i := i + 1 end ensure same_lower: Result.lower = lower same_upper: Result.upper = upper end linear_representation: LINEAR [INTEGER] is -- Representation as a linear structure do check terminal: upper_defined and lower_defined end Result := as_array.linear_representation end to_c: ANY is -- Address of actual sequence of values, -- for passing to external (non-Eiffel) routines. require finite: upper_defined and lower_defined do Result := as_array.to_c end feature -- Duplication copy (other: like Current) is -- Reset to be the same interval as other. require -- from ANY other_not_void: other /= void type_identity: same_type (other) do lower_internal := other.lower_internal upper_internal := other.upper_internal lower_defined := other.lower_defined upper_defined := other.upper_defined ensure -- from ANY is_equal: is_equal (other) ensure then same_lower: lower = other.lower same_upper: upper = other.upper same_lower_defined: lower_defined = other.lower_defined same_upper_defined: upper_defined = other.upper_defined end subinterval (start_pos, end_pos: INTEGER): like Current is -- Interval made of items of current array within -- bounds start_pos and end_pos. do create Result.make (start_pos, end_pos) end feature {NONE} -- Inapplicable bag_put (v: INTEGER) is -- (from TABLE) require -- from COLLECTION extendible: extendible do ensure -- from COLLECTION item_inserted: is_inserted (v) end indexable_put (v: INTEGER; k: INTEGER) is -- Associate value v with key k. -- Not applicable here. require -- from TABLE valid_key: valid_index (k) do ensure then -- from INDEXABLE insertion_done: item (k) = v end prune (v: INTEGER) is -- Remove one occurrence of v if any. -- Not applicable here. require -- from COLLECTION prunable: prunable do ensure then -- from SET removed_count_change: old has (v) implies (count = old count - 1) not_removed_no_count_change: not old has (v) implies (count = old count) item_deleted: not has (v) end feature {INTEGER_INTERVAL} -- Implementation lower_internal: INTEGER -- See `lower`. upper_internal: INTEGER -- See `upper`. feature -- Iteration exists (condition: FUNCTION [ANY, TUPLE [INTEGER], BOOLEAN]): BOOLEAN is -- Does at least one of  interval's values -- satisfy condition? require finite: upper_defined and lower_defined local i: INTEGER do from i := lower until i > upper or else condition.item ([i]) loop i := i + 1 end Result := (i <= upper) ensure consistent_with_count: Result = (hold_count (condition) > 0) end exists1 (condition: FUNCTION [ANY, TUPLE [INTEGER], BOOLEAN]): BOOLEAN is -- Does exactly one of  interval's values -- satisfy condition? require finite: upper_defined and lower_defined do Result := (hold_count (condition) = 1) ensure consistent_with_count: Result = (hold_count (condition) = 1) end for_all (condition: FUNCTION [ANY, TUPLE [INTEGER], BOOLEAN]): BOOLEAN is -- Do all interval's values satisfy condition? require finite: upper_defined and lower_defined local i: INTEGER do from Result := True i := lower until (i > upper) or else (not condition.item ([i])) loop i := i + 1 end Result := (i > upper) ensure consistent_with_count: Result = (hold_count (condition) = count) end hold_count (condition: FUNCTION [ANY, TUPLE [INTEGER], BOOLEAN]): INTEGER is -- Number of  interval's values that -- satisfy condition require finite: upper_defined and lower_defined local i: INTEGER do from i := lower until i > upper loop if condition.item ([i]) then Result := Result + 1 end i := i + 1 end ensure non_negative: Result >= 0 end invariant count_definition: upper_defined and lower_defined implies count = upper - lower + 1 index_set_is_range: equal (index_set, Current) not_infinite: upper_defined and lower_defined -- from ANY reflexive_equality: standard_is_equal (Current) reflexive_conformance: conforms_to (Current) -- from RESIZABLE increase_by_at_least_one: minimal_increase >= 1 -- from BOUNDED valid_count: count <= capacity full_definition: full = (count = capacity) -- from FINITE empty_definition: is_empty = (count = 0) non_negative_count: count >= 0 -- from INDEXABLE index_set_not_void: index_set /= void 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 INTEGER_INTERVAL
Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:

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