3 * ====================================================================
4 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
19 * @brief all sorts of sorts.
26 #include <apr_pools.h>
27 #include <apr_tables.h> /* for apr_array_header_t */
30 /* Define a MAX macro if we don't already have one */
32 #define MAX(a, b) ((a) < (b) ? (b) : (a))
35 /* Define a MIN macro if we don't already have one */
37 #define MIN(a, b) ((a) < (b) ? (a) : (b))
42 #endif /* __cplusplus */
46 /** This structure is used to hold a key/value from a hash table.
47 * @note Private. For use by Subversion's own code only. See issue #1644.
49 typedef struct svn_sort__item_t
{
50 /** pointer to the key */
53 /** size of the key */
56 /** pointer to the value */
61 /** Compare two @c svn_sort__item_t's, returning an integer greater than,
62 * equal to, or less than 0, according to whether the key of @a a is
63 * greater than, equal to, or less than the key of @a b as determined
64 * by comparing them with svn_path_compare_paths().
66 * The key strings must be NULL-terminated, even though klen does not
67 * include the terminator.
69 * This is useful for converting a hash into a sorted
70 * @c apr_array_header_t. For example, to convert hash @a hsh to a sorted
74 apr_array_header_t *hdr;
75 hdr = svn_sort__hash (hsh, @c svn_sort_compare_items_as_paths, pool);
78 int svn_sort_compare_items_as_paths(const svn_sort__item_t
*a
,
79 const svn_sort__item_t
*b
);
82 /** Compare two @c svn_sort__item_t's, returning an integer greater than,
83 * equal to, or less than 0, according as @a a is greater than, equal to,
84 * or less than @a b according to a lexical key comparison. The keys are
85 * not required to be zero-terminated.
87 int svn_sort_compare_items_lexically(const svn_sort__item_t
*a
,
88 const svn_sort__item_t
*b
);
90 /** Compare two @c svn_revnum_t's, returning an integer greater than, equal
91 * to, or less than 0, according as @a b is greater than, equal to, or less
92 * than @a a. Note that this sorts newest revision to oldest (IOW, descending
95 * This function is compatible for use with qsort().
97 * This is useful for converting an array of revisions into a sorted
98 * @c apr_array_header_t. You are responsible for detecting, preventing or
99 * removing duplicates.
101 int svn_sort_compare_revisions(const void *a
, const void *b
);
105 * Compare two @c const char * paths, returning an integer greater
106 * than, equal to, or less than 0, using the same comparison rules as
107 * are used by svn_path_compare_paths().
109 * This function is compatible for use with qsort().
113 int svn_sort_compare_paths(const void *a
, const void *b
);
116 * Compare two @c svn_merge_range_t *'s, returning an integer greater
117 * than, equal to, or less than 0 if the first range is greater than,
118 * equal to, or less than, the second range.
121 int svn_sort_compare_ranges(const void *a
, const void *b
);
123 /** Sort @a ht according to its keys, return an @c apr_array_header_t
124 * containing @c svn_sort__item_t structures holding those keys and values
125 * (i.e. for each @c svn_sort__item_t @a item in the returned array,
126 * @a item->key and @a item->size are the hash key, and @a item->data points to
129 * Storage is shared with the original hash, not copied.
131 * @a comparison_func should take two @c svn_sort__item_t's and return an
132 * integer greater than, equal to, or less than 0, according as the first item
133 * is greater than, equal to, or less than the second.
135 * @note Private. For use by Subversion's own code only. See issue #1644.
137 * @note This function and the @c svn_sort__item_t should go over to APR.
140 svn_sort__hash(apr_hash_t
*ht
,
141 int (*comparison_func
)(const svn_sort__item_t
*,
142 const svn_sort__item_t
*),
148 #endif /* __cplusplus */
150 #endif /* SVN_SORTS_H */