Subversion
|
00001 /** 00002 * @copyright 00003 * ==================================================================== 00004 * Licensed to the Apache Software Foundation (ASF) under one 00005 * or more contributor license agreements. See the NOTICE file 00006 * distributed with this work for additional information 00007 * regarding copyright ownership. The ASF licenses this file 00008 * to you under the Apache License, Version 2.0 (the 00009 * "License"); you may not use this file except in compliance 00010 * with the License. You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, 00015 * software distributed under the License is distributed on an 00016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00017 * KIND, either express or implied. See the License for the 00018 * specific language governing permissions and limitations 00019 * under the License. 00020 * ==================================================================== 00021 * @endcopyright 00022 * 00023 * @file svn_sorts.h 00024 * @brief all sorts of sorts. 00025 */ 00026 00027 00028 #ifndef SVN_SORTS_H 00029 #define SVN_SORTS_H 00030 00031 #include <apr.h> /* for apr_ssize_t */ 00032 #include <apr_pools.h> /* for apr_pool_t */ 00033 #include <apr_tables.h> /* for apr_array_header_t */ 00034 #include <apr_hash.h> /* for apr_hash_t */ 00035 00036 /* Define a MAX macro if we don't already have one */ 00037 #ifndef MAX 00038 #define MAX(a, b) ((a) < (b) ? (b) : (a)) 00039 #endif 00040 00041 /* Define a MIN macro if we don't already have one */ 00042 #ifndef MIN 00043 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 00044 #endif 00045 00046 #ifdef __cplusplus 00047 extern "C" { 00048 #endif /* __cplusplus */ 00049 00050 00051 00052 /** This structure is used to hold a key/value from a hash table. 00053 * @note Private. For use by Subversion's own code only. See issue #1644. 00054 */ 00055 typedef struct svn_sort__item_t { 00056 /** pointer to the key */ 00057 const void *key; 00058 00059 /** size of the key */ 00060 apr_ssize_t klen; 00061 00062 /** pointer to the value */ 00063 void *value; 00064 } svn_sort__item_t; 00065 00066 00067 /** Compare two @c svn_sort__item_t's, returning an integer greater than, 00068 * equal to, or less than 0, according to whether the key of @a a is 00069 * greater than, equal to, or less than the key of @a b as determined 00070 * by comparing them with svn_path_compare_paths(). 00071 * 00072 * The key strings must be NULL-terminated, even though klen does not 00073 * include the terminator. 00074 * 00075 * This is useful for converting a hash into a sorted 00076 * @c apr_array_header_t. For example, to convert hash @a hsh to a sorted 00077 * array, do this: 00078 * 00079 * @code 00080 apr_array_header_t *array; 00081 array = svn_sort__hash(hsh, svn_sort_compare_items_as_paths, pool); 00082 @endcode 00083 */ 00084 int 00085 svn_sort_compare_items_as_paths(const svn_sort__item_t *a, 00086 const svn_sort__item_t *b); 00087 00088 00089 /** Compare two @c svn_sort__item_t's, returning an integer greater than, 00090 * equal to, or less than 0, according as @a a is greater than, equal to, 00091 * or less than @a b according to a lexical key comparison. The keys are 00092 * not required to be zero-terminated. 00093 */ 00094 int 00095 svn_sort_compare_items_lexically(const svn_sort__item_t *a, 00096 const svn_sort__item_t *b); 00097 00098 /** Compare two @c svn_revnum_t's, returning an integer greater than, equal 00099 * to, or less than 0, according as @a b is greater than, equal to, or less 00100 * than @a a. Note that this sorts newest revision to oldest (IOW, descending 00101 * order). 00102 * 00103 * This function is compatible for use with qsort(). 00104 * 00105 * This is useful for converting an array of revisions into a sorted 00106 * @c apr_array_header_t. You are responsible for detecting, preventing or 00107 * removing duplicates. 00108 */ 00109 int 00110 svn_sort_compare_revisions(const void *a, 00111 const void *b); 00112 00113 00114 /** 00115 * Compare two @c const char * paths, returning an integer greater 00116 * than, equal to, or less than 0, using the same comparison rules as 00117 * are used by svn_path_compare_paths(). 00118 * 00119 * This function is compatible for use with qsort(). 00120 * 00121 * @since New in 1.1. 00122 */ 00123 int 00124 svn_sort_compare_paths(const void *a, 00125 const void *b); 00126 00127 /** 00128 * Compare two @c svn_merge_range_t *'s, returning an integer greater 00129 * than, equal to, or less than 0 if the first range is greater than, 00130 * equal to, or less than, the second range. 00131 * 00132 * Both @c svn_merge_range_t *'s must describe forward merge ranges. 00133 * 00134 * If @a a and @a b intersect then the range with the lower start revision 00135 * is considered the lesser range. If the ranges' start revisions are 00136 * equal then the range with the lower end revision is considered the 00137 * lesser range. 00138 * 00139 * @since New in 1.5 00140 */ 00141 int 00142 svn_sort_compare_ranges(const void *a, 00143 const void *b); 00144 00145 /** Sort @a ht according to its keys, return an @c apr_array_header_t 00146 * containing @c svn_sort__item_t structures holding those keys and values 00147 * (i.e. for each @c svn_sort__item_t @a item in the returned array, 00148 * @a item->key and @a item->size are the hash key, and @a item->data points to 00149 * the hash value). 00150 * 00151 * Storage is shared with the original hash, not copied. 00152 * 00153 * @a comparison_func should take two @c svn_sort__item_t's and return an 00154 * integer greater than, equal to, or less than 0, according as the first item 00155 * is greater than, equal to, or less than the second. 00156 * 00157 * @note Private. For use by Subversion's own code only. See issue #1644. 00158 * 00159 * @note This function and the @c svn_sort__item_t should go over to APR. 00160 */ 00161 apr_array_header_t * 00162 svn_sort__hash(apr_hash_t *ht, 00163 int (*comparison_func)(const svn_sort__item_t *, 00164 const svn_sort__item_t *), 00165 apr_pool_t *pool); 00166 00167 /* Return the lowest index at which the element *KEY should be inserted into 00168 the array ARRAY, according to the ordering defined by COMPARE_FUNC. 00169 The array must already be sorted in the ordering defined by COMPARE_FUNC. 00170 COMPARE_FUNC is defined as for the C stdlib function bsearch(). */ 00171 int 00172 svn_sort__bsearch_lower_bound(const void *key, 00173 const apr_array_header_t *array, 00174 int (*compare_func)(const void *, const void *)); 00175 00176 /* Insert a shallow copy of *NEW_ELEMENT into the array ARRAY at the index 00177 INSERT_INDEX, growing the array and shuffling existing elements along to 00178 make room. */ 00179 void 00180 svn_sort__array_insert(const void *new_element, 00181 apr_array_header_t *array, 00182 int insert_index); 00183 00184 00185 /* Remove ELEMENTS_TO_DELETE elements starting at DELETE_INDEX from the 00186 array ARR. If DELETE_INDEX is not a valid element of ARR, 00187 ELEMENTS_TO_DELETE is not greater than zero, or 00188 DELETE_INDEX + ELEMENTS_TO_DELETE is greater than ARR->NELTS, then do 00189 nothing. */ 00190 void 00191 svn_sort__array_delete(apr_array_header_t *arr, 00192 int delete_index, 00193 int elements_to_delete); 00194 00195 #ifdef __cplusplus 00196 } 00197 #endif /* __cplusplus */ 00198 00199 #endif /* SVN_SORTS_H */