File include/jlib/darray_mods.h changed (mode: 100644) (index c83cb2c..c5becf2) |
11 |
11 |
namespace jl |
namespace jl |
12 |
12 |
{ |
{ |
13 |
13 |
/** |
/** |
14 |
|
* @brief Dynamic-size array with unordered access to items. |
|
|
14 |
|
* @brief Dynamic-sized array with unordered access to items. |
15 |
15 |
* |
* |
16 |
16 |
* Same as darray, but some functions are optimized, |
* Same as darray, but some functions are optimized, |
17 |
|
* considering that user does not care about position of items in array. |
|
|
17 |
|
* as the position of items in array is not important to user. |
18 |
18 |
* |
* |
19 |
|
* Remove function swaps item with last item in the array, so it cannot be used in the loops. |
|
|
19 |
|
* Remove function swaps item with the last item in the array, so it cannot be used in the loops. |
20 |
20 |
* |
* |
21 |
21 |
* @see darray |
* @see darray |
22 |
22 |
*/ |
*/ |
|
... |
... |
namespace jl |
30 |
30 |
using typename darray::end; |
using typename darray::end; |
31 |
31 |
|
|
32 |
32 |
/** |
/** |
33 |
|
* @brief Call function with item from iterator position, and remove. |
|
|
33 |
|
* @brief Call function with item from iterator position, and remove it. |
34 |
34 |
* |
* |
35 |
|
* Same as darray::remove, but instead of moving items, swap item with last item in the array, |
|
|
35 |
|
* Same as darray::remove, but instead of moving items, swaps an item with the last item in the array, |
36 |
36 |
* so it cannot be used in the loops. |
* so it cannot be used in the loops. |
37 |
37 |
*/ |
*/ |
38 |
38 |
template<typename P_FOO, typename ... Args> |
template<typename P_FOO, typename ... Args> |
|
... |
... |
namespace jl |
45 |
45 |
} |
} |
46 |
46 |
|
|
47 |
47 |
/** |
/** |
48 |
|
* @brief Call function with item by index, and remove. |
|
|
48 |
|
* @brief Call function with item by index, and remove it. |
49 |
49 |
* |
* |
50 |
|
* Same as darray::remove, but instead of moving items, swap item with last item in the array, |
|
|
50 |
|
* Same as darray::remove, but instead of moving items, swaps an item with the last item in the array, |
51 |
51 |
* so it cannot be used in the loops. |
* so it cannot be used in the loops. |
52 |
52 |
*/ |
*/ |
53 |
53 |
template<typename P_FOO, typename ... Args> |
template<typename P_FOO, typename ... Args> |
|
... |
... |
namespace jl { |
63 |
63 |
template<typename T, typename G = grow_policy<>> struct darray_sorted; |
template<typename T, typename G = grow_policy<>> struct darray_sorted; |
64 |
64 |
} |
} |
65 |
65 |
/** |
/** |
66 |
|
* @brief Dynamic-size array with always sorted items. |
|
|
66 |
|
* @brief Dynamic-sized array which always has sorted items. |
67 |
67 |
* |
* |
68 |
|
* Same as darray, but some functions are changed, to keep items sorted. |
|
|
68 |
|
* Same as darray, but some functions are modified, to keep items sorted. |
69 |
69 |
* @see darray |
* @see darray |
70 |
70 |
*/ |
*/ |
71 |
71 |
template<typename T, typename G> |
template<typename T, typename G> |
|
... |
... |
struct jl::darray_sorted : darray<T, G> |
75 |
75 |
using typename darray::item; |
using typename darray::item; |
76 |
76 |
|
|
77 |
77 |
/** |
/** |
78 |
|
* @brief Stole allocation from darray and sort items |
|
|
78 |
|
* @brief Takes allocation from darray and sorts items |
79 |
79 |
* |
* |
80 |
80 |
* Must not be called if darray_sorted already initialized. |
* Must not be called if darray_sorted already initialized. |
81 |
81 |
* |
* |
82 |
|
* @param p_da Pointer to darray, where from allocation |
|
83 |
|
* will be stollen. This darray will be empty after. |
|
|
82 |
|
* @param p_da Pointer to darray, where allocation |
|
83 |
|
* will be taken from. This darray will be empty after. |
84 |
84 |
*/ |
*/ |
85 |
85 |
void sort_darray(darray *p_da) { |
void sort_darray(darray *p_da) { |
86 |
86 |
*this = *p_da; |
*this = *p_da; |
|
... |
... |
struct jl::darray_sorted : darray<T, G> |
100 |
100 |
* @brief Insert single item, copied from value, to the sorted position. |
* @brief Insert single item, copied from value, to the sorted position. |
101 |
101 |
* |
* |
102 |
102 |
* Function will search for suitable position for item by comparing items with value to insert. |
* Function will search for suitable position for item by comparing items with value to insert. |
103 |
|
* All items from found position to the end of the array will be moved by 1 position right, |
|
104 |
|
* to free space for new item. |
|
|
103 |
|
* All items from found position to the end of the array will be moved 1 position right, |
|
104 |
|
* to free up the space for a new item. |
105 |
105 |
* |
* |
106 |
106 |
* T type must have overloaded ">=" operator for T type. |
* T type must have overloaded ">=" operator for T type. |
107 |
107 |
* |
* |
108 |
|
* @param[in] value Item value to be copited to new item in the found position. |
|
|
108 |
|
* @param[in] value Item value to be copied to new item in the found position. |
109 |
109 |
* @return False if reserved count is zero and memory reallocation fails. |
* @return False if reserved count is zero and memory reallocation fails. |
110 |
110 |
* |
* |
111 |
111 |
*/ |
*/ |
|
... |
... |
struct jl::darray_sorted : darray<T, G> |
117 |
117 |
} |
} |
118 |
118 |
|
|
119 |
119 |
/** |
/** |
120 |
|
* @brief Get pointer to item that equal to value_to_search. |
|
|
120 |
|
* @brief Get pointer to an item that equal to value_to_search. |
121 |
121 |
* |
* |
122 |
122 |
* Same function as darray::find, but uses binary search, because array is sorted. |
* Same function as darray::find, but uses binary search, because array is sorted. |
123 |
123 |
* |
* |
|
... |
... |
struct jl::darray_sorted : darray<T, G> |
129 |
129 |
} |
} |
130 |
130 |
|
|
131 |
131 |
/** |
/** |
132 |
|
* @brief Get copy of item that equal to value_to_search. |
|
|
132 |
|
* @brief Get a copy of an item that is equal to value_to_search. |
133 |
133 |
* |
* |
134 |
134 |
* Same function as darray::find, but uses binary search, because array is sorted. |
* Same function as darray::find, but uses binary search, because array is sorted. |
135 |
135 |
* |
* |
|
... |
... |
struct jl::darray_sorted : darray<T, G> |
143 |
143 |
return false; |
return false; |
144 |
144 |
} |
} |
145 |
145 |
|
|
146 |
|
/// @brief Search for item and insert to the sorted position, if not found. |
|
|
146 |
|
/// @brief Search for item and insert it to the sorted position, if search fails. |
147 |
147 |
/// @param p_p_dst Pointer to place pointer to found or inserted value. |
/// @param p_p_dst Pointer to place pointer to found or inserted value. |
148 |
148 |
/// @return bool is value found, if false - value inserted. |
/// @return bool is value found, if false - value inserted. |
149 |
149 |
/// @see darray_sorted::find_or_insert(const T &value, bool *p_is_found) |
/// @see darray_sorted::find_or_insert(const T &value, bool *p_is_found) |
|
... |
... |
struct jl::darray_sorted : darray<T, G> |
156 |
156 |
} |
} |
157 |
157 |
|
|
158 |
158 |
/** |
/** |
159 |
|
* @brief Search for item and insert to the sorted position, if not found. |
|
|
159 |
|
* @brief Search for item and insert it to the sorted position, if search fails. |
160 |
160 |
* |
* |
161 |
161 |
* T type must have overloaded ">=" and ">" operator for T type. |
* T type must have overloaded ">=" and ">" operator for T type. |
162 |
162 |
* |
* |