#ifndef LIBRARYMANAGER_H #define LIBRARYMANAGER_H #include "Book.h" #include "AVLTree.h" #include #include #include #include class LibraryManager { public: LibraryManager(); ~LibraryManager(); bool addBook(const Book& book); bool removeBook(const std::string& bookID); Book* searchByBookID(const std::string& bookID) const; std::vector searchBooks(const std::string& query) const; // 新增方法 std::vector> getAllBooks() const; void inOrderTraverse(AVLNode* node, std::vector>& booksAndHeight) const; AVLNode* getBookIDTreeRoot() const; std::vector getAllBooksOld() const; private: AVLTree bookIDTree; AVLTree titleTree; AVLTree authorTree; // 倒排索引:关键词 -> 书籍列表 //std::unordered_map> invertedIndex; MyUnorderedMap> invertedIndex; void inOrderTraverseHelper(AVLNode* node, std::vector>& booksAndHeight) const; void loadBooksFromFile(const std::string& filename = "books.txt"); void addToIndex(const Book& book); void removeFromIndex(const Book& book); // 辅助函数 std::vector tokenize(const std::string& text) const; std::string toLower(const std::string& str) const; // 声明 toLower 函数 }; #endif // LIBRARYMANAGER_H