Skip to content

Commit 806222d

Browse files
committed
Make length comparison cross-platform
1 parent f070279 commit 806222d

5 files changed

Lines changed: 5 additions & 6 deletions

File tree

‎bktree/bktree.hpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ class LengthDistance final : public Distance<LengthDistance> {
8080
public:
8181
explicit LengthDistance(){};
8282
integer_type compute_distance(std::string_view s, std::string_view t) const {
83-
std::int64_t const d = s.length() - t.length();
84-
return d >= 0 ? d : -d;
83+
return s.length() > t.length() ? s.length() - t.length() : t.length() - s.length();
8584
}
8685
};
8786

‎examples/bktree_damerau.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void example() {
77
bk_tree::BKTree<bk_tree::metrics::DamerauLevenshteinDistance> tree;
88
{
99
std::vector<std::string> input{"tall", "tell", "teel", "feel", "tally",
10-
"tuck", "belly", "kelly", "kill", "tal"};
10+
"tuck", "belly", "kelly", "kill", "tal"};
1111
for (auto &s : input) {
1212
tree.insert(s);
1313
}

‎examples/bktree_edit.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void example() {
77
bk_tree::BKTree<bk_tree::metrics::EditDistance> tree;
88
{
99
std::vector<std::string> input{"tall", "tell", "teel", "feel", "tally",
10-
"tuck", "belly", "kelly", "kill", "tal"};
10+
"tuck", "belly", "kelly", "kill", "tal"};
1111
for (auto &s : input) {
1212
tree.insert(s);
1313
}

‎examples/bktree_hamming.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void example() {
77
bk_tree::BKTree<bk_tree::metrics::HammingDistance> tree;
88
{
99
std::vector<std::string> input{"tall", "tell", "teel", "feel", "tally",
10-
"tuck", "belly", "kelly", "kill", "tal"};
10+
"tuck", "belly", "kelly", "kill", "tal"};
1111
for (auto &s : input) {
1212
tree.insert(s);
1313
}

‎examples/bktree_lcs.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void example() {
77
bk_tree::BKTree<bk_tree::metrics::LCSubseqDistance> tree;
88
{
99
std::vector<std::string> input{"tall", "tell", "teel", "feel", "tally",
10-
"belly", "kelly", "kill", "tal", "tuck"};
10+
"belly", "kelly", "kill", "tal", "tuck"};
1111
for (auto &s : input) {
1212
tree.insert(s);
1313
}

0 commit comments

Comments
 (0)