C++ Standard Template Library browser.
at main 45 lines 1.2 kB view raw
1#pragma once 2#include "prelude.hpp" 3#include <filesystem> 4#include <fstream> 5#include <iostream> 6#include <ranges> 7#include <sstream> 8#include <unordered_map> 9 10template <typename Key, typename Value> 11using map = std::unordered_map<Key, Value>; 12 13struct Document { 14 map<String, U64> freqs; 15 String filename; 16 17 Document(std::string_view name, map<String, U64>&& mp); 18 19 Document(std::string_view name); 20 21 void show_freqs() const noexcept; 22}; 23 24fn filter_divs(std::string_view html) noexcept -> String; 25 26fn to_words(std::string_view lines) noexcept -> Vector<String>; 27 28fn index_directory(std::filesystem::path dir) noexcept -> Vector<Document>; 29 30void cache_index(Ref<const Vector<Document>> documents) noexcept; 31 32fn load_index() noexcept -> Vector<Document>; 33 34fn get_cache_dir() noexcept -> std::filesystem::path; 35 36fn count_query(Ref<const Vector<Document>> documents, 37 Ref<const String> query) noexcept 38 -> Vector<std::pair<String, F64>>; 39 40fn count_tfidf(Ref<const Vector<Document>> documents, 41 Ref<const String> query) noexcept 42 -> Vector<std::pair<String, F64>>; 43 44fn top_n_matches(Ref<const Vector<Document>> documents, Ref<const String> query, U64 n) noexcept 45 -> Vector<std::pair<String, F64>>;