MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / similarity

Method similarity

core/string/ustring.cpp:3755–3783  ·  view source on GitHub ↗

Similarity according to Sorensen-Dice coefficient

Source from the content-addressed store, hash-verified

3753
3754// Similarity according to Sorensen-Dice coefficient
3755float String::similarity(const String &p_string) const {
3756 if (operator==(p_string)) {
3757 // Equal strings are totally similar
3758 return 1.0f;
3759 }
3760 if (length() < 2 || p_string.length() < 2) {
3761 // No way to calculate similarity without a single bigram
3762 return 0.0f;
3763 }
3764
3765 const int src_size = length() - 1;
3766 const int tgt_size = p_string.length() - 1;
3767
3768 const int sum = src_size + tgt_size;
3769 int inter = 0;
3770 for (int i = 0; i < src_size; i++) {
3771 const char32_t i0 = get(i);
3772 const char32_t i1 = get(i + 1);
3773
3774 for (int j = 0; j < tgt_size; j++) {
3775 if (i0 == p_string.get(j) && i1 == p_string.get(j + 1)) {
3776 inter++;
3777 break;
3778 }
3779 }
3780 }
3781
3782 return (2.0f * inter) / sum;
3783}
3784
3785static bool _wildcard_match(const char32_t *p_pattern, const char32_t *p_string, bool p_case_sensitive) {
3786 switch (*p_pattern) {

Callers 3

suggest_actionsMethod · 0.80
test_string.hFile · 0.80

Calls 3

getFunction · 0.50
lengthMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected