streecmp/README

74 lines
2.8 KiB
Plaintext
Raw Normal View History

2024-08-25 12:19:42 +00:00
+==============+
| streecmp |
+==============+
Fast*er* string comparison - an alternative to thousands of strcmp calls
2024-08-28 18:30:33 +00:00
This is an O(n) solution - n being the length of the string to be checked.
A plus is that this method will stay O(n) *no matter the length of the string
nor the number of strings to be checked against*.
Potential minuses might be the additional memory needed to store the trie
data structure or the computational time required to generate the tree before
utilizing it. Therefore, users are advised to use a secure, fast hashmap
instead of streecmp. streecmp is only applied to specific scenarios where
a rather simple or fast solution for string comparison is required so the
project moves on.
2024-08-25 12:19:42 +00:00
RES: en.wikipedia.org/wiki/Trie
RES: en.wikipedia.org/wiki/Suffix_tree
RES: en.wikipedia.org/wiki/Radix_tree
RES: facweb.cs.depaul.edu/mobasher/classes/csc575/Suffix_Trees/index.html
TECHNICALS
struct nod
* data structure that represents a node of the tree
2024-08-27 16:53:04 +00:00
void frenod(struct nod *nod)
* free memory of node and all of its children
struct nod *allocnod(void)
* allocate memory for a node and its pool size for
character hashmap
* returns: poiner to said node or NULL if function fails
struct nod *mknod(struct nod *nod, int loc)
* create a child node below given parent node
* loc is the character of the node (consult source code
of mkstr for more information)
* returns: pointer to said node or NULL if function fails
2024-08-27 16:53:04 +00:00
int mkstr(struct nod *nod, char *str)
2024-08-25 12:19:42 +00:00
* fit string into tree if it does not already exist
* warning: string has to be null-byte terminated
* returns: the assigned ID of the string, 0 if string
is already inside tree, or -1 if function fails
2024-08-27 16:59:30 +00:00
int gentree(struct nod *nod, char *strs, char *delim)
2024-08-25 12:19:42 +00:00
* generate tree from character seperated strings
2024-08-27 16:59:30 +00:00
* if delim is NULL, then "\n" is assumed
2024-08-25 12:19:42 +00:00
* warning: seperation character is '\n'
* returns: 0 if ok or -1 if function fails
2024-08-27 16:53:04 +00:00
int streecmp(struct nod *nod, char *str)
2024-08-25 12:19:42 +00:00
* traverse tree and search for str
* returns: id of string or 0 if there is no match
2024-08-27 16:59:30 +00:00
test.c provides a practical example for comparing against
HTTP header fields
LEAKS
LEAKS file contains the most recent valgrind memory leaks
dump ran on test.c.
2024-08-25 12:19:42 +00:00
TODO
2024-08-28 18:30:33 +00:00
* feat: add length option - streencpy
* feat: ++ strong or loose -- comparison option
2024-08-25 12:19:42 +00:00
COMMITS
Each commit is prefixed with an indicator token of what the change is
*mostly* about. List of tokens is:
* repo: change docs or code style
* feat: implement new change
* fix: implement fix for a bug