Sort

class corsort.Sort(compute_history=False)[source]

Abstract class for sorting algorithms.

Parameters:

compute_history (bool) – If True, then compute the history of the distance to the sorted array.

n_

Number of items in the list.

Type:

int:

perm_

Input permutation.

Type:

ndarray

n_comparisons_

Number of comparison performed.

Type:

int

history_distances_

History of the Spearman footrule metric to the sorted list.

Type:

list of int

history_comparisons_

History of the pairwise comparisons. Tuple (i, j) means that items of indices i and j were compared, and that perm[i] < perm[j].

Type:

list of tuple

distance_to_sorted_array()[source]

Distance to sorted array.

Returns:

Distance between the current estimation and the sorted array.

Return type:

int

property history_comparisons_values_

History of the pairwise comparisons, in terms of compared values. Tuple (x, y) means that items of values x and y were compared, and that x < y.

Type:

list of tuple

test_i_lt_j(i, j)[source]

Test whether perm[i] < perm[j].

Parameters:
  • i (int) – First index.

  • j (int) – Second index.

Returns:

True if item of index i is lower than item of index j.

Return type:

bool

Notes

The history of distance is computed just before the comparison. Hence it should be computed a last time at the end of the algorithm.