Sorensen–Dice coefficient: Difference between revisions

m
C++ - minor performance improvement
(Added C++ solution)
m (C++ - minor performance improvement)
Line 57:
#include <vector>
 
using bigram = std::pair<char, char>;
std::multiset<std::string> split(const std::string& phrase) {
 
std::multiset<std::string> result;
std::multiset<std::stringbigram> split(const std::string& phrase) {
std::multiset<std::stringbigram> result;
std::istringstream is(phrase);
std::string word;
Line 67 ⟶ 69:
size_t length = word.size();
if (length == 1) {
result.emplace(1, word[0], '\0');
} else {
for (size_t i = 0; i + 1 < length; ++i) {
result.insertemplace(std::string{word[i], word[i + 1]});
}
}
Line 80 ⟶ 82:
auto a = split(s1);
auto b = split(s2);
std::multiset<std::stringbigram> c;
std::set_intersection(a.begin(), a.end(), b.begin(), b.end(),
std::inserter(c, c.begin()));
1,777

edits