mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 01:29:58 +01:00
[graph] Fix StorageCartesianFunction
This commit is contained in:
@@ -5,22 +5,14 @@ extern "C" {
|
||||
}
|
||||
#include <ion.h>
|
||||
|
||||
using namespace Shared;
|
||||
|
||||
namespace Graph {
|
||||
|
||||
//constexpr const char * StorageCartesianFunctionStore::k_functionNames[k_maxNumberOfFunctions];
|
||||
|
||||
Shared::StorageCartesianFunction StorageCartesianFunctionStore::NullModel() {
|
||||
return Shared::StorageCartesianFunction("");
|
||||
}
|
||||
|
||||
StorageCartesianFunctionStore::StorageCartesianFunctionStore() :
|
||||
Shared::StorageFunctionStore<Shared::StorageCartesianFunction>()
|
||||
Shared::StorageFunctionStore()
|
||||
{
|
||||
//addEmptyModel();
|
||||
}
|
||||
|
||||
char StorageCartesianFunctionStore::symbol() const {
|
||||
return 'x';
|
||||
addEmptyModel();
|
||||
}
|
||||
|
||||
void StorageCartesianFunctionStore::removeAll() {
|
||||
@@ -28,5 +20,26 @@ void StorageCartesianFunctionStore::removeAll() {
|
||||
addEmptyModel();
|
||||
}
|
||||
|
||||
void StorageCartesianFunctionStore::addEmptyModel() {
|
||||
Ion::Storage::Record::ErrorStatus error;
|
||||
StorageCartesianFunction newModel = StorageCartesianFunction::NewModel(&error);
|
||||
assert(error == Ion::Storage::Record::ErrorStatus::None);
|
||||
}
|
||||
|
||||
void StorageCartesianFunctionStore::privateSetMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const {
|
||||
assert(cacheIndex >= 0 && cacheIndex < k_maxNumberOfMemoizedModels);
|
||||
m_functions[cacheIndex] = StorageCartesianFunction(record);
|
||||
}
|
||||
|
||||
void StorageCartesianFunctionStore::moveMemoizedModel(int previousIndex, int nextIndex) const {
|
||||
assert(nextIndex >= 0 && nextIndex < k_maxNumberOfMemoizedModels);
|
||||
assert(previousIndex >= 0 && previousIndex < k_maxNumberOfMemoizedModels);
|
||||
m_functions[nextIndex] = m_functions[previousIndex];
|
||||
}
|
||||
|
||||
StorageExpressionModel * StorageCartesianFunctionStore::memoizedModelAtIndex(int cacheIndex) const {
|
||||
assert(cacheIndex >= 0 && cacheIndex < k_maxNumberOfMemoizedModels);
|
||||
return &m_functions[cacheIndex];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,26 +8,21 @@
|
||||
|
||||
namespace Graph {
|
||||
|
||||
class StorageCartesianFunctionStore : public Shared::StorageFunctionStore<Shared::StorageCartesianFunction> {
|
||||
class StorageCartesianFunctionStore : public Shared::StorageFunctionStore {
|
||||
public:
|
||||
static Shared::StorageCartesianFunction NullModel();
|
||||
|
||||
StorageCartesianFunctionStore();
|
||||
/* StorageCartesianFunction activeCartesianFunctionAtIndex(int i) override { return (CartesianFunction *)Shared::FunctionStore::activeFunctionAtIndex(i); }
|
||||
StorageCartesianFunction definedFunctionAtIndex(int i) override { return (CartesianFunction *)Shared::FunctionStore::definedFunctionAtIndex(i); }
|
||||
*/
|
||||
char symbol() const override;
|
||||
Shared::StorageCartesianFunction * modelAtIndex(int i) const override { return static_cast<Shared::StorageCartesianFunction *>(Shared::StorageFunctionStore::modelAtIndex(i)); }
|
||||
Shared::StorageCartesianFunction * activeFunctionAtIndex(int i) const override { return static_cast<Shared::StorageCartesianFunction *>(Shared::StorageFunctionStore::activeFunctionAtIndex(i)); }
|
||||
Shared::StorageCartesianFunction * definedModelAtIndex(int i) const override { return static_cast<Shared::StorageCartesianFunction *>(Shared::StorageFunctionStore::definedModelAtIndex(i)); }
|
||||
char symbol() const override { return 'x'; }
|
||||
void removeAll() override;
|
||||
static constexpr int k_maxNumberOfFunctions = 4; //TODO
|
||||
private:
|
||||
/* static constexpr const char * k_functionNames[k_maxNumberOfFunctions] = {
|
||||
"f", "g", "h", "p" //TODO
|
||||
};
|
||||
|
||||
const char * firstAvailableName() override {
|
||||
return firstAvailableAttribute(k_functionNames, FunctionStore::name);
|
||||
}*/
|
||||
const char * firstAvailableName() override { return "f"; }
|
||||
void addEmptyModel();
|
||||
const char * modelExtension() const override { return Shared::GlobalContext::funcExtension; }
|
||||
void privateSetMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const override;
|
||||
void moveMemoizedModel(int previousIndex, int nextIndex) const override;
|
||||
Shared::StorageExpressionModel * memoizedModelAtIndex(int cacheIndex) const override;
|
||||
mutable Shared::StorageCartesianFunction m_functions[k_maxNumberOfMemoizedModels];
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -26,10 +26,11 @@ public:
|
||||
|
||||
// Other
|
||||
void tidy();
|
||||
protected:
|
||||
constexpr static int k_maxNumberOfMemoizedModels = 5;
|
||||
private:
|
||||
virtual const char * modelExtension() const = 0;
|
||||
// Memoization of k_maxNumberOfMemoizedModels consecutive models
|
||||
constexpr static int k_maxNumberOfMemoizedModels = 5;
|
||||
mutable int m_firstMemoizedModelIndex;
|
||||
mutable uint32_t m_memoizedModelChecksum[k_maxNumberOfMemoizedModels];
|
||||
void setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record) const;
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
int numberOfActiveFunctions() const;
|
||||
virtual StorageFunction * modelAtIndex(int i) const override { return static_cast<StorageFunction *>(StorageExpressionModelStore::modelAtIndex(i)); }
|
||||
virtual StorageFunction * definedModelAtIndex(int i) const override { return static_cast<StorageFunction *>(StorageExpressionModelStore::definedModelAtIndex(i)); }
|
||||
virtual StorageFunction * activeFunctionAtIndex(int i);
|
||||
virtual StorageFunction * activeFunctionAtIndex(int i) const;
|
||||
|
||||
virtual char symbol() const = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user