Skip to content

Commit

Permalink
Update ExprTk
Browse files Browse the repository at this point in the history
Signed-off-by: Arash Partow <partow@gmail.com>
  • Loading branch information
ArashPartow committed Nov 13, 2024
1 parent 452bfb0 commit 2340bdb
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 119 deletions.
2 changes: 1 addition & 1 deletion cmake/exprtk.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(exprtk-download NONE)
include(ExternalProject)
ExternalProject_Add(exprtk
GIT_REPOSITORY https://github.com/ArashPartow/exprtk.git
GIT_TAG 0.0.2
GIT_TAG 0.0.3
SOURCE_DIR "${CMAKE_BINARY_DIR}/exprtk-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/exprtk-build"
CONFIGURE_COMMAND ""
Expand Down
29 changes: 29 additions & 0 deletions cpp/perspective/src/cpp/scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,35 @@ t_tscalar::operator%=(const t_tscalar& rhs) {
return *this;
}

t_tscalar::operator std::size_t () const {
switch (get_dtype()) {
case perspective::t_dtype::DTYPE_INT64:
return static_cast<std::size_t>(get<std::int64_t>());
case perspective::t_dtype::DTYPE_INT32:
return static_cast<std::size_t>(get<std::int32_t>());
case perspective::t_dtype::DTYPE_INT16:
return static_cast<std::size_t>(get<std::int16_t>());
case perspective::t_dtype::DTYPE_INT8:
return static_cast<std::size_t>(get<std::int8_t>());
case perspective::t_dtype::DTYPE_UINT64:
return static_cast<std::size_t>(get<std::uint64_t>());
case perspective::t_dtype::DTYPE_UINT32:
return static_cast<std::size_t>(get<std::uint32_t>());
case perspective::t_dtype::DTYPE_UINT16:
return static_cast<std::size_t>(get<std::uint16_t>());
case perspective::t_dtype::DTYPE_UINT8:
return static_cast<std::size_t>(get<std::uint8_t>());
case perspective::t_dtype::DTYPE_FLOAT64:
return static_cast<std::size_t>(get<double>());
case perspective::t_dtype::DTYPE_FLOAT32:
return static_cast<std::size_t>(get<float>());
default:
return std::numeric_limits<std::size_t>::max();
}

return std::numeric_limits<std::size_t>::max();
}

t_tscalar
t_tscalar::add_typesafe(const t_tscalar& rhs) const {
t_tscalar rval;
Expand Down
3 changes: 3 additions & 0 deletions cpp/perspective/src/cpp/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ rapidjson_type_to_dtype(const rapidjson::Value& value) {
case rapidjson::kArrayType:
PSP_COMPLAIN_AND_ABORT("Unknown JSON type");
return t_dtype::DTYPE_NONE;
default:
PSP_COMPLAIN_AND_ABORT("Unknown JSON type");
return t_dtype::DTYPE_NONE;
}
}

Expand Down
36 changes: 18 additions & 18 deletions cpp/perspective/src/include/perspective/computed_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ namespace computed_function {

// A regex function that caches its parsed regex objects.
#define REGEX_FUNCTION_HEADER(NAME) \
struct NAME : public exprtk::igeneric_function<t_tscalar> { \
struct NAME final : public exprtk::igeneric_function<t_tscalar> { \
NAME(t_regex_mapping& regex_mapping); \
~NAME(); \
t_tscalar operator()(t_parameter_list parameters); \
t_tscalar operator()(t_parameter_list parameters) override; \
t_regex_mapping& m_regex_mapping; \
};

// A regex function that returns a string stored in the expression vocab.
#define REGEX_STRING_FUNCTION_HEADER(NAME) \
struct NAME : public exprtk::igeneric_function<t_tscalar> { \
struct NAME final : public exprtk::igeneric_function<t_tscalar> { \
NAME( \
t_expression_vocab& expression_vocab, \
t_regex_mapping& regex_mapping, \
bool is_type_validator \
); \
~NAME(); \
t_tscalar operator()(t_parameter_list parameters); \
t_tscalar operator()(t_parameter_list parameters) override; \
t_expression_vocab& m_expression_vocab; \
t_regex_mapping& m_regex_mapping; \
bool m_is_type_validator; \
Expand All @@ -74,10 +74,10 @@ namespace computed_function {
// get_dtype, and because the gnode is guaranteed to be valid for all of
// those invocations, we can store a reference to the vocab.
#define STRING_FUNCTION_HEADER(NAME) \
struct NAME : public exprtk::igeneric_function<t_tscalar> { \
struct NAME final : public exprtk::igeneric_function<t_tscalar> { \
NAME(t_expression_vocab& expression_vocab, bool is_type_validator); \
~NAME(); \
t_tscalar operator()(t_parameter_list parameters); \
t_tscalar operator()(t_parameter_list parameters) override; \
t_expression_vocab& m_expression_vocab; \
t_tscalar m_sentinel; \
bool m_is_type_validator; \
Expand Down Expand Up @@ -111,11 +111,11 @@ namespace computed_function {
* Strings in the column not provided to `order()` will by default appear at
* the end.
*/
struct order : public exprtk::igeneric_function<t_tscalar> {
struct order final : public exprtk::igeneric_function<t_tscalar> {
order(bool is_type_validator);
~order();

t_tscalar operator()(t_parameter_list parameters);
t_tscalar operator()(t_parameter_list parameters) override;
void clear_order_map();

tsl::hopscotch_map<std::string, double> m_order_map;
Expand Down Expand Up @@ -179,37 +179,37 @@ namespace computed_function {
REGEX_STRING_FUNCTION_HEADER(replace_all)

#define FUNCTION_HEADER(NAME) \
struct NAME : public exprtk::igeneric_function<t_tscalar> { \
struct NAME final : public exprtk::igeneric_function<t_tscalar> { \
NAME(); \
~NAME(); \
t_tscalar operator()(t_parameter_list parameters); \
t_tscalar operator()(t_parameter_list parameters) override; \
};

// Length of the string
FUNCTION_HEADER(length)

struct index : public exprtk::igeneric_function<t_tscalar> {
struct index final : public exprtk::igeneric_function<t_tscalar> {
index(
const t_pkey_mapping& pkey_map,
std::shared_ptr<t_data_table> source_table,
t_uindex& row_idx
);
~index();
t_tscalar operator()(t_parameter_list parameters);
t_tscalar operator()(t_parameter_list parameters) override;

private:
const t_pkey_mapping& m_pkey_map;
std::shared_ptr<t_data_table> m_source_table;
t_uindex& m_row_idx;
};

struct col : public exprtk::igeneric_function<t_tscalar> {
struct col final : public exprtk::igeneric_function<t_tscalar> {
col(t_expression_vocab& expression_vocab,
bool is_type_validator,
std::shared_ptr<t_data_table> source_table,
t_uindex& row_idx);
~col();
t_tscalar operator()(t_parameter_list parameters);
t_tscalar operator()(t_parameter_list parameters) override;

private:
t_expression_vocab& m_expression_vocab;
Expand All @@ -218,15 +218,15 @@ namespace computed_function {
t_uindex& m_row_idx;
};

struct vlookup : public exprtk::igeneric_function<t_tscalar> {
struct vlookup final : public exprtk::igeneric_function<t_tscalar> {
vlookup(
t_expression_vocab& expression_vocab,
bool is_type_validator,
std::shared_ptr<t_data_table> source_table,
t_uindex& row_idx
);
~vlookup();
t_tscalar operator()(t_parameter_list parameters);
t_tscalar operator()(t_parameter_list parameters) override;

private:
t_expression_vocab& m_expression_vocab;
Expand Down Expand Up @@ -272,11 +272,11 @@ namespace computed_function {
*
* Any other inputs are invalid.
*/
struct bucket : public exprtk::igeneric_function<t_tscalar> {
struct bucket final : public exprtk::igeneric_function<t_tscalar> {
bucket();
~bucket();

t_tscalar operator()(t_parameter_list parameters);
t_tscalar operator()(t_parameter_list parameters) final;

// faster unit lookups, since we are calling this lookup in a tight
// loop.
Expand Down
Loading

0 comments on commit 2340bdb

Please sign in to comment.