# Module e.c.u.sorting

Part of elisa.core.utils

Utility functions for sorting

Line # | Kind | Name | Docs
--- | --- | --- | ---
39 | Function | natural_cmp | Compare the two strings `this` and `other` with a more natural way.
50 | Function | natural_sort | Case insensitive human compliant sort.
59 | Function | async_ordered_placement | Place the `sort_obj` at the right position of the `sorted_list`. As the
92 | Function | async_sorted_merge | Merge `to_insert_list` into `reference_list` by sorting every item into it

def natural_cmp(this, other):
Compare the two strings `this` and `other` with a more natural way.

def natural_sort(l):
Case insensitive human compliant sort.

Parameters | l | list that needs to be sorted (type: list of unicode )

def async_ordered_placement(sorted_list, sort_obj, compare=cmp):

Place the `sort_obj` at the right position of the `sorted_list`. As the name already says `sorted_list` is meant to be a sorted list so that the new object can be placed at right position by comparing it with the others in the list.

This is done in non-blocking manner.

This method is returing a deferred that lets you cancel the operation when it is not finished yet.

Parameters | sorted_list | the reference list (sorted) the object should placed into (type: `list` )
| sort_obj | the (compareable) object you want to have placed in the reference list
| compare | method that should be used to compare the two objects. the expected return values should be as for `cmp`. Default: `cmp` (type: `Callable` like `cmp` )
Returns | (type: `elisa.core.utils.cancellable_defer.CancellableDeferred` )

def async_sorted_merge(reference_list, to_insert_list, compare=cmp):
Merge `to_insert_list` into `reference_list` by sorting every item into it in ansynchronous manner. The `reference_list` needs to be sorted while the `to_insert_list` is not expected to be so.

Parameters | compare | method that should be used to compare the two objects. the expected return values should be as for `cmp`. Default: `cmp` (type: `Callable` like `cmp` FIXME: this might not be sorting totally correctly if it is called twice at the same time with two different lists. )