Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

状态类型系统增加对数值状态类型的支持 #212

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

zhaoxi-scut
Copy link
Member

Pull Request 合并请求准备清单

详情参见此处

  • 我同意在 Apache 2 开源许可下为本项目做贡献
  • 此 pull request 是在正确的分支上提出的
  • 此 pull request 有对应的错误报告或其他待改进的内容
  • 我本地的 RMVL 进行了单元测试、性能测试,有对应的测试数据
  • 我提交的 feature 有很好的文档记录,并且可以使用 CMake 项目构建示例代码

具体内容

  • 原先的状态类型由

    std::unordered_map<std::string, std::string> _states;

    所管理,现改为

    std::unordered_map<std::string, rm::StateType> _states;

    其中 rm::StateType

    std::variant<double, std::string>
  • 修改 add 接口,改为

    // 添加数值状态
    RMVL_W void add(std::string_view key, double val);
    
    // 添加字符串状态
    RMVL_W void add(std::string_view key, std::string_view str);

    两个重载版本

  • 原先的 at(std::string_view key) const; 改为 at_numericat_string 两个成员函数,用于获取不同类型的状态

本地单元测试结果

[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from RMStatus_test
[ RUN      ] RMStatus_test.add_type
[       OK ] RMStatus_test.add_type (0 ms)
[----------] 1 test from RMStatus_test (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[  PASSED  ] 1 test.

本地基准测试结果

-----------------------------------------------------------------------------------------------
Benchmark                                                     Time             CPU   Iterations
-----------------------------------------------------------------------------------------------
enum types (init x3, modify x3)/iterations:50000           1.77 ns         1.76 ns        50000
string states (init x3, modify x3)/iterations:50000         130 ns          130 ns        50000
numeric states (init x3, modify x3)/iterations:50000        124 ns          124 ns        50000

@zhaoxi-scut zhaoxi-scut added feature 新特性、新功能 optimization 代码重构、功能优化 labels Jan 9, 2025
@zhaoxi-scut zhaoxi-scut added this to the 2.2.0 milestone Jan 9, 2025
@TooPretty0108 TooPretty0108 force-pushed the add-numeric-to-stateinfo branch from e1e88f1 to 453400c Compare January 9, 2025 07:11
@TooPretty0108 TooPretty0108 merged commit 254fbc1 into cv-rmvl:2.x Jan 9, 2025
8 checks passed
@zhaoxi-scut zhaoxi-scut deleted the add-numeric-to-stateinfo branch January 9, 2025 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 新特性、新功能 optimization 代码重构、功能优化
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants