Skip to content

Commit

Permalink
iteration on some code
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Jan 2, 2024
1 parent 8418cb9 commit bdf6eca
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 32 deletions.
2 changes: 1 addition & 1 deletion include/common/pddl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace loki
PDDLPositionCache& positions;
// For referencing to existing bindings
ScopeStack& scopes;
// For checking that binding pointers were referenced at least once
// For checking that certain PDDL objects were referenced at least once
ReferencedPDDLObjects references;
// For convenience, to avoid an additional parameter during semantic parsing
pddl::Requirements requirements;
Expand Down
8 changes: 5 additions & 3 deletions include/common/pddl/position.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define LOKI_INCLUDE_LOKI_COMMON_PDDL_POSITION_HPP_

#include "config.hpp"
#include "declarations.hpp"

#include "../ast/error_reporting.hpp"
#include "../filesystem.hpp"

Expand All @@ -27,7 +29,7 @@

namespace loki {
template<typename T>
using PositionMapType = std::unordered_map<const T*, std::vector<PositionType>>;
using PositionMapType = std::unordered_map<PDDLElement<T>, std::vector<PositionType>>;

/// @brief Stores all occurrences of a PDDL object in the input file for each PDDL type T.
template<typename... Ts>
Expand All @@ -41,10 +43,10 @@ class PositionCache {
PositionCache(const X3ErrorHandler& error_handler, const fs::path& file, int tabs=4);

template<typename T>
void push_back(const T* object, const PositionType& position);
void push_back(const PDDLElement<T>& element, const PositionType& position);

template<typename T>
std::vector<PositionType> get(const T* object) const;
std::vector<PositionType> get(const PDDLElement<T>& element) const;

const PDDLErrorHandler& get_error_handler() const;
};
Expand Down
8 changes: 4 additions & 4 deletions include/common/pddl/position.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ PositionCache<Ts...>::PositionCache(const X3ErrorHandler& error_handler, const f

template<typename... Ts>
template<typename T>
void PositionCache<Ts...>::push_back(const T* object, const PositionType& position) {
void PositionCache<Ts...>::push_back(const PDDLElement<T>& element, const PositionType& position) {
auto& t_positions = std::get<PositionMapType<T>>(m_positions);
t_positions[object].push_back(position);
t_positions[element].push_back(position);
}

template<typename... Ts>
template<typename T>
std::vector<PositionType> PositionCache<Ts...>::get(const T* object) const {
std::vector<PositionType> PositionCache<Ts...>::get(const PDDLElement<T>& element) const {
auto& t_positions = std::get<PositionMapType<T>>(m_positions);
auto it = t_positions.find(object);
auto it = t_positions.find(element);
if (it != t_positions.end()) {
return it->second;
}
Expand Down
3 changes: 1 addition & 2 deletions include/common/pddl/reference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class References {
void untrack(T reference);
};

using ReferencedPDDLObjects = References<pddl::Type
, pddl::Object
using ReferencedPDDLObjects = References<pddl::Object
, pddl::Predicate
, pddl::FunctionSkeleton
, pddl::Variable
Expand Down
4 changes: 4 additions & 0 deletions include/common/pddl/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@


namespace loki {
// The segmented sizes are chosen sufficiently large to avoid
// to avoid allocations and for continuous storage.
// The values are just educated guesses based on the knowledge
// that cache line size is 64 Bytes.
using RequirementFactory = PersistentFactory<pddl::RequirementsImpl, 100>;
using TypeFactory = PersistentFactory<pddl::TypeImpl, 1000>;
using VariableFactory = PersistentFactory<pddl::VariableImpl, 1000>;
Expand Down
16 changes: 0 additions & 16 deletions include/domain/pddl/declarations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@

#include <boost/container/small_vector.hpp>

#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <set>
#include <variant>


Expand All @@ -38,12 +34,10 @@ namespace loki::pddl {
class TypeImpl;
using Type = const TypeImpl*;
using TypeList = boost::container::small_vector<Type,1>; // often single type
using TypeSet = std::set<Type>;

class ObjectImpl;
using Object = const ObjectImpl*;
using ObjectList = std::vector<Object>;
using ObjectSet = std::set<Object>;

class VariableImpl;
using Variable = const VariableImpl*;
Expand All @@ -68,12 +62,10 @@ namespace loki::pddl {
class PredicateImpl;
using Predicate = const PredicateImpl*;
using PredicateList = std::vector<Predicate>;
using PredicateSet = std::set<Predicate>;

class LiteralImpl;
using Literal = const LiteralImpl*;
using LiteralList = std::vector<Literal>;
using LiteralSet = std::set<Literal>;

class ConditionLiteralImpl;
class ConditionAndImpl;
Expand All @@ -91,7 +83,6 @@ namespace loki::pddl {
, ConditionForallImpl>;
using Condition = const ConditionImpl*;
using ConditionList = std::vector<Condition>;
using ConditionSet = std::set<Condition>;

class EffectLiteralImpl;
class EffectAndImpl;
Expand All @@ -105,7 +96,6 @@ namespace loki::pddl {
, EffectConditionalWhenImpl>;
using Effect = const EffectImpl*;
using EffectList = std::vector<Effect>;
using EffectSet = std::set<Effect>;

class FunctionExpressionNumberImpl;
class FunctionExpressionBinaryOperatorImpl;
Expand All @@ -123,32 +113,26 @@ namespace loki::pddl {
class FunctionSkeletonImpl;
using FunctionSkeleton = const FunctionSkeletonImpl*;
using FunctionSkeletonList = std::vector<FunctionSkeleton>;
using FunctionSkeletonSet = std::set<FunctionSkeleton>;

class FunctionImpl;
using Function = const FunctionImpl*;
using FunctionList = std::vector<Function>;
using FunctionSet = std::set<Function>;

class ConstraintImpl;
using Constraint = const ConstraintImpl*;
using ConstraintList = std::vector<Constraint>;
using ConstraintSet = std::set<Constraint>;

class ActionImpl;
using Action = const ActionImpl*;
using ActionList = std::vector<Action>;
using ActionSet = std::set<Action>;

class DerivedPredicateImpl;
using DerivedPredicate = const DerivedPredicateImpl*;
using DerivedPredicateList = std::vector<DerivedPredicate>;
using DerivedPredicateSet = std::set<DerivedPredicate>;

class DomainImpl;
using Domain = const DomainImpl*;
using DomainList = std::vector<Domain>;
using DomainSet = std::set<Domain>;
}

#endif
5 changes: 0 additions & 5 deletions include/problem/pddl/declarations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@

#include "../../domain/pddl/declarations.hpp"

#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>


Expand Down
1 change: 0 additions & 1 deletion src/domain/pddl/parser/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ static void test_reserved_type(const pddl::Type& type, const domain::ast::Name&
static void insert_context_information(const pddl::Type& type, const domain::ast::Name& node, Context& context) {
context.positions.push_back(type, node);
context.scopes.insert(type->get_name(), type, node);
context.references.track(type);
}


Expand Down

0 comments on commit bdf6eca

Please sign in to comment.