move operator info into a struct for locality

thread
Brett 2024-06-30 13:57:45 -04:00
parent d3124f8516
commit 96d8b278e8
4 changed files with 16 additions and 15 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(blt-gp VERSION 0.0.43) project(blt-gp VERSION 0.0.44)
include(CTest) include(CTest)

View File

@ -49,13 +49,17 @@ namespace blt::gp
struct argc_t struct argc_t
{ {
blt::size_t argc = 0; blt::u32 argc = 0;
blt::size_t argc_context = 0; blt::u32 argc_context = 0;
}; };
struct operator_info struct operator_info
{ {
std::vector<type_id> argument_types;
type_id return_type;
argc_t argc;
detail::callable_t function;
detail::transfer_t transfer;
}; };
struct operator_storage struct operator_storage
@ -65,9 +69,9 @@ namespace blt::gp
blt::expanding_buffer<std::vector<operator_id>> non_terminals; blt::expanding_buffer<std::vector<operator_id>> non_terminals;
blt::expanding_buffer<std::vector<std::pair<operator_id, blt::size_t>>> operators_ordered_terminals; blt::expanding_buffer<std::vector<std::pair<operator_id, blt::size_t>>> operators_ordered_terminals;
// indexed from OPERATOR ID (operator number) // indexed from OPERATOR ID (operator number)
blt::hashset_t<operator_id> static_types;
blt::expanding_buffer<std::vector<type>> argument_types; blt::expanding_buffer<std::vector<type>> argument_types;
blt::expanding_buffer<argc_t> operator_argc; blt::expanding_buffer<argc_t> operator_argc;
blt::hashset_t<operator_id> static_types;
std::vector<detail::callable_t> operators; std::vector<detail::callable_t> operators;
std::vector<detail::transfer_t> transfer_funcs; std::vector<detail::transfer_t> transfer_funcs;
}; };

View File

@ -88,8 +88,10 @@ namespace blt::gp
template<typename T> template<typename T>
inline type register_type() inline type register_type()
{ {
types.insert({blt::type_string_raw<T>(), type::make_type<T>(types.size())}); auto t = type::make_type<T>(types.size());
return types[blt::type_string_raw<T>()]; types.insert({blt::type_string_raw<T>(), t});
types_from_id[t.id()] = t;
return t;
} }
template<typename T> template<typename T>
@ -100,13 +102,7 @@ namespace blt::gp
inline type get_type(type_id id) inline type get_type(type_id id)
{ {
for (const auto& v : types) return types_from_id[id];
{
if (v.second.id() == id)
return v.second;
}
BLT_ABORT(("Type " + std::to_string(id) + " does not exist").c_str());
std::exit(0);
} }
/** /**
@ -126,6 +122,7 @@ namespace blt::gp
private: private:
blt::hashmap_t<std::string, type> types; blt::hashmap_t<std::string, type> types;
blt::expanding_buffer<type> types_from_id;
}; };
} }

@ -1 +1 @@
Subproject commit f3451b57ab249fdcf5ccedd64cbd56b2a64e2de2 Subproject commit 57ddcfca1e72245b8e7e59a2f6ccf2efda1b29b3