deferred class interface COLLECTION2[E]
   --  
   --  Abstract definition of a 2 dimensional collection of elements
   --  of type E. 
   --  
   --  The SmallEiffel standard library (lib_std) provides two
   --  implementations : ARRAY2[E] and FIXED_ARRAY2[E].
   --  All implementations have exactly the same behavior. Switching 
   --  from one implementation to another only change the memory used
   --  and the execution time.
   -- 

feature(s) from COLLECTION2
   --  Indexing :

   lower1: INTEGER
      --  Lower index bounds.


feature(s) from COLLECTION2
   --  Indexing :

   lower2: INTEGER
      --  Lower index bounds.


   line_minimum: INTEGER
      --  Equivalent of lower1.


   column_minimum: INTEGER
      --  Equivalent of lower2.


   upper1: INTEGER
      --  Upper index bounds.


   upper2: INTEGER
      --  Upper index bounds.


   line_maximum: INTEGER
      --  Equivalent of upper1.


   column_maximum: INTEGER
      --  Equivalent of upper2.


feature(s) from COLLECTION2
   --  Reading :

   item (line, column: INTEGER): E
      require
         valid_index(line,column)

feature(s) from COLLECTION2
   --  Writing :

   put (element: like item; line, column: INTEGER)
      require
         valid_index(line,column)
      ensure
         item(line,column) = element

   force (element: like item; line, column: INTEGER)
      --  Put element at position (line,column). Collection is
      --  resized first when (line,column) is not inside current
      --  bounds. New bounds are initialized with default values.

      require
         line >= 0;
         column >= 0
      ensure
         item(line,column) = element;
         count >= old count

feature(s) from COLLECTION2
   --  Index validity :

   valid_line (line: INTEGER): BOOLEAN
      ensure
         Result = (lower1 <= line and line <= upper1)

feature(s) from COLLECTION2
   --  Index validity :

   valid_index1 (line: INTEGER): BOOLEAN
      ensure
         Result = (lower1 <= line and line <= upper1)

   valid_column (column: INTEGER): BOOLEAN
      ensure
         Result = (lower2 <= column and column <= upper2)

   valid_index2 (column: INTEGER): BOOLEAN
      ensure
         Result = (lower2 <= column and column <= upper2)

   valid_index (line, column: INTEGER): BOOLEAN
      ensure
         Result = (valid_line(line) and valid_index2(column))

feature(s) from COLLECTION2
   --  Counting :

   count1: INTEGER
      --  Size of the first dimension.

      ensure
         Result = upper1 - lower1 + 1

   line_count: INTEGER
      --  Equivalent of count1.


   count2: INTEGER
      --  Size of the second dimension.

      ensure
         Result = upper2 - lower2 + 1

   column_count: INTEGER

   count: INTEGER
      --  Total number of elements.

      ensure
         Result = line_count * column_count

feature(s) from COLLECTION2
   swap (line1, column1, line2, column2: INTEGER)
      --  Swap the element at index (line1,column1) with the
      --  the element at index (line2,column2).

      require
         valid_index(line1,column1);
         valid_index(line2,column2)
      ensure
         item(line1,column1) = old item(line2,column2);
         item(line2,column2) = old item(line1,column1);
         count = old count

   set_all_with (v: like item)
      --  Set all item with value v.

      ensure
         count = old count

   clear_all
      --  Set all items to default values.

      ensure
         count = old count

feature(s) from COLLECTION2
   --  Creating or initializing :

   from_collection2 (model: COLLECTION2[like item])
      --   Uses model to initialize Current.

      require
         model /= Void
      ensure
         count1 = model.count1;
         count2 = model.count2

   from_model (model: COLLECTION[COLLECTION[E]])
      --  The model is used to fill line by line Current.
      --  Assume all sub-collections of model have the same
      --  number of lines.

      require
         model /= Void
      ensure
         count1 = model.count;
         count2 > 0 implies count2 = model.first.count

feature(s) from COLLECTION2
   --  Looking and comparison :

   all_cleared: BOOLEAN
      --  Are all items set to default values ?


   same_as (other: COLLECTION2[E]): BOOLEAN
      --  Unlike is_equal, this feature can be used to compare
      --  distinct implementation of COLLECTION2.

      require
         other /= Void
      ensure
         Result implies standard_same_as(other)

feature(s) from COLLECTION2
   --  Printing :

   fill_tagged_out_memory
      --  Append a viewable information in tagged_out_memory in 
      --  order to affect the behavior of out, tagged_out, etc.


feature(s) from COLLECTION2
   --  Miscellaneous features :

   nb_occurrences (elt: E): INTEGER
      --  Number of occurrences using equal.
      --  See also fast_nb_occurrences to chose
      --  the apropriate one.

      ensure
         Result >= 0

   fast_nb_occurrences (elt: E): INTEGER
      --  Number of occurrences using =.

      ensure
         Result >= 0

   has (x: like item): BOOLEAN
      --  Search if a element x is in the array using equal.
      --  See also fast_has to chose the apropriate one.


   fast_has (x: like item): BOOLEAN
      --   Search if a element x is in the array using =.


   replace_all (old_value, new_value: like item)
      --  Replace all occurences of the element old_value by new_value 
      --  using equal for comparison.
      --  See also fast_replace_all to choose the apropriate one.

      ensure
         count = old count;
         nb_occurrences(old_value) = 0

   fast_replace_all (old_value, new_value: like item)
      --  Replace all occurences of the element old_value by new_value 
      --  using operator = for comparison.
      --  See also replace_all to choose the apropriate one.

      ensure
         count = old count;
         fast_nb_occurrences(old_value) = 0

   sub_collection2 (line_min, line_max, column_min, column_max: INTEGER): like Current
      --  Create a new object using selected area of Current.

      require
         valid_index(line_min,column_min);
         valid_index(line_min,column_min)
      ensure
         Result /= Void

   set_area (element: like item; line_min, line_max, column_min, column_max: INTEGER)
      --  Set all the elements of the selected area rectangle with element.

      require
         valid_index(line_min,line_max);
         valid_index(column_min,column_max)
      ensure
         count = old count


end of deferred COLLECTION2[E]