Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
strings.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/sort/strings.hpp
3  *
4  * Front-end for string sorting algorithms.
5  *
6  * Part of tlx - http://panthema.net/tlx
7  *
8  * Copyright (C) 2018 Timo Bingmann <[email protected]>
9  *
10  * All rights reserved. Published under the Boost Software License, Version 1.0
11  ******************************************************************************/
12 
13 #ifndef TLX_SORT_STRINGS_HEADER
14 #define TLX_SORT_STRINGS_HEADER
15 
16 #include <tlx/sort/strings.hpp>
20 
21 #include <cstdint>
22 #include <string>
23 #include <vector>
24 
25 namespace tlx {
26 
27 //! \addtogroup tlx_sort
28 //! \{
29 //! \name String Sorting Algorithms
30 //! \{
31 
32 /******************************************************************************/
33 
34 /*!
35  * Sort a set of strings represented by C-style uint8_t* in place.
36  *
37  * If the memory limit is non zero, possibly slower algorithms will be selected
38  * to stay within the memory limit.
39  */
40 static inline
41 void sort_strings(unsigned char** strings, size_t size, size_t memory = 0) {
44  sort_strings_detail::UCharStringSet(strings, strings + size)),
45  /* depth */ 0, memory);
46 }
47 
48 /*!
49  * Sort a set of strings represented by C-style char* in place.
50  *
51  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
52  * If the memory limit is non zero, possibly slower algorithms will be selected
53  * to stay within the memory limit.
54  */
55 static inline
56 void sort_strings(char** strings, size_t size, size_t memory = 0) {
57  return sort_strings(
58  reinterpret_cast<unsigned char**>(strings), size, memory);
59 }
60 
61 /*!
62  * Sort a set of strings represented by C-style uint8_t* in place.
63  *
64  * If the memory limit is non zero, possibly slower algorithms will be selected
65  * to stay within the memory limit.
66  */
67 static inline
68 void sort_strings(const unsigned char** strings, size_t size,
69  size_t memory = 0) {
72  sort_strings_detail::CUCharStringSet(strings, strings + size)),
73  /* depth */ 0, memory);
74 }
75 
76 /*!
77  * Sort a set of strings represented by C-style char* in place.
78  *
79  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
80  * If the memory limit is non zero, possibly slower algorithms will be selected
81  * to stay within the memory limit.
82  */
83 static inline
84 void sort_strings(const char** strings, size_t size, size_t memory = 0) {
85  return sort_strings(
86  reinterpret_cast<const unsigned char**>(strings), size, memory);
87 }
88 
89 /******************************************************************************/
90 
91 /*!
92  * Sort a set of strings represented by C-style char* in place.
93  *
94  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
95  * If the memory limit is non zero, possibly slower algorithms will be selected
96  * to stay within the memory limit.
97  */
98 static inline
99 void sort_strings(std::vector<char*>& strings, size_t memory = 0) {
100  return sort_strings(strings.data(), strings.size(), memory);
101 }
102 
103 /*!
104  * Sort a set of strings represented by C-style uint8_t* in place.
105  *
106  * If the memory limit is non zero, possibly slower algorithms will be selected
107  * to stay within the memory limit.
108  */
109 static inline
110 void sort_strings(std::vector<unsigned char*>& strings, size_t memory = 0) {
111  return sort_strings(strings.data(), strings.size(), memory);
112 }
113 
114 /*!
115  * Sort a set of strings represented by C-style char* in place.
116  *
117  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
118  * If the memory limit is non zero, possibly slower algorithms will be selected
119  * to stay within the memory limit.
120  */
121 static inline
122 void sort_strings(std::vector<const char*>& strings, size_t memory = 0) {
123  return sort_strings(strings.data(), strings.size(), memory);
124 }
125 
126 /*!
127  * Sort a set of strings represented by C-style uint8_t* in place.
128  *
129  * If the memory limit is non zero, possibly slower algorithms will be selected
130  * to stay within the memory limit.
131  */
132 static inline
133 void sort_strings(std::vector<const unsigned char*>& strings,
134  size_t memory = 0) {
135  return sort_strings(strings.data(), strings.size(), memory);
136 }
137 
138 /******************************************************************************/
139 
140 /*!
141  * Sort a set of std::strings in place.
142  *
143  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
144  * If the memory limit is non zero, possibly slower algorithms will be selected
145  * to stay within the memory limit.
146  */
147 static inline
148 void sort_strings(std::string* strings, size_t size, size_t memory = 0) {
151  sort_strings_detail::StdStringSet(strings, strings + size)),
152  /* depth */ 0, memory);
153 }
154 
155 /*!
156  * Sort a vector of std::strings in place.
157  *
158  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
159  * If the memory limit is non zero, possibly slower algorithms will be selected
160  * to stay within the memory limit.
161  */
162 static inline
163 void sort_strings(std::vector<std::string>& strings, size_t memory = 0) {
164  return sort_strings(strings.data(), strings.size(), memory);
165 }
166 
167 /******************************************************************************/
168 /******************************************************************************/
169 /******************************************************************************/
170 
171 /*!
172  * Sort a set of strings represented by C-style uint8_t* in place.
173  *
174  * If the memory limit is non zero, possibly slower algorithms will be selected
175  * to stay within the memory limit.
176  */
177 static inline
178 void sort_strings_lcp(unsigned char** strings, size_t size, uint32_t* lcp,
179  size_t memory = 0) {
183  sort_strings_detail::UCharStringSet(strings, strings + size), lcp),
184  /* depth */ 0, memory);
185 }
186 
187 /*!
188  * Sort a set of strings represented by C-style char* in place.
189  *
190  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
191  * If the memory limit is non zero, possibly slower algorithms will be selected
192  * to stay within the memory limit.
193  */
194 static inline
195 void sort_strings_lcp(char** strings, size_t size, uint32_t* lcp,
196  size_t memory = 0) {
197  return sort_strings_lcp(
198  reinterpret_cast<unsigned char**>(strings), size, lcp, memory);
199 }
200 
201 /*!
202  * Sort a set of strings represented by C-style uint8_t* in place.
203  *
204  * If the memory limit is non zero, possibly slower algorithms will be selected
205  * to stay within the memory limit.
206  */
207 static inline
208 void sort_strings_lcp(const unsigned char** strings, size_t size, uint32_t* lcp,
209  size_t memory = 0) {
213  sort_strings_detail::CUCharStringSet(strings, strings + size), lcp),
214  /* depth */ 0, memory);
215 }
216 
217 /*!
218  * Sort a set of strings represented by C-style char* in place.
219  *
220  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
221  * If the memory limit is non zero, possibly slower algorithms will be selected
222  * to stay within the memory limit.
223  */
224 static inline
225 void sort_strings_lcp(const char** strings, size_t size, uint32_t* lcp,
226  size_t memory = 0) {
227  return sort_strings_lcp(
228  reinterpret_cast<const unsigned char**>(strings), size, lcp, memory);
229 }
230 
231 /******************************************************************************/
232 
233 /*!
234  * Sort a set of strings represented by C-style char* in place.
235  *
236  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
237  * If the memory limit is non zero, possibly slower algorithms will be selected
238  * to stay within the memory limit.
239  */
240 static inline
241 void sort_strings_lcp(std::vector<char*>& strings, uint32_t* lcp,
242  size_t memory = 0) {
243  return sort_strings_lcp(strings.data(), strings.size(), lcp, memory);
244 }
245 
246 /*!
247  * Sort a set of strings represented by C-style uint8_t* in place.
248  *
249  * If the memory limit is non zero, possibly slower algorithms will be selected
250  * to stay within the memory limit.
251  */
252 static inline
253 void sort_strings_lcp(std::vector<unsigned char*>& strings, uint32_t* lcp,
254  size_t memory = 0) {
255  return sort_strings_lcp(strings.data(), strings.size(), lcp, memory);
256 }
257 
258 /*!
259  * Sort a set of strings represented by C-style char* in place.
260  *
261  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
262  * If the memory limit is non zero, possibly slower algorithms will be selected
263  * to stay within the memory limit.
264  */
265 static inline
266 void sort_strings_lcp(std::vector<const char*>& strings, uint32_t* lcp,
267  size_t memory = 0) {
268  return sort_strings_lcp(strings.data(), strings.size(), lcp, memory);
269 }
270 
271 /*!
272  * Sort a set of strings represented by C-style uint8_t* in place.
273  *
274  * If the memory limit is non zero, possibly slower algorithms will be selected
275  * to stay within the memory limit.
276  */
277 static inline
278 void sort_strings_lcp(std::vector<const unsigned char*>& strings, uint32_t* lcp,
279  size_t memory = 0) {
280  return sort_strings_lcp(strings.data(), strings.size(), lcp, memory);
281 }
282 
283 /******************************************************************************/
284 
285 /*!
286  * Sort a set of std::strings in place.
287  *
288  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
289  * If the memory limit is non zero, possibly slower algorithms will be selected
290  * to stay within the memory limit.
291  */
292 static inline
293 void sort_strings_lcp(std::string* strings, size_t size, uint32_t* lcp,
294  size_t memory = 0) {
298  sort_strings_detail::StdStringSet(strings, strings + size), lcp),
299  /* depth */ 0, memory);
300 }
301 
302 /*!
303  * Sort a vector of std::strings in place.
304  *
305  * The strings are sorted as _unsigned_ 8-bit characters, not signed characters!
306  * If the memory limit is non zero, possibly slower algorithms will be selected
307  * to stay within the memory limit.
308  */
309 static inline
310 void sort_strings_lcp(std::vector<std::string>& strings, uint32_t* lcp,
311  size_t memory = 0) {
312  return sort_strings_lcp(strings.data(), strings.size(), lcp, memory);
313 }
314 
315 /******************************************************************************/
316 
317 //! \}
318 //! \}
319 
320 } // namespace tlx
321 
322 #endif // !TLX_SORT_STRINGS_HEADER
323 
324 /******************************************************************************/
static void sort_strings(unsigned char **strings, size_t size, size_t memory=0)
Sort a set of strings represented by C-style uint8_t* in place.
Definition: strings.hpp:41
Class implementing StringSet concept for char* and unsigned char* strings.
Definition: string_set.hpp:204
Class implementing StringSet concept for arrays of std::string objects.
Definition: string_set.hpp:301
static void radixsort_CE3(const StringPtr &strptr, size_t depth, size_t memory)
Definition: radix_sort.hpp:502
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
Objectified string and LCP array pointer arrays.
Definition: string_ptr.hpp:93
static void sort_strings_lcp(unsigned char **strings, size_t size, uint32_t *lcp, size_t memory=0)
Sort a set of strings represented by C-style uint8_t* in place.
Definition: strings.hpp:178
Objectified string array pointer array.
Definition: string_ptr.hpp:47