diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-11-04 02:19:09 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-11-04 02:19:09 -0500 |
commit | 76bc3b3677062c0c1a6b9fa08ff20d12e470159c (patch) | |
tree | 390897784acdec4f002df4a13e5d63f1f641fb40 /designer.h | |
parent | 5a65625cb589b2cb5b336e1fa5748df8dcdb8f6a (diff) | |
download | wizard-76bc3b3677062c0c1a6b9fa08ff20d12e470159c.tar.gz wizard-76bc3b3677062c0c1a6b9fa08ff20d12e470159c.tar.bz2 wizard-76bc3b3677062c0c1a6b9fa08ff20d12e470159c.zip |
Some old refactoring + some new refactoring
Diffstat (limited to 'designer.h')
-rw-r--r-- | designer.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/designer.h b/designer.h new file mode 100644 index 0000000..38ae3c3 --- /dev/null +++ b/designer.h | |||
@@ -0,0 +1,49 @@ | |||
1 | #ifndef DESIGNER_H_06F8DE64 | ||
2 | #define DESIGNER_H_06F8DE64 | ||
3 | |||
4 | #include <cstddef> | ||
5 | #include <list> | ||
6 | #include <memory> | ||
7 | #include <random> | ||
8 | #include <string> | ||
9 | #include <vector> | ||
10 | |||
11 | #include "cardset.h" | ||
12 | #include "prefix_search.h" | ||
13 | |||
14 | struct usage { | ||
15 | size_t cardId; | ||
16 | size_t strIndex; | ||
17 | size_t strLen; | ||
18 | |||
19 | usage(size_t ci, size_t si, size_t sl) | ||
20 | : cardId(ci), strIndex(si), strLen(sl) {} | ||
21 | }; | ||
22 | |||
23 | struct solution { | ||
24 | const ps_type& prefix; | ||
25 | std::vector<size_t> lengths; | ||
26 | size_t score; | ||
27 | }; | ||
28 | |||
29 | class designer { | ||
30 | public: | ||
31 | designer(std::string text, const ps_type& titles) | ||
32 | : text_(std::move(text)), | ||
33 | titles_(titles), | ||
34 | solutions_(text_.length() + 1) {} | ||
35 | |||
36 | std::list<usage> generate(std::mt19937& rng) const; | ||
37 | |||
38 | private: | ||
39 | const solution& get(size_t i) const; | ||
40 | |||
41 | solution calculate(size_t i) const; | ||
42 | |||
43 | const std::string text_; | ||
44 | const ps_type& titles_; | ||
45 | |||
46 | mutable std::vector<std::unique_ptr<solution>> solutions_; | ||
47 | }; | ||
48 | |||
49 | #endif /* end of include guard: DESIGNER_H_06F8DE64 */ | ||