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 * ====================================================================
23 * @file svn_sorts_private.h
24 * @brief all sorts of sorts.
28 #ifndef SVN_SORTS_PRIVATE_H
29 #define SVN_SORTS_PRIVATE_H
31 #include "../svn_sorts.h"
35 #endif /* __cplusplus */
39 /** This structure is used to hold a key/value from a hash table.
40 * @note Private. For use by Subversion's own code only. See issue #1644.
42 struct svn_sort__item_t {
43 /** pointer to the key */
46 /** size of the key */
49 /** pointer to the value */
53 /** Sort @a ht according to its keys, return an @c apr_array_header_t
54 * containing @c svn_sort__item_t structures holding those keys and values
55 * (i.e. for each @c svn_sort__item_t @a item in the returned array,
56 * @a item->key and @a item->size are the hash key, and @a item->value points to
59 * Storage is shared with the original hash, not copied.
61 * @a comparison_func should take two @c svn_sort__item_t's and return an
62 * integer greater than, equal to, or less than 0, according as the first item
63 * is greater than, equal to, or less than the second.
65 * @note Private. For use by Subversion's own code only. See issue #1644.
67 * @note This function and the @c svn_sort__item_t should go over to APR.
70 svn_sort__hash(apr_hash_t *ht,
71 int (*comparison_func)(const svn_sort__item_t *,
72 const svn_sort__item_t *),
75 /* Sort APR array @a array using ordering defined by @a comparison_func.
76 * @a comparison_func is defined as for the C stdlib function qsort().
79 svn_sort__array(apr_array_header_t *array,
80 int (*comparison_func)(const void *,
83 /* Return the lowest index at which the element @a *key should be inserted into
84 * the array @a array, according to the ordering defined by @a compare_func.
85 * The array must already be sorted in the ordering defined by @a compare_func.
86 * @a compare_func is defined as for the C stdlib function bsearch(); the
87 * @a key will always passed to it as the second parameter.
89 * @note Private. For use by Subversion's own code only.
92 svn_sort__bsearch_lower_bound(const apr_array_header_t *array,
94 int (*compare_func)(const void *, const void *));
96 /* Find the lowest index at which the element @a *key should be inserted into
97 * the array @a array, according to the ordering defined by @a compare_func.
98 * The array must already be sorted in the ordering defined by @a compare_func.
99 * @a compare_func is defined as for the C stdlib function bsearch(); the
100 * @a key will always passed to it as the second parameter.
102 * Returns a reference to the array element at the insertion location if
103 * that matches @a key and return NULL otherwise. If you call this function
104 * multiple times for the same array and expect the results to often be
105 * consecutive array elements, provide @a hint. It should be initialized
106 * with -1 for the first call and receives the array index if the returned
107 * element. If the return value is NULL, @a *hint is the location where
108 * the respective key would be inserted.
110 * @note Private. For use by Subversion's own code only.
113 svn_sort__array_lookup(const apr_array_header_t *array,
116 int (*compare_func)(const void *, const void *));
119 /* Insert a shallow copy of @a *new_element into the array @a array at the index
120 * @a insert_index, growing the array and shuffling existing elements along to
123 * @note Private. For use by Subversion's own code only.
126 svn_sort__array_insert(apr_array_header_t *array,
127 const void *new_element,
131 /* Remove @a elements_to_delete elements starting at @a delete_index from the
132 * array @a arr. If @a delete_index is not a valid element of @a arr,
133 * @a elements_to_delete is not greater than zero, or
134 * @a delete_index + @a elements_to_delete is greater than @a arr->nelts,
137 * @note Private. For use by Subversion's own code only.
140 svn_sort__array_delete(apr_array_header_t *arr,
142 int elements_to_delete);
144 /* Reverse the order of elements in @a array, in place.
146 * @note Private. For use by Subversion's own code only.
149 svn_sort__array_reverse(apr_array_header_t *array,
150 apr_pool_t *scratch_pool);
154 * @defgroup svn_priority_queue__t Priority Queues
159 * We implement priority queues on top of existing ELEMENTS arrays. They
160 * provide us with memory management and very basic element type information.
162 * The extraction order is being defined by a comparison function similar
163 * to the ones used with qsort. The first element in the queue is always
164 * on with COMPARISON_FUNC(first,element) <= 0, for all elements in the
169 * Opaque data type for priority queues.
171 typedef struct svn_priority_queue__t svn_priority_queue__t;
174 * Return a priority queue containing all provided @a elements and prioritize
175 * them according to @a compare_func.
177 * @note The priority queue will use the existing @a elements array for data
178 * storage. So, you must not manipulate that array while using the queue.
179 * Also, the lifetime of the queue is bound to that of the array.
181 svn_priority_queue__t *
182 svn_priority_queue__create(apr_array_header_t *elements,
183 int (*compare_func)(const void *, const void *));
186 * Returns the number of elements in the @a queue.
189 svn_priority_queue__size(svn_priority_queue__t *queue);
192 * Returns a reference to the first element in the @a queue. The queue
193 * contents remains unchanged. If the @a queue is empty, #NULL will be
197 svn_priority_queue__peek(svn_priority_queue__t *queue);
200 * Notify the @a queue after modifying the first item as returned by
201 * #svn_priority_queue__peek.
204 svn_priority_queue__update(svn_priority_queue__t *queue);
207 * Remove the first element from the @a queue. This is a no-op for empty
211 svn_priority_queue__pop(svn_priority_queue__t *queue);
214 * Append the new @a element to the @a queue. @a element must neither be
215 * #NULL nor the first element as returned by #svn_priority_queue__peek.
218 svn_priority_queue__push(svn_priority_queue__t *queue, const void *element);
225 #endif /* __cplusplus */
227 #endif /* SVN_SORTS_PRIVATE_H */