SyntaxParser/include/ItemCollection.h

65 lines
1.2 KiB
C
Raw Normal View History

2021-04-30 12:55:56 +00:00
//
// Created by Administrator on 2021/4/30.
//
#ifndef SYNTAXPARSER_ITEMCOLLECTION_H
#define SYNTAXPARSER_ITEMCOLLECTION_H
#include <fstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <Item.h>
#include <GrammarResourcePool.h>
class ItemCollectionManager;
class ItemCollection{
int index = 0;
std::map<size_t, Item *> items;
std::vector<Item *> cache;
GrammarResourcePool *pool;
friend ItemCollectionManager;
template <class T>
inline void hash_combine(std::size_t& seed, const T& v) const
{
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
static bool compare_item_ptr(const Item* lhs, const Item* rhs);
public:
explicit ItemCollection(GrammarResourcePool *pool) : pool(pool) {
}
[[nodiscard]] const std::vector<Item *> &getItems() const {
return cache;
}
[[nodiscard]] int getIndex() const {
return index;
}
bool addItem(const Production *p_pdt, int dot_index, int terminator, bool generated = false);
void CLOSURE();
void print(std::wofstream &output) const;
[[nodiscard]] size_t getHash() const;
};
#endif //SYNTAXPARSER_ITEMCOLLECTION_H