ad-oliviero / uwufetch

A meme system info tool for Linux, based on nyan/uwu trend on r/linuxmasterrace.
GNU General Public License v3.0
731 stars 47 forks source link

[OPTIMIZE] Add AC trie data structure #239

Closed i80287 closed 9 months ago

i80287 commented 10 months ago

Describe your changes

Added a replacer class that is based on the AC trie data structure.

It replaces all occurrences of given patterns (case insensetive) in the given text in O(new_length) where new_length is a length of the text after replacement. Before all replacements (uwufying kernel name, hardware names, etc) were done in O(patterns_count pattern_length new_length) on average, so this data structure speeds up replacement of the substrings.

Also now all patterns and replacements for them are added in one function void uwufy_all(struct info*), while before they all were used separately in the different functions. As a result it will be easier to add new patterns in the future. (all you need to add a new pattern is write actrie_t_add_pattern(&replacer, pattern, pattern_replacement); )

To test this data structure 11 tests were added to the /src/tests/tests.c New file "actrie.h" is formatted with clang-format and changes are tested with make, make debug and make tests on Ubuntu based OS

Example of how replacer works can be found in added test functions, for example, in bool test8_long(): (all this replacements are done in O(new_length) without splitting the original string) image

Settings of this class can be modified in the beginning of the actrie.h header file: image