00001 /** 00002 * @copyright 00003 * ==================================================================== 00004 * Copyright (c) 2000-2004 CollabNet. All rights reserved. 00005 * 00006 * This software is licensed as described in the file COPYING, which 00007 * you should have received as part of this distribution. The terms 00008 * are also available at http://subversion.tigris.org/license-1.html. 00009 * If newer versions of this license are posted there, you may use a 00010 * newer version instead, at your option. 00011 * 00012 * This software consists of voluntary contributions made by many 00013 * individuals. For exact contribution history, see the revision 00014 * history and logs, available at http://subversion.tigris.org/. 00015 * ==================================================================== 00016 * @endcopyright 00017 * 00018 * @file svn_sorts.h 00019 * @brief all sorts of sorts. 00020 */ 00021 00022 00023 #ifndef SVN_SORTS_H 00024 #define SVN_SORTS_H 00025 00026 #include <apr_pools.h> 00027 #include <apr_tables.h> /* for apr_array_header_t */ 00028 #include <apr_hash.h> 00029 00030 00031 #ifdef __cplusplus 00032 extern "C" { 00033 #endif /* __cplusplus */ 00034 00035 00036 00037 /** This structure is used to hold a key/value from a hash table. 00038 * NOTE: Private. For use by Subversion's own code only. See issue #1644. 00039 */ 00040 typedef struct svn_sort__item_t { 00041 /** pointer to the key */ 00042 const void *key; 00043 00044 /** size of the key */ 00045 apr_ssize_t klen; 00046 00047 /** pointer to the value */ 00048 void *value; 00049 } svn_sort__item_t; 00050 00051 00052 /** Compare two @c svn_sort__item_t's, returning an integer greater than, 00053 * equal to, or less than 0, according as @a a is greater than, equal to, 00054 * or less than @a b. 00055 * 00056 * This is useful for converting a hash into a sorted 00057 * @c apr_array_header_t. For example, to convert hash @a hsh to a sorted 00058 * array, do this: 00059 * 00060 *<pre> apr_array_header_t *hdr; 00061 * hdr = svn_sort__hash (hsh, @c svn_sort_compare_items_as_paths, pool);</pre> 00062 * 00063 * The key strings must be null-terminated, even though klen does not 00064 * include the terminator. 00065 */ 00066 int svn_sort_compare_items_as_paths (const svn_sort__item_t *a, 00067 const svn_sort__item_t *b); 00068 00069 00070 /** Compare two @c svn_sort__item_t's, returning an integer greater than, 00071 * equal to, or less than 0, according as @a a is greater than, equal to, 00072 * or less than @a b according to a lexical key comparison. The keys are 00073 * not required to be zero-terminated. 00074 */ 00075 int svn_sort_compare_items_lexically (const svn_sort__item_t *a, 00076 const svn_sort__item_t *b); 00077 00078 /** Compare two @c svn_revnum_t's, returning an integer greater than, equal 00079 * to, or less than 0, according as @a b is greater than, equal to, or less 00080 * than @a a. Note that this sorts newest revision to oldest (IOW, descending 00081 * order). 00082 * 00083 * This function is compatible for use with @c qsort(). 00084 * 00085 * This is useful for converting an array of revisions into a sorted 00086 * @c apr_array_header_t. You are responsible for detecting, preventing or 00087 * removing duplicates. 00088 */ 00089 int svn_sort_compare_revisions (const void *a, const void *b); 00090 00091 00092 /** 00093 * @since New in 1.1. 00094 * 00095 * Compare two @c const char * paths, returning an integer greater 00096 * than, equal to, or less than 0, using the same comparison rules as 00097 * are used by @c svn_path_compare_paths. 00098 * 00099 * This function is compatible for use with @c qsort(). 00100 */ 00101 int svn_sort_compare_paths (const void *a, const void *b); 00102 00103 00104 /** Sort @a ht according to its keys, return an @c apr_array_header_t 00105 * containing @c svn_sort__item_t structures holding those keys and values 00106 * (i.e. for each @c svn_sort__item_t @a item in the returned array, 00107 * @a item->key and @a item->size are the hash key, and @a item->data points to 00108 * the hash value). 00109 * 00110 * Storage is shared with the original hash, not copied. 00111 * 00112 * @a comparison_func should take two @c svn_sort__item_t's and return an 00113 * integer greater than, equal to, or less than 0, according as the first item 00114 * is greater than, equal to, or less than the second. 00115 * 00116 * NOTE: Private. For use by Subversion's own code only. See issue #1644. 00117 * 00118 * NOTE: This function and the @a svn_sort__item_t should go over to APR. 00119 */ 00120 apr_array_header_t * 00121 svn_sort__hash (apr_hash_t *ht, 00122 int (*comparison_func) (const svn_sort__item_t *, 00123 const svn_sort__item_t *), 00124 apr_pool_t *pool); 00125 00126 00127 #ifdef __cplusplus 00128 } 00129 #endif /* __cplusplus */ 00130 00131 #endif /* SVN_SORTS_H */