Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

svn_sorts.h

Go to the documentation of this file.
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 to whether the key of @a a is
00054  * greater than, equal to, or less than the key of @a b as determined
00055  * by comparing them with svn_path_compare_paths().
00056  *
00057  * The key strings must be null-terminated, even though klen does not
00058  * include the terminator.
00059  * 
00060  * This is useful for converting a hash into a sorted
00061  * @c apr_array_header_t.  For example, to convert hash @a hsh to a sorted
00062  * array, do this:
00063  * 
00064  *<pre>   apr_array_header_t *hdr;
00065  *   hdr = svn_sort__hash (hsh, @c svn_sort_compare_items_as_paths, pool);</pre>
00066  */
00067 int svn_sort_compare_items_as_paths(const svn_sort__item_t *a,
00068                                     const svn_sort__item_t *b);
00069 
00070 
00071 /** Compare two @c svn_sort__item_t's, returning an integer greater than,
00072  * equal to, or less than 0, according as @a a is greater than, equal to,
00073  * or less than @a b according to a lexical key comparison.  The keys are
00074  * not required to be zero-terminated.
00075  */
00076 int svn_sort_compare_items_lexically(const svn_sort__item_t *a,
00077                                      const svn_sort__item_t *b);
00078 
00079 /** Compare two @c svn_revnum_t's, returning an integer greater than, equal
00080  * to, or less than 0, according as @a b is greater than, equal to, or less
00081  * than @a a. Note that this sorts newest revision to oldest (IOW, descending
00082  * order).
00083  *
00084  * This function is compatible for use with qsort().
00085  *
00086  * This is useful for converting an array of revisions into a sorted
00087  * @c apr_array_header_t. You are responsible for detecting, preventing or
00088  * removing duplicates.
00089  */
00090 int svn_sort_compare_revisions(const void *a, const void *b);
00091 
00092 
00093 /**
00094  * Compare two @c const char * paths, returning an integer greater
00095  * than, equal to, or less than 0, using the same comparison rules as
00096  * are used by svn_path_compare_paths().
00097  *
00098  * This function is compatible for use with qsort().
00099  *
00100  * @since New in 1.1.
00101  */
00102 int svn_sort_compare_paths(const void *a, const void *b);
00103 
00104 
00105 /** Sort @a ht according to its keys, return an @c apr_array_header_t
00106  * containing @c svn_sort__item_t structures holding those keys and values
00107  * (i.e. for each @c svn_sort__item_t @a item in the returned array,
00108  * @a item->key and @a item->size are the hash key, and @a item->data points to
00109  * the hash value).
00110  *
00111  * Storage is shared with the original hash, not copied.
00112  *
00113  * @a comparison_func should take two @c svn_sort__item_t's and return an
00114  * integer greater than, equal to, or less than 0, according as the first item
00115  * is greater than, equal to, or less than the second.
00116  *
00117  * @note Private. For use by Subversion's own code only. See issue #1644.
00118  *
00119  * @note This function and the @c svn_sort__item_t should go over to APR.
00120  */
00121 apr_array_header_t *
00122 svn_sort__hash(apr_hash_t *ht,
00123                int (*comparison_func)(const svn_sort__item_t *,
00124                                       const svn_sort__item_t *),
00125                apr_pool_t *pool);
00126 
00127 
00128 #ifdef __cplusplus
00129 }
00130 #endif /* __cplusplus */
00131 
00132 #endif /* SVN_SORTS_H */

Generated on Sat Dec 22 05:38:05 2007 for Subversion by  doxygen 1.3.9.1