Skip to content

Conversation

@aaayyywww
Copy link

in main.c there is a realization of levensthtein distance functrion;
in updated cstring.h there is a new func called stringLevenstheinDistance

Comment on lines +6 to +31
int64_t LevenstheinRecursive(TString s1, TString s2, int64_t len1, int64_t len2) {
int64_t a, b, c;
if (len1 == 0) {
return len2;
}
if (len2 == 0) {
return len1;
}
if (s1.data[len1 - 1] == s2.data[len2 - 1]) {
return LevenstheinRecursive(s1, s2, len1 - 1, len2 - 1);
}
a = LevenstheinRecursive(s1, s2, len1 - 1, len2 - 1);
b = LevenstheinRecursive(s1, s2, len1, len2 - 1);
c = LevenstheinRecursive(s1, s2, len1 - 1, len2);

if (a > b) a = b;
if (a > c) a = c;
return a + 1;
}

int64_t stringLevenstheinDistance(TString s1, TString s2) {
int64_t len1 = (int64_t)stringLen(s1);
int64_t len2 = (int64_t)stringLen(s2);
int64_t res = LevenstheinRecursive(s1, s2, len1, len2);
return res;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is it? Place it into cstring.h to other funtions

Comment on lines +27 to +29
int64_t len1 = (int64_t)stringLen(s1);
int64_t len2 = (int64_t)stringLen(s2);
int64_t res = LevenstheinRecursive(s1, s2, len1, len2);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need int64_t? Use size_t instead

Comment on lines +34 to +36
TString myString1 = stringInitWithCharArr("hello world");
TString myString2 = stringInitWithCharArr("hello 112312ld");
int64_t res = stringLevenstheinDistance(myString1, myString2);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move test to testfile.
Add more cases: empty string, equal strings and so on

#include "cstring.h"
#include <string.h>

int64_t LevenstheinRecursive(TString s1, TString s2, int64_t len1, int64_t len2) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is very clear, nice!

@@ -1,944 +1,945 @@
#ifndef CSTRING_LIB
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong! The entire file has been deleted and added back, some kind of error. It is necessary that only the really modified parts of the code are highlighted. Please fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants