Compare commits
2 Commits
c46eb7b3aa
...
7258ae9237
Author | SHA1 | Date | |
---|---|---|---|
|
7258ae9237 | ||
|
e5f6c01c2b |
14
README
14
README
|
@ -4,6 +4,17 @@
|
||||||
|
|
||||||
Fast*er* string comparison - an alternative to thousands of strcmp calls
|
Fast*er* string comparison - an alternative to thousands of strcmp calls
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
RES: en.wikipedia.org/wiki/Trie
|
RES: en.wikipedia.org/wiki/Trie
|
||||||
RES: en.wikipedia.org/wiki/Suffix_tree
|
RES: en.wikipedia.org/wiki/Suffix_tree
|
||||||
RES: en.wikipedia.org/wiki/Radix_tree
|
RES: en.wikipedia.org/wiki/Radix_tree
|
||||||
|
@ -48,7 +59,8 @@ LEAKS
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
* everything done so far
|
* feat: add length option - streencpy
|
||||||
|
* feat: ++ strong or loose -- comparison option
|
||||||
|
|
||||||
COMMITS
|
COMMITS
|
||||||
|
|
||||||
|
|
15
streecmp.c
15
streecmp.c
|
@ -115,3 +115,18 @@ int streecmp(struct nod *nod, char *str) {
|
||||||
|
|
||||||
return streecmp(target, str+1);
|
return streecmp(target, str+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int streencmp(struct nod *nod, char *str, int len) {
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
struct nod *target = nod->pool[*str];
|
||||||
|
if (target == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target->val.cval == '\0') {
|
||||||
|
return target->val.ival;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -21,5 +21,6 @@ struct nod *mknod(struct nod *nod, int loc);
|
||||||
int mkstr(struct nod *nod, char *str);
|
int mkstr(struct nod *nod, char *str);
|
||||||
int gentree(struct nod *nod, char *strs, char *delim);
|
int gentree(struct nod *nod, char *strs, char *delim);
|
||||||
int streecmp(struct nod *nod, char *str);
|
int streecmp(struct nod *nod, char *str);
|
||||||
|
int streencmp(struct nod *nod, char *str, int len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user