Reworked handling of numerical key tables to make iteration over keys actual numerics, instead of strings
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
6
src/Evaluator/EvalValues/NumericalTableEvalValue.cpp
Normal file
6
src/Evaluator/EvalValues/NumericalTableEvalValue.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "NumericalTableEvalValue.hpp"
|
||||
#include "../Iterator/NumericalKeyIterator.hpp"
|
||||
|
||||
Porygon::Evaluation::Iterator *Porygon::Evaluation::NumericalTableEvalValue::GetKeyIterator() const {
|
||||
return new NumericalKeyIterator(this);
|
||||
}
|
||||
69
src/Evaluator/EvalValues/NumericalTableEvalValue.hpp
Normal file
69
src/Evaluator/EvalValues/NumericalTableEvalValue.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef PORYGONLANG_NUMERICALTABLEEVALVALUE_HPP
|
||||
#define PORYGONLANG_NUMERICALTABLEEVALVALUE_HPP
|
||||
|
||||
|
||||
#include <utility>
|
||||
#include <map>
|
||||
#include "EvalValue.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Porygon::Evaluation {
|
||||
class NumericalTableEvalValue : public EvalValue {
|
||||
const shared_ptr<vector<shared_ptr<EvalValue>>> _table;
|
||||
const size_t _hash;
|
||||
|
||||
explicit NumericalTableEvalValue(shared_ptr<vector<shared_ptr<EvalValue>>> table, size_t hash)
|
||||
: _table(std::move(table)),
|
||||
_hash(hash)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
explicit NumericalTableEvalValue(shared_ptr<vector<shared_ptr<EvalValue>>> table) :
|
||||
_table(std::move(table)),
|
||||
_hash(rand())
|
||||
{
|
||||
}
|
||||
|
||||
const TypeClass GetTypeClass() const final {
|
||||
return TypeClass::Table;
|
||||
}
|
||||
|
||||
const size_t GetHashCode() const final {
|
||||
return _hash;
|
||||
}
|
||||
|
||||
const bool operator==(EvalValue *b) const final {
|
||||
return this->_hash == b->GetHashCode();
|
||||
}
|
||||
|
||||
const shared_ptr<EvalValue> Clone() const final {
|
||||
return shared_ptr<EvalValue>(new NumericalTableEvalValue(_table, _hash));
|
||||
}
|
||||
|
||||
const shared_ptr<EvalValue> IndexValue(EvalValue *val) const final {
|
||||
const auto index = val->EvaluateInteger() - 1;
|
||||
return this->_table->at(index);
|
||||
}
|
||||
|
||||
const shared_ptr<EvalValue> IndexValue(uint32_t hash) const final {
|
||||
return this->_table->at(hash - 1);
|
||||
}
|
||||
|
||||
void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue> &value) const final {
|
||||
auto index = key->EvaluateInteger();
|
||||
this->_table->at(index - 1) = value;
|
||||
}
|
||||
|
||||
Iterator * GetKeyIterator() const final;
|
||||
|
||||
const shared_ptr<vector<shared_ptr<EvalValue>>> GetTable() const{
|
||||
return _table;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#undef iteratorKind
|
||||
|
||||
#endif //PORYGONLANG_NUMERICALTABLEEVALVALUE_HPP
|
||||
Reference in New Issue
Block a user