diff options
| -rw-r--r-- | benchmarks/plotbench/plot.py | 48 | ||||
| -rw-r--r-- | docs/cstr_api.md | 60 | ||||
| -rw-r--r-- | docs/csview_api.md | 23 | ||||
| -rw-r--r-- | include/stc/csview.h | 2 |
4 files changed, 65 insertions, 68 deletions
diff --git a/benchmarks/plotbench/plot.py b/benchmarks/plotbench/plot.py index ea3871f4..fa538285 100644 --- a/benchmarks/plotbench/plot.py +++ b/benchmarks/plotbench/plot.py @@ -1,24 +1,24 @@ -import sys
-import seaborn as sns
-import pandas as pd
-import matplotlib.pyplot as plt
-#sns.set_theme(style="whitegrid")
-
-comp = ['All compilers', 'Mingw-g++-10.30', 'Win-Clang-12', 'VC-19.28']
-n = int(sys.argv[1]) if len(sys.argv) > 1 else 0
-file = sys.argv[2] if len(sys.argv) > 2 else 'plot_win.csv'
-df = pd.read_csv(file)
-df = df[df.Method != 'total']
-if n > 0:
- df = df[df.Compiler == comp[n]]
-
-g = sns.catplot(data=df, x='Method', y='Seconds', hue='Library', col='C', kind='bar',
- ci=68, legend=False, col_wrap=2, sharex=False, aspect=1.4, height=3.1)
-g.set_xlabels('')
-
-g.add_legend(bbox_to_anchor=(0.75, 0.2), borderaxespad=0.)
-
-g.fig.subplots_adjust(top=0.90, left=0.06, bottom=0.07)
-g.fig.suptitle('Benchmark STC vs c++ std containers: %s' % comp[n], fontsize=15, y=0.98)
-
-plt.show()
+import sys +import seaborn as sns +import pandas as pd +import matplotlib.pyplot as plt +#sns.set_theme(style="whitegrid") + +comp = ['All compilers', 'Mingw-g++-10.30', 'Win-Clang-12', 'VC-19.28'] +n = int(sys.argv[1]) if len(sys.argv) > 1 else 0 +file = sys.argv[2] if len(sys.argv) > 2 else 'plot_win.csv' +df = pd.read_csv(file) +df = df[df.Method != 'total'] +if n > 0: + df = df[df.Compiler == comp[n]] + +g = sns.catplot(data=df, x='Method', y='Seconds', hue='Library', col='C', kind='bar', + ci=68, legend=False, col_wrap=2, sharex=False, aspect=1.4, height=3.1) +g.set_xlabels('') + +g.add_legend(bbox_to_anchor=(0.75, 0.2), borderaxespad=0.) + +g.fig.subplots_adjust(top=0.90, left=0.06, bottom=0.07) +g.fig.suptitle('Benchmark STC vs c++ std containers: %s' % comp[n], fontsize=15, y=0.98) + +plt.show() diff --git a/docs/cstr_api.md b/docs/cstr_api.md index 09ca6592..0991a8c4 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -12,11 +12,11 @@ See the c++ class [std::basic_string](https://en.cppreference.com/w/cpp/string/b All cstr definitions and prototypes are available by including a single header file. ```c -#define i_implement // define this (or use global STC_IMPLEMENT) in one source file only! +#define i_implement // optional: define in one source file only for shared symbols linking! #include <stc/cstr.h> ``` -## Methods +## Methods ```c cstr cstr_init(void); // constructor; same as cstr_null. cstr cstr_new(const char literal_only[]); // cstr from literal; no strlen() call. @@ -41,23 +41,6 @@ size_t cstr_length(cstr s); size_t cstr_capacity(cstr s); bool cstr_empty(cstr s); -// utf8 encoded strings: -size_t cstr_size_u8(cstr s); // number of utf8 codepoints -size_t cstr_size_n_u8(cstr s, size_t nbytes); // utf8 size within n bytes -csview cstr_at(const cstr* self, size_t bytepos); // utf8 codepoints as a csview -csview cstr_at_u8(const cstr* self, size_t u8idx); // utf8 codepoints at utf8 pos -size_t cstr_pos_u8(const cstr* self, size_t u8idx); // byte position at utf8 index -// utf8 functions requires linking with src/utf8code.c: -bool cstr_valid_u8(const cstr* self); // check if str is valid utf8 -cstr cstr_tolower(const cstr* self); // returns new lowercase utf8 cstr -cstr cstr_toupper(const cstr* self); // returns new uppercase utf8 cstr -void cstr_lowercase(cstr* self); // transform cstr to lowercase utf8 -void cstr_uppercase(cstr* self); // transform cstr to uppercase utf8 -bool cstr_iequals(cstr s, const char* str); // utf8 case-insensitive comparison -bool cstr_istarts_with(cstr s, const char* str); // " -bool cstr_iends_with(cstr s, const char* str); // " -int cstr_icmp(const cstr* s1, const cstr* s2); // " - size_t cstr_reserve(cstr* self, size_t capacity); void cstr_resize(cstr* self, size_t len, char fill); void cstr_shrink_to_fit(cstr* self); @@ -78,15 +61,15 @@ void cstr_insert(cstr* self, size_t pos, const char* ins); void cstr_insert_s(cstr* self, size_t pos, cstr ins); void cstr_insert_n(cstr* self, size_t pos, const char* ins, size_t n); -void cstr_replace_all(cstr* self, const char* search, const char* repl); +void cstr_erase(cstr* self, size_t pos); +void cstr_erase_n(cstr* self, size_t pos, size_t n); + size_t cstr_replace(cstr* self, const char* search, const char* repl); size_t cstr_replace_from(cstr* self, size_t pos, const char* search, const char* repl); void cstr_replace_at(cstr* self, size_t pos, size_t len, const char* repl); void cstr_replace_s(cstr* self, size_t pos, size_t len, cstr repl); void cstr_replace_n(cstr* self, size_t pos, size_t len, const char* repl, size_t n); - -void cstr_erase(cstr* self, size_t pos); -void cstr_erase_n(cstr* self, size_t pos, size_t n); +void cstr_replace_all(cstr* self, const char* search, const char* repl); bool cstr_equals(cstr s, const char* str); bool cstr_equals_s(cstr s, cstr s2); @@ -96,25 +79,44 @@ bool cstr_contains(cstr s, const char* search); bool cstr_starts_with(cstr s, const char* str); bool cstr_ends_with(cstr s, const char* str); -void cstr_push_back(cstr* self, char ch); -void cstr_pop_back(cstr* self); -char* cstr_front(cstr* self); -char* cstr_back(cstr* self); - bool cstr_getline(cstr *self, FILE *stream); // cstr_getdelim(self, '\n', stream) bool cstr_getdelim(cstr *self, int delim, FILE *stream); // does not append delim to result ``` +#### UTF8 methods +``` +size_t cstr_size_u8(cstr s); // number of utf8 codepoints +size_t cstr_size_n_u8(cstr s, size_t nbytes); // utf8 size within n bytes +csview cstr_at(const cstr* self, size_t bytepos); // utf8 codepoints as a csview +csview cstr_at_u8(const cstr* self, size_t u8idx); // utf8 codepoints at utf8 pos +size_t cstr_pos_u8(const cstr* self, size_t u8idx); // byte position at utf8 index + +// iterate utf8 codepoints +cstr_iter cstr_begin(const cstr* self); +cstr_iter cstr_end(const cstr* self); +void cstr_next(cstr_iter* it); + +// utf8 functions requires linking with src/utf8code.c symbols: +bool cstr_valid_u8(const cstr* self); // check if str is valid utf8 +cstr cstr_tolower(const cstr* self); // returns new lowercase utf8 cstr +cstr cstr_toupper(const cstr* self); // returns new uppercase utf8 cstr +void cstr_lowercase(cstr* self); // transform cstr to lowercase utf8 +void cstr_uppercase(cstr* self); // transform cstr to uppercase utf8 +bool cstr_iequals(cstr s, const char* str); // utf8 case-insensitive comparison +bool cstr_istarts_with(cstr s, const char* str); // " +bool cstr_iends_with(cstr s, const char* str); // " +``` + Note that all methods with arguments `(..., const char* str, size_t n)`, `n` must be within the range of `str` length. #### Helper methods: ```c int cstr_cmp(const cstr *s1, const cstr *s2); +int cstr_icmp(const cstr* s1, const cstr* s2); // utf8 case-insensitive comparison bool cstr_eq(const cstr *s1, const cstr *s2); bool cstr_hash(const cstr *s); char* c_strnstrn(const char* str, const char* search, size_t slen, size_t nlen); -int c_strncasecmp(const char* str1, const char* str2, size_t n); ``` ## Types diff --git a/docs/csview_api.md b/docs/csview_api.md index e95737b1..f6984f84 100644 --- a/docs/csview_api.md +++ b/docs/csview_api.md @@ -31,19 +31,11 @@ csview csview_new(const char literal_only[]); // make csvi csview csview_from_s(const cstr* s); // convert to csview from cstr csview csview_from(const char* str); // make csview from const char* csview csview_from_n(const char* str, size_t n); // construct +void csview_clear(csview* self); size_t csview_size(csview sv); size_t csview_length(csview sv); bool csview_empty(csview sv); -char csview_front(csview sv); -char csview_back(csview sv); - -void csview_clear(csview* self); - -// requires i_implement defined before one include of csview.h -csview csview_substr_ex(csview sv, intptr_t pos, size_t n); // negative pos count from end -csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2); // negative p1, p2 count from end -csview csview_token(csview sv, csview sep, size_t* start); // see split example below. bool csview_equals(csview sv, csview sv2); size_t csview_find(csview sv, csview needle); @@ -51,9 +43,10 @@ bool csview_contains(csview sv, csview needle); bool csview_starts_with(csview sv, csview sub); bool csview_ends_with(csview sv, csview sub); -csview_iter csview_begin(const csview* self); -csview_iter csview_end(const csview* self); -void csview_next(csview_iter* it); // NB: UTF8 codepoint step, not byte! +// requires i_implement defined before one include of csview.h +csview csview_substr_ex(csview sv, intptr_t pos, size_t n); // negative pos count from end +csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2); // negative p1, p2 count from end +csview csview_token(csview sv, csview sep, size_t* start); // see split example below. ``` #### UTF8 methods @@ -61,7 +54,11 @@ void csview_next(csview_iter* it); // NB: UTF8 size_t csview_size_u8(csview sv); csview csview_substr_u8(csview sv, size_t u8pos, size_t u8len); -// require linking with src/utf8code.c: +csview_iter csview_begin(const csview* self); +csview_iter csview_end(const csview* self); +void csview_next(csview_iter* it); // utf8 codepoint step, not byte! + +// requires linking with src/utf8code.c: bool csview_valid_u8(csview sv); int csview_icmp(const csview* x, const csview* y); diff --git a/include/stc/csview.h b/include/stc/csview.h index e55e547b..6cfd6e82 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -45,8 +45,6 @@ STC_INLINE void csview_clear(csview* self) { *self = csview_null; } STC_INLINE size_t csview_size(csview sv) { return sv.size; } STC_INLINE size_t csview_length(csview sv) { return sv.size; } STC_INLINE bool csview_empty(csview sv) { return sv.size == 0; } -STC_INLINE char csview_front(csview sv) { return sv.str[0]; } -STC_INLINE char csview_back(csview sv) { return sv.str[sv.size - 1]; } STC_INLINE bool csview_equals(csview sv, csview sv2) { return sv.size == sv2.size && !memcmp(sv.str, sv2.str, sv.size); } |
