EncodedFormula SchemaEngine::unhashExpr(const std::string& exprHash) const { istringstream serial(exprHash); EncodedFormula expr; size_t exprSize; serial >> exprSize; expr.reserve(exprSize); for (size_t i = 0; i < exprSize; i++) { uint32_t id; uint32_t arity; serial >> id >> arity; expr.push_back(encoded_token(id, arity)); } return expr; }
string SchemaEngine::hashExpr(const EncodedFormula& expr) const { ostringstream serial; serial << expr.size(); for (const encoded_token_t& tok : expr) { serial << " " << tok.id << " " << tok.arity; } return serial.str(); }
static inline int test_expr_reducer(const EncodedFormula& expr, const EncodedFormula& expectedExpr, uint8_t depth) { MeaningDictionary dict = get_meaning_dict(); SchemaEngine schEng(dict); EncodedFormula result = schEng.reduceFormula(expr, depth); if (expectedExpr.size() != result.size()) return EXIT_FAILURE; for (size_t i = 0; i < result.size(); i++) { encoded_token_t expected = expectedExpr[i]; encoded_token_t returned = result[i]; if (expected.id != returned.id || expected.arity != returned.arity) { return EXIT_FAILURE; } } return EXIT_SUCCESS; }