All Projects → seniorbutter → Rapidstring

seniorbutter / Rapidstring

Licence: mit
Maybe the fastest string library ever.

Programming Languages

c
50402 projects - #5 most used programming language
cpp
1120 projects

Labels

Projects that are alternatives of or similar to Rapidstring

Attributedstring
基于Swift插值方式优雅的构建富文本, 支持点击长按事件, 支持不同类型过滤, 支持自定义视图等.
Stars: ✭ 294 (-59.84%)
Mutual labels:  string
React Element To Jsx String
Turn a ReactElement into the corresponding JSX string
Stars: ✭ 349 (-52.32%)
Mutual labels:  string
Typeset
Deal with AttributedString efficiently
Stars: ✭ 458 (-37.43%)
Mutual labels:  string
Coderchef Kitchen
The official repository for our programming kitchen which consists of 50+ delicious programming recipes having all the interesting ingredients ranging from dynamic programming, graph theory, linked lists and much more. All the articles contain beautiful images and some gif/video at times to help clear important concepts.
Stars: ✭ 306 (-58.2%)
Mutual labels:  string
Tiny Utf8
Unicode (UTF-8) capable std::string
Stars: ✭ 322 (-56.01%)
Mutual labels:  string
Ustring
The Hoa\Ustring library.
Stars: ✭ 403 (-44.95%)
Mutual labels:  string
Obfuscate
Guaranteed compile-time string literal obfuscation header-only library for C++14
Stars: ✭ 260 (-64.48%)
Mutual labels:  string
Python String Similarity
A library implementing different string similarity and distance measures using Python.
Stars: ✭ 546 (-25.41%)
Mutual labels:  string
Underscore.string
String manipulation helpers for javascript
Stars: ✭ 3,355 (+358.33%)
Mutual labels:  string
Colorful
Terminal string styling done right, in Python 🐍 🎉
Stars: ✭ 456 (-37.7%)
Mutual labels:  string
Voca
The ultimate JavaScript string library
Stars: ✭ 3,387 (+362.7%)
Mutual labels:  string
Bistring
Bidirectionally transformed strings
Stars: ✭ 326 (-55.46%)
Mutual labels:  string
Portable Utf8
🉑 Portable UTF-8 library - performance optimized (unicode) string functions for php.
Stars: ✭ 405 (-44.67%)
Mutual labels:  string
Multilanguages
Android 多语种适配框架,兼容高版本,适配第三方库语种
Stars: ✭ 299 (-59.15%)
Mutual labels:  string
String
String handling evolved
Stars: ✭ 483 (-34.02%)
Mutual labels:  string
Kind Of
Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
Stars: ✭ 268 (-63.39%)
Mutual labels:  string
Competitive Programming Repository
Competitive Programming templates that I used during the past few years.
Stars: ✭ 367 (-49.86%)
Mutual labels:  string
String
Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way.
Stars: ✭ 709 (-3.14%)
Mutual labels:  string
Android interviews
🚀Everything you need to know to find a android job. 算法 / 面试题 / Android 知识点 🔥🔥🔥 总结不易,你的 star 是我最大的动力!
Stars: ✭ 510 (-30.33%)
Mutual labels:  string
Xorstr
heavily vectorized c++17 compile time string encryption.
Stars: ✭ 435 (-40.57%)
Mutual labels:  string
Linux Build Status Windows Build Status Codacy Badge Coverage Status License

rapidstring

rapidstring is maybe the fastest string library ever written in ANSI C. Here are some of the features:

  • Highly performant. Every aspect of the library was first considered from a performance perspective, and it shows. The current benchmarks outperform the standard string implementations of GCC, Clang, MSVC and ICC by a factor of two or more in most tests.

  • Trivial integration. The entire library consists of a single header file. The code is written in vanilla ANSI C that has been tested on all current compilers. Furthermore, the code is entirely C++ compatible.

  • Minimalist design. Out of the ~1,500 lines of code, only 200 are used to implement the library functions, the rest being documentation. The library has the sole purpose of providing an efficient and reliable string library.

  • Extensive documentation. All functions are thoroughly documented with information on its parameters, the complexity, whether it allocates, when it allocates and more.

  • Configurable. The internal implementation of rapidstring is very open. All internal functions and macros are documented to allow the utmost leeway to the user. Any internal macros such as the allocations functions, the stack capacity, the growth multiplier or the inling settings may be redefined by the user.

  • Rigorous testing. The library has 100% unit test coverage with valgrind memory leak checks. All tests are ran on GCC, Clang and MSVC in the continous integration builds to ensure the library is always up to par.

Why maybe?

All of the current benchmarks in this repository outperform the standard string implementations typically by a factor of two or more. However, these implementations are subject to change at any moment, the benchmarks may be inaccurate, certain factors might not be considered, etc.

If you believe a benchmark is incorrect or misleading, by all means I encourage you to create an issue/pull request. I am continuously striving to improve rapidstring's performance and I will do my best to ensure the benchmarks accurately represent its efficiency as a library.

Examples

All strings must be freed with rs_free(). This was excluded from the examples for brevity.

Construction

rapidstring s1, s2, s3, s4;

/* Empty string. */
rs_init(&s1);

/* Initialize with a value. */
rs_init_w(&s2, "Hello World!");

/* Specify the length to speed it up. */
rs_init_w_n(&s3, "Hello World!", 12);

/* Initialize with another string. */
rs_init_w_rs(&s4, &s3);

puts(rs_data(&s4)); /* Hello World! */
printf("%zu", rs_len(&s4)); /* 12 */

A common pattern in this library is the use of the _n suffix. This specifies that the function takes the size of the const char* provided, which avoids an unnecessary call to strlen(). As for the _w suffix, this simply means "with".

Assignment

rapidstring s1, s2;
rs_init(&s1);
rs_init(&s2);

rs_cpy(&s1, "Blimey!");

puts(rs_data(&s1)); /* Blimey! */

rs_cpy_n(&s1, "Jiminy Cricket!", 15);
rs_cpy_rs(&s2, &s1);

puts(rs_data(&s2)); /* Jiminy Cricket! */

It is important to note that all strings must be initialized before any functions such as rs_cpy() are called. Failing to do so will result in undefined behavior (or assertion failures when NDEBUG is not defined).

Concatenation

rapidstring s1, s2;
rs_init(&s1);
rs_init(&s2);

rs_cat(&s1, "Hello ");
rs_cat_n(&s2, "World!", 6);
rs_cat_rs(&s1, &s2);

puts(rs_data(&s1)); /* Hello World! */

It is unnecessary to call rs_free() if you are sure the string length will always remain under RS_STACK_CAPACITY. This macro may be redefined to suit your application's needs.

Resizing

rapidstring s;
rs_init_w(&s, "long $MU");

printf("%zu", rs_len(&s)); /* 8 */

/* Resize with 'a' as a filler character. */
rs_resize_w(&s, 15, 'a');

printf("%zu", rs_len(&s)); /* 15 */
puts(rs_data(&s)); /* long $MUaaaaaaa */

If you wish to resize a string without a filler character, you may do so with rs_resize which is considerably faster but it leaves garbage in the place of the new characters.

Capacity

rapidstring s;
rs_init_w_cap(&s, 100);

printf("%zu", rs_cap(&s)); /* 100 */
printf("%zu", rs_len(&s)); /* 0 */
printf("%zu", rs_is_heap(&s)); /* 1 */

rs_shrink_to_fit(&s);
printf("%zu", rs_cap(&s)); /* 0 */

rs_reserve(&s, 50);
printf("%zu", rs_cap(&s)); /* 50 */

In order to allow the string's capacity to grow at a faster rate, the macro RS_GROWTH_FACTOR may be redefined. The default is 2, meaning the capacity is doubled every time the string runs out of space.

Erasing

rapidstring s;
rs_init_w(&s, "Blasphemy!");

rs_erase(&s, 0, 2);
puts(rs_data(&s)); /* asphemy! */

rs_clear(&s);
printf("%zu", rs_len(&s)); /* 0 */

Erasing from the first element with the length of the string is identicle to calling rs_clear(), but the latter is marginally faster.

Build

To build the project, the following must be run:

git clone --recurse-submodules https://github.com/boyerjohn/rapidstring
cd rapidstring
mkdir build
cd build
cmake .. -DBUILD_TESTING=1
cmake --build .

The build will default to debug mode. To compile in release mode, pass this flag -DCMAKE_BUILD_TYPE=Release to the cmake generation command. The test and benchmark executables will be in their respective folders.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].