forked from cubicdaiya/dtl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strdiff.cpp
62 lines (44 loc) · 1.63 KB
/
strdiff.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "common.hpp" // fmt::formatter for dtl_modern::SesElem
#include <dtl_modern/dtl_modern.hpp>
#define DTL_MODERN_DISPLAY_FMTLIB
#include <dtl_modern/extra/ses_display_simple.hpp>
#include <dtl.hpp>
#include <fmt/core.h>
#include <fmt/std.h>
#include <fmt/ranges.h>
void classic()
{
using namespace std::string_literals; // s UDL
using Diff = dtl::Diff<char, std::string>;
fmt::println("\n>>> dtl classic:");
auto hello1 = "hello World!"s;
auto hello2 = "Hell word"s;
fmt::println("\thello1 : {:?}", hello1);
fmt::println("\thello2 : {:?}\n", hello2);
auto diff = Diff{ hello1, hello2 };
diff.compose();
fmt::println("\tedit_distance: {}", diff.getEditDistance());
fmt::println("\tlcs : {}", diff.getLcs().getSequence());
fmt::println("\tses : {}", diff.getSes().getSequence());
diff.printSES();
}
void modern()
{
using namespace std::literals; // s and sv UDL
fmt::println("\n>>> dtl modern:");
auto hello1 = "hello World!"sv; // notice the different type, this one is std::string_view
auto hello2 = "Hell word"s; // this one is std::string
fmt::println("\thello1 : {:?}", hello1);
fmt::println("\thello2 : {:?}\n", hello2);
auto [lcs, ses, edit_distance] = dtl_modern::diff(hello1, hello2);
fmt::println("\tedit_distance: {}", edit_distance);
fmt::println("\tlcs : {}", lcs.get());
fmt::println("\tses : {}", ses.get());
fmt::print("{}", dtl_modern::extra::display(ses));
// std::cout << dtl_modern::extra::display(ses);
}
int main()
{
classic();
modern();
}