3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
20 * ====================================================================
24 * @brief all sorts of sorts.
31 #include <apr.h> /* for apr_ssize_t */
32 #include <apr_pools.h> /* for apr_pool_t */
33 #include <apr_tables.h> /* for apr_array_header_t */
34 #include <apr_hash.h> /* for apr_hash_t */
36 /* Define a MAX macro if we don't already have one */
38 #define MAX(a, b) ((a) < (b) ? (b) : (a))
41 /* Define a MIN macro if we don't already have one */
43 #define MIN(a, b) ((a) < (b) ? (a) : (b))
48 #endif /* __cplusplus */
52 /** This structure is used to hold a key/value from a hash table.
53 * @note Private. For use by Subversion's own code only. See issue #1644.
55 typedef struct svn_sort__item_t svn_sort__item_t;
58 /** Compare two @c svn_sort__item_t's, returning an integer greater than,
59 * equal to, or less than 0, according to whether the key of @a a is
60 * greater than, equal to, or less than the key of @a b as determined
61 * by comparing them with svn_path_compare_paths().
63 * The key strings must be NULL-terminated, even though klen does not
64 * include the terminator.
66 * This is useful for converting a hash into a sorted
67 * @c apr_array_header_t. For example, to convert hash @a hsh to a sorted
71 apr_array_header_t *array;
72 array = svn_sort__hash(hsh, svn_sort_compare_items_as_paths, pool);
75 * This function works like svn_sort_compare_items_lexically() except that it
76 * orders children in subdirectories directly after their parents. This allows
77 * using the given ordering for a depth first walk, but at a performance
78 * penalty. Code that doesn't need this special behavior for children, e.g. when
79 * sorting files at a single directory level should use
80 * svn_sort_compare_items_lexically() instead.
83 svn_sort_compare_items_as_paths(const svn_sort__item_t *a,
84 const svn_sort__item_t *b);
87 /** Compare two @c svn_sort__item_t's, returning an integer greater than,
88 * equal to, or less than 0, according as @a a is greater than, equal to,
89 * or less than @a b according to a lexical key comparison. The keys are
90 * not required to be zero-terminated.
93 svn_sort_compare_items_lexically(const svn_sort__item_t *a,
94 const svn_sort__item_t *b);
96 /** Compare two @c svn_revnum_t's, returning an integer greater than, equal
97 * to, or less than 0, according as @a b is greater than, equal to, or less
98 * than @a a. Note that this sorts newest revision to oldest (IOW, descending
101 * This function is compatible for use with qsort().
103 * This is useful for converting an array of revisions into a sorted
104 * @c apr_array_header_t. You are responsible for detecting, preventing or
105 * removing duplicates.
108 svn_sort_compare_revisions(const void *a,
113 * Compare two @c const char * paths, @a *a and @a *b, returning an
114 * integer greater than, equal to, or less than 0, using the same
115 * comparison rules as are used by svn_path_compare_paths().
117 * This function is compatible for use with qsort().
122 svn_sort_compare_paths(const void *a,
126 * Compare two @c svn_merge_range_t *'s, @a *a and @a *b, returning an
127 * integer greater than, equal to, or less than 0 if the first range is
128 * greater than, equal to, or less than, the second range.
130 * Both @c svn_merge_range_t *'s must describe forward merge ranges.
132 * If @a *a and @a *b intersect then the range with the lower start revision
133 * is considered the lesser range. If the ranges' start revisions are
134 * equal then the range with the lower end revision is considered the
140 svn_sort_compare_ranges(const void *a,
145 #endif /* __cplusplus */
147 #endif /* SVN_SORTS_H */