00001 /* EGlib "Efficient General Library" provides some basic structures and 00002 * algorithms commons in many optimization algorithms. 00003 * 00004 * Copyright (C) 2005 Daniel Espinoza and Marcos Goycoolea. 00005 * 00006 * This library is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published by the 00008 * Free Software Foundation; either version 2.1 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00013 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00014 * License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this library; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 * */ 00020 #include "eg_compare.h" 00021 /** @file 00022 * @ingroup EGcompare */ 00023 /* @{ */ 00024 00025 /* ========================================================================= */ 00026 /** @brief Lexicographical order of strings. 00027 * @param str1 pointer to a stream of stirngs. 00028 * @param str2 pointer to a stream of stirngs. 00029 * @par Description: 00030 * This function compare two strings of (\\0 terminated) chars in 00031 * lexicographical order. */ 00032 int EGstringCompare (const void *str1, 00033 const void *str2) 00034 { 00035 return strcmp ((const char *) str1, (const char *) str2); 00036 } 00037 00038 /* ========================================================================= */ 00039 /** @brief Normal order of doubles. 00040 * @par Description: 00041 * This function compare two double. */ 00042 int EGlfCompare (const void *str1, 00043 const void *str2) 00044 { 00045 if (*((const double *) str1) < *((const double *) str2)) 00046 return -1; 00047 if (*((const double *) str1) > *((const double *) str2)) 00048 return 1; 00049 return 0; 00050 } 00051 00052 /* ========================================================================= */ 00053 /** @brief Normal order of integers. 00054 * @par Description: 00055 * This function compare integers. */ 00056 int EGdCompare (const void *str1, 00057 const void *str2) 00058 { 00059 if (*((const int *) str1) < *((const int *) str2)) 00060 return -1; 00061 if (*((const int *) str1) > *((const int *) str2)) 00062 return 1; 00063 return 0; 00064 } 00065 00066 /* ========================================================================= */ 00067 /** @brief Normal order of unsigned integers. 00068 * @par Description: 00069 * This function compare two unsigned integers. */ 00070 int EGudCompare (const void *str1, 00071 const void *str2) 00072 { 00073 return memcmp (str1, str2, sizeof (unsigned int)); 00074 } 00075 00076 /* ========================================================================= */ 00077 /** @brief Normal order of pointers. 00078 * @par Description: 00079 * This function compare pointers in 'memory' order. */ 00080 int EGptCompare (const void *str1, 00081 const void *str2) 00082 { 00083 if (str1 < str2) 00084 return -1; 00085 if (str1 > str2) 00086 return 1; 00087 return 0; 00088 } 00089 00090 /* ========================================================================= */ 00091 /* } */ 00092 /* end of eg_compare.c */
1.4.5