indexing
	description: "Two-dimensional arrays"
	names: array2, matrix, table
	representation: array
	access: index, row_and_column, membership
	size: resizable
	contents: generic

class interface
	ARRAY2 [G]

create 

	make (nb_rows, nb_columns: INTEGER)
			-- Create a two dimensional array which has nb_rows
			-- rows and nb_columns columns,
			-- with lower bounds starting at 1.
		require
			not_flat: nb_rows > 0;
			not_thin: nb_columns > 0
		ensure
			new_count: count = height * width

feature -- Initialization

	initialize (v: G)
			-- Make each entry have value v.

	make (nb_rows, nb_columns: INTEGER)
			-- Create a two dimensional array which has nb_rows
			-- rows and nb_columns columns,
			-- with lower bounds starting at 1.
		require
			not_flat: nb_rows > 0;
			not_thin: nb_columns > 0
		ensure
			new_count: count = height * width

	setup (other: like Current)
			-- Perform actions on a freshly created object so that
			-- the contents of other can be safely copied onto it.
			-- (from ARRAY)
		ensure -- from GENERAL
			consistent (other)
	
feature -- Access

	item (row, column: INTEGER): G
			-- Entry at coordinates (row, column)
		require
			valid_row: (1 <= row) and (row <= height);
			valid_column: (1 <= column) and (column <= width)
	
feature {ANY} -- Access

	area: SPECIAL [G]
			-- Special data zone
			-- (from TO_SPECIAL)
	
feature -- Measurement

	height: INTEGER
			-- Number of rows

	width: INTEGER
			-- Number of columns
	
feature -- Comparison

	is_equal (other: like Current): BOOLEAN
			-- Is array made of the same items as other?
			-- (from ARRAY)
		require -- from GENERAL
			other_not_void: other /= void
		ensure -- from GENERAL
			symmetric: Result implies other.is_equal (Current);
			consistent: standard_is_equal (other) implies Result
	
feature -- Status report

	consistent (other: like Current): BOOLEAN
			-- Is object in a consistent state so that other
			-- may be copied onto it? (Default answer: yes).
			-- (from ARRAY)
	
feature -- Element change

	force (v: like item; row, column: INTEGER)
			-- Assign item v at coordinates (row, column).
			-- Resize if necessary.
		require
			row_large_enough: 1 <= row;
			column_large_enough: 1 <= column

	put (v: like item; row, column: INTEGER)
			-- Assign item v at coordinates (row, column).
		require
			valid_row: 1 <= row and row <= height;
			valid_column: 1 <= column and column <= width
	
feature -- Removal

	wipe_out
			-- Remove all items.
		require -- from COLLECTION
			prunable

feature -- Resizing

	resize (nb_rows, nb_columns: INTEGER)
			-- Rearrange array so that it can accommodate
			-- nb_rows rows and nb_columns columns,
			-- without losing any previously
			-- entered items, nor changing their coordinates;
			-- do nothing if not possible.
		require
			valid_row: nb_rows >= 1;
			valid_column: nb_columns >= 1
	
feature -- Duplication

	copy (other: like Current)
			-- Reinitialize by copying all the items of other.
			-- (This is also used by clone.)
			-- (from ARRAY)
		require -- ARRAY
			precursor: True
		require -- from GENERAL
			other_not_void: other /= void;
			type_identity: same_type (other)
		ensure then -- from ARRAY
			equal_areas: area.is_equal (other.area)
		ensure -- from GENERAL
			is_equal: is_equal (other)
		ensure then -- from ARRAY
			equal_areas: area.is_equal (other.area)
	
invariant

		-- from GENERAL
	reflexive_equality: standard_is_equal (Current);
	reflexive_conformance: conforms_to (Current);
	items_number: count = width * height;

end -- class ARRAY2