+
Point of view
All features
expanded class COMPARATOR_COLLECTION_SORTER [X_]
Summary
Some algorithms to sort any COLLECTION using an external comparator.
Elements are sorted using the order given by the comparator: large elements at the beginning of the collection, small at the end (increasing order is implemented by class COLLECTION_SORTER).
Note that without setting a comparator (using set_comparator), collections won't get sorted.
How to use this expanded class :
         local
            sorter: COMPARATOR_COLLECTION_SORTER[INTEGER]
            array: ARRAY[INTEGER]
         do
            array := <<1,3,2>>
            sorter.set_comparator(agent my_comparator)
            sorter.sort(array)
            check
               sorter.is_sorted(array)
            end
            ...
Direct parents
Insert list: ABSTRACT_SORTER
Overview
Creation features
{ANY}
Features
{ANY}
{}
Auxiliary functions
{}
{ANY}
  • is_sorted (c: COLLECTION[X_]): BOOLEAN
    Is c already sorted ? Uses lte for comparison.
  • has (c: COLLECTION[X_], element: X_): BOOLEAN
  • index_of (c: COLLECTION[X_], element: X_): INTEGER_32
  • add (c: COLLECTION[X_], element: X_)
    Add element in collection c keeping the sorted property.
  • insert_index (c: COLLECTION[X_], element: X_): INTEGER_32
    retrieve the upper index for which gt
  • sort (c: COLLECTION[X_])
    Sort c using the default most efficient sorting algorithm already implemented.
  • quick_sort (c: COLLECTION[X_])
    Sort c using the quick sort algorithm.
  • von_neuman_sort (c: COLLECTION[X_])
    Sort c using the Von Neuman algorithm.
  • heap_sort (c: COLLECTION[X_])
    Sort c using the heap sort algorithm.
  • bubble_sort (c: COLLECTION[X_])
    Sort c using the bubble sort algorithm.
{}
set_comparator (a_comparator: FUNCTION[TUPLE[TUPLE 2[X_, X_]]])
effective procedure
{ANY}
comparator: FUNCTION[TUPLE[TUPLE 2[X_, X_]]]
writable attribute
{ANY}
lt (x: X_, y: X_): BOOLEAN
effective function
{}
default_comparator (x: X_, y: X_): BOOLEAN
effective function
{}
default_create
effective procedure
{}
Default creation method.
with_comparator (a_comparator: FUNCTION[TUPLE[TUPLE 2[X_, X_]]])
effective procedure
{}
gt (x: X_, y: X_): BOOLEAN
effective function
{}
lte (x: X_, y: X_): BOOLEAN
effective function
{}
gte (x: X_, y: X_): BOOLEAN
effective function
{}
is_sorted (c: COLLECTION[X_]): BOOLEAN
effective function
{ANY}
Is c already sorted ? Uses lte for comparison.
has (c: COLLECTION[X_], element: X_): BOOLEAN
effective function
{ANY}
index_of (c: COLLECTION[X_], element: X_): INTEGER_32
effective function
{ANY}
add (c: COLLECTION[X_], element: X_)
effective procedure
{ANY}
Add element in collection c keeping the sorted property.
insert_index (c: COLLECTION[X_], element: X_): INTEGER_32
effective function
{ANY}
retrieve the upper index for which gt
sort (c: COLLECTION[X_])
effective procedure
{ANY}
Sort c using the default most efficient sorting algorithm already implemented.
quick_sort (c: COLLECTION[X_])
effective procedure
{ANY}
Sort c using the quick sort algorithm.
von_neuman_sort (c: COLLECTION[X_])
effective procedure
{ANY}
Sort c using the Von Neuman algorithm.
heap_sort (c: COLLECTION[X_])
effective procedure
{ANY}
Sort c using the heap sort algorithm.
bubble_sort (c: COLLECTION[X_])
effective procedure
{ANY}
Sort c using the bubble sort algorithm.
von_neuman_line (src: COLLECTION[X_], dest: COLLECTION[X_], count: INTEGER_32, d_count: INTEGER_32, lower: INTEGER_32, imax: INTEGER_32)
effective procedure
{}
von_neuman_inner_sort (src: COLLECTION[X_], dest: COLLECTION[X_], sg1: INTEGER_32, count: INTEGER_32, imax: INTEGER_32)
effective procedure
{}
heap_repair (c: COLLECTION[X_], c_lower: INTEGER_32, first: INTEGER_32, last: INTEGER_32)
effective procedure
{}
Repair the heap from the node number first It considers that the last item of c is number last It supposes that children are heaps.
quick_sort_region (c: COLLECTION[X_], left: INTEGER_32, right: INTEGER_32)
effective procedure
{}