OpenTTD
Functions
sort_func.hpp File Reference

Functions related to sorting operations. More...

#include "mem_func.hpp"

Go to the source code of this file.

Functions

template<typename T >
static void QSortT (T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
 Type safe qsort() More...
 
template<typename T >
static void GSortT (T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
 Type safe Gnome Sort. More...
 

Detailed Description

Functions related to sorting operations.

Definition in file sort_func.hpp.

Function Documentation

◆ GSortT()

template<typename T >
static void GSortT ( T *  base,
uint  num,
int(CDECL *comparator)(const T *, const T *)  ,
bool  desc = false 
)
inlinestatic

Type safe Gnome Sort.

This is a slightly modified Gnome search. The basic Gnome search tries to sort already sorted list parts. The modification skips these.

Note
Use this sort for presorted / regular sorted data.
Parameters
basePointer to the first element of the array to be sorted.
numNumber of elements in the array pointed by base.
comparatorFunction that compares two elements.
descSort descending.

Definition at line 52 of file sort_func.hpp.

Referenced by GUIList< const Company *>::Sort().

◆ QSortT()

template<typename T >
static void QSortT ( T *  base,
uint  num,
int(CDECL *comparator)(const T *, const T *)  ,
bool  desc = false 
)
inlinestatic

Type safe qsort()

Note
Use this sort for irregular sorted data.
Parameters
basePointer to the first element of the array to be sorted.
numNumber of elements in the array pointed by base.
comparatorFunction that compares two elements.
descSort descending.

Definition at line 28 of file sort_func.hpp.

Referenced by CmdSetTimetableStart(), DoScanNewGRFFiles(), EngList_Sort(), WindowDesc::SaveToConfig(), GUIList< const Company *>::Sort(), and SortIndustryTypes().