#ifndef SLOT_MANAGER_INTERNAL_H
#define SLOT_MANAGER_INTERNAL_H
#include "nfagraph/ng.h"
#include "nfagraph/ng_is_equal.h"
#include "util/charreach.h"
#include "ue2common.h"
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <vector>
namespace ue2 {
struct InitialResetEntry {
InitialResetEntry(std::shared_ptr<const NGHolder> sent_in,
std::shared_ptr<const NGHolder> body_in,
const std::unordered_map<NFAVertex, u32> &body_regions_in,
u32 sent_region_in, u32 first_bad_region_in)
: sent(sent_in), body(body_in), body_regions(body_regions_in),
sent_region(sent_region_in), first_bad_region(first_bad_region_in) {}
std::shared_ptr<const NGHolder> sent;
std::shared_ptr<const NGHolder> body;
std::unordered_map<NFAVertex, u32> body_regions;
u32 sent_region;
u32 first_bad_region;
};
struct InitialResetInfo {
explicit InitialResetInfo(u32 slot_in) : slot(slot_in) {}
std::vector<InitialResetEntry> entries;
u32 slot;
};
struct SlotCacheEntry {
SlotCacheEntry(const NGHolder &prefix_in, const CharReach &escapes_in,
u32 parent_in, bool is_reset_in, u32 slot_in);
std::unique_ptr<const NGHolder> prefix;
CharReach escapes;
u32 parent_slot;
bool is_reset;
u32 slot;
};
struct SlotEntryHasher {
size_t operator()(const SlotCacheEntry &e) const;
};
struct SlotEntryEqual {
bool operator()(const SlotCacheEntry &a, const SlotCacheEntry &b) const;
};
struct SlotCache {
typedef std::unordered_set<SlotCacheEntry, SlotEntryHasher,
SlotEntryEqual> CacheStore;
void insert(const NGHolder &prefix, const CharReach &escapes,
u32 parent_slot, bool is_reset, u32 slot);
const SlotCacheEntry *find(const NGHolder &prefix, const CharReach &escapes,
u32 parent_slot, bool is_reset);
CacheStore store;
std::unordered_set<std::shared_ptr<const NGHolder>, NGHolderHasher,
NGHolderEqual> initial_prefixes;
std::vector<InitialResetInfo> initial_resets;
};
}
#endif