core/vbl/vbl_sort.cxx
Go to the documentation of this file.
00001 // This is core/vbl/vbl_sort.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Andrew W. Fitzgibbon, Oxford RRG
00008 // \date   19 Nov 97
00009 //
00010 //-----------------------------------------------------------------------------
00011 
00012 #include "vbl_sort.h"
00013 
00014 //: Predicate that will sort doubles in ascending order.
00015 int vbl_sort_double_ascending(double const& a, double const& b)
00016 {
00017   if (a < b)
00018     return -1;
00019 
00020   if (a == b)
00021     return 0;
00022 
00023   return 1;
00024 }
00025 
00026 //: Predicate that will sort in descending order.
00027 int vbl_sort_double_descending(double const& a, double const& b)
00028 {
00029   if (a < b)
00030     return 1;
00031 
00032   if (a == b)
00033     return 0;
00034 
00035   return -1;
00036 }
00037 
00038 //: Ascending integers.
00039 int vbl_sort_int_ascending(int const& a, int const& b)
00040 {
00041   if (a < b)
00042     return -1;
00043 
00044   if (a == b)
00045     return 0;
00046 
00047   return 1;
00048 }
00049 
00050 //: Descending integers.
00051 int vbl_sort_int_descending(const int& a, const int& b)
00052 {
00053   if (a < b)
00054     return 1;
00055 
00056   if (a == b)
00057     return 0;
00058 
00059   return -1;
00060 }
00061 
00062 VBL_SORT_INSTANTIATE(int);
00063 VBL_SORT_INSTANTIATE(double);