forked from cubicdaiya/dtl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intdiff.cpp
72 lines (53 loc) · 1.97 KB
/
intdiff.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
63
64
65
66
67
68
69
70
71
72
#include "common.hpp"
#include <dtl_modern/dtl_modern.hpp>
#define DTL_MODERN_DISPLAY_FMTLIB
#include <dtl_modern/extra/ses_display_simple.hpp>
#include <dtl_modern/extra/uni_hunk_display_simple.hpp>
#include <dtl.hpp>
#include <fmt/base.h>
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <sstream>
void classic()
{
fmt::println("\n>>> dtl classic:");
auto a = std::vector{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
auto b = std::vector{ 3, 5, 1, 4, 5, 1, 7, 9, 6, 10 };
fmt::println("\ta: {}", a);
fmt::println("\tb: {}\n", b);
auto diff = dtl::Diff<int>{ a, b };
diff.compose();
diff.composeUnifiedHunks();
fmt::println("\tedit_distance: {}", diff.getEditDistance());
fmt::println("\tlcs : {}", diff.getLcs().getSequence());
fmt::println("\tses : {::?}", diff.getSes().getSequence());
fmt::println("\thunks : {}", diff.getUniHunks().size());
std::stringstream sstream;
diff.printSES(sstream);
fmt::println("\tses text : {:?}", sstream.str());
std::stringstream{}.swap(sstream);
diff.printUnifiedFormat(sstream);
fmt::println("\thunks text : {:?}", sstream.str());
}
void modern()
{
fmt::println("\n>>> dtl modern:");
auto a = std::array{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
auto b = std::array{ 3, 5, 1, 4, 5, 1, 7, 9, 6, 10 };
fmt::println("\ta: {}", a);
fmt::println("\tb: {}\n", b);
auto [hunks, lcs, ses, edit_distance] = dtl_modern::unidiff(a, b);
fmt::println("\tedit_distance: {}", edit_distance);
fmt::println("\tlcs : {}", lcs.get());
fmt::println("\tses : {::?}", ses.get());
fmt::println("\thunks : {}", hunks.get().size());
auto ses_str = fmt::format("{}", dtl_modern::extra::display(ses));
auto hunks_str = fmt::format("{}", dtl_modern::extra::display(hunks));
fmt::println("\tses text : {:?}", ses_str);
fmt::println("\thunks text : {:?}", hunks_str);
}
int main()
{
classic();
modern();
}