aboutsummaryrefslogtreecommitdiff
path: root/Занимательное программирование/5/3_context/context.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'Занимательное программирование/5/3_context/context.hpp')
-rw-r--r--Занимательное программирование/5/3_context/context.hpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/Занимательное программирование/5/3_context/context.hpp b/Занимательное программирование/5/3_context/context.hpp
new file mode 100644
index 0000000..519b601
--- /dev/null
+++ b/Занимательное программирование/5/3_context/context.hpp
@@ -0,0 +1,27 @@
+#include <list>
+#include "utf8.h"
+#include <unordered_map>
+
+struct context_occurrence
+{
+ unsigned int count{ 1 };
+ std::unordered_map<utf8::utfchar32_t, unsigned int> counts;
+
+ explicit context_occurrence(utf8::utfchar32_t character);
+ void add(utf8::utfchar32_t character);
+
+ std::unordered_map<utf8::utfchar32_t, unsigned int>::iterator begin();
+ std::unordered_map<utf8::utfchar32_t, unsigned int>::iterator end();
+};
+
+struct context_model
+{
+ void add(utf8::utfchar32_t character);
+
+ std::unordered_map<std::string, context_occurrence>::iterator begin();
+ std::unordered_map<std::string, context_occurrence>::iterator end();
+
+private:
+ std::list<utf8::utfchar32_t> current_context;
+ std::unordered_map<std::string, context_occurrence> occurrences;
+};