LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
LMCAS::PiecewiseNode类 参考

分段函数节点,表示条件分支表达式. 更多...

#include </home/runner/work/docs/docs/LMCAS/src/internal/symbolic_ast/bindings.hpp>

类 LMCAS::PiecewiseNode 继承关系图:
LMCAS::PiecewiseNode 的协作图:

类

struct  Branch

Public 成员函数

void accept (LMCAS::detail::SymbolicVisitor &visitor) const override
const std::vector< Branch > & branches () const noexcept
std::shared_ptr< const SymbolicNode > clone () const override
int compare (const SymbolicNode &other) const
 与另一个节点进行全序比较.
const std::shared_ptr< const SymbolicNode > & default_expr () const noexcept
bool equals (const SymbolicNode &other) const
 判断两个节点是否结构相等.
std::size_t hash () const
 获取节点哈希值(带缓存).
virtual bool is_number () const
virtual bool is_one () const
virtual bool is_positive () const
virtual bool is_zero () const
int type_priority () const override

Protected 成员函数

int compare_same_type (const SymbolicNode &other) const override
std::size_t compute_hash () const override

Protected 属性

std::atomic< std::size_t > cached_hash {0}
std::atomic< bool > hash_computed {false}

Private 成员函数

 PiecewiseNode (std::vector< Branch > br, std::shared_ptr< const SymbolicNode > def=nullptr)
 构造分段函数节点.

Private 属性

const std::vector< Branch > branches_
const std::shared_ptr< const SymbolicNode > default_expr_
 LMCAS_AST_NODE_FACTORY_FRIEND

详细描述

分段函数节点,表示条件分支表达式.

存储有序的 (表达式, 条件) 对列表和可选的默认表达式. 条件应为 RelationalNode 或 LogicalNode 表达式.

在文件 bindings.hpp 第 12 行定义.


类说明

◆ LMCAS::PiecewiseNode::Branch

struct LMCAS::PiecewiseNode::Branch

在文件 bindings.hpp 第 14 行定义.

LMCAS::PiecewiseNode::Branch 的协作图:
类成员
shared_ptr< const SymbolicNode > condition 条件(RelationalNode 或 LogicalNode)。
shared_ptr< const SymbolicNode > expression 分支值。

构造及析构函数说明

◆ PiecewiseNode()

LMCAS::PiecewiseNode::PiecewiseNode ( std::vector< Branch > br,
std::shared_ptr< const SymbolicNode > def = nullptr )
inlineprivate

构造分段函数节点.

参数
br分支列表
def默认表达式(可为 nullptr)

在文件 bindings.hpp 第 30 行定义.

31 : branches_(std::move(br)), default_expr_(std::move(def)) {
32 if (branches_.empty()) {
33 throw std::invalid_argument("PiecewiseNode requires at least one branch");
34 }
35 for (const auto& branch : branches_) {
36 if (!branch.expression || !branch.condition) {
37 throw std::invalid_argument("PiecewiseNode branch fields cannot be null");
38 }
39 }
40 }
const std::vector< Branch > branches_
const std::shared_ptr< const SymbolicNode > default_expr_

引用了 branches_ , 以及 default_expr_.

被这些函数引用 compare_same_type().

这是这个函数的调用关系图:

成员函数说明

◆ accept()

void LMCAS::PiecewiseNode::accept ( LMCAS::detail::SymbolicVisitor & visitor) const
inlineoverridevirtual

实现了 LMCAS::SymbolicNode.

在文件 bindings.hpp 第 85 行定义.

85{ LMCAS::detail::SymbolicVisitor::DepthGuard guard(visitor); visitor.visit(*this); }
virtual void visit(const NumberNode &node)=0

引用了 LMCAS::detail::SymbolicVisitor::visit().

函数调用图:

◆ branches()

◆ clone()

std::shared_ptr< const SymbolicNode > LMCAS::PiecewiseNode::clone ( ) const
inlineoverridevirtual

实现了 LMCAS::SymbolicNode.

在文件 bindings.hpp 第 87 行定义.

87 {
88 std::vector<Branch> new_branches;
89 new_branches.reserve(branches_.size());
90 for (const auto& b : branches_) {
91 new_branches.push_back({b.expression->clone(), b.condition->clone()});
92 }
93 auto new_def = default_expr_ ? default_expr_->clone() : nullptr;
94 return LMCAS::detail::make_node<PiecewiseNode>(std::move(new_branches), std::move(new_def));
95 }
std::shared_ptr< const Node > make_node(Args &&... args)
const MultiPoly & b

引用了 LMCAS::b, branches_, default_expr_ , 以及 LMCAS::detail::make_node().

函数调用图:

◆ compare()

int LMCAS::SymbolicNode::compare ( const SymbolicNode & other) const
inlineinherited

与另一个节点进行全序比较.

参数
other待比较的节点
返回
小于返回 -1,等于返回 0,大于返回 1

在文件 base.hpp 第 183 行定义.

183 {
184 if (type_priority() != other.type_priority()) {
185 return type_priority() < other.type_priority() ? -1 : 1;
186 }
187 return compare_same_type(other);
188 }
virtual int compare_same_type(const SymbolicNode &other) const =0
virtual int type_priority() const =0

引用了 SymbolicNode(), compare_same_type() , 以及 type_priority().

被这些函数引用 LMCAS::anonymous_namespace{symbolic_cancel.cpp}::combine_fraction_terms() , 以及 LMCAS::endpoints_equivalent().

函数调用图:
这是这个函数的调用关系图:

◆ compare_same_type()

int LMCAS::PiecewiseNode::compare_same_type ( const SymbolicNode & other) const
inlineoverrideprotectedvirtual

实现了 LMCAS::SymbolicNode.

在文件 bindings.hpp 第 64 行定义.

64 {
65 const auto& o = static_cast<const PiecewiseNode&>(other);
66 if (branches_.size() != o.branches_.size()) {
67 return branches_.size() < o.branches_.size() ? -1 : 1;
68 }
69 for (size_t i = 0; i < branches_.size(); ++i) {
70 int cmp = branches_[i].expression->compare(*o.branches_[i].expression);
71 if (cmp != 0) return cmp;
72 cmp = branches_[i].condition->compare(*o.branches_[i].condition);
73 if (cmp != 0) return cmp;
74 }
75 bool has_def = (default_expr_ != nullptr);
76 bool o_has_def = (o.default_expr_ != nullptr);
77 if (has_def != o_has_def) return has_def ? 1 : -1;
78 if (has_def && o_has_def) {
79 return default_expr_->compare(*o.default_expr_);
80 }
81 return 0;
82 }
PiecewiseNode(std::vector< Branch > br, std::shared_ptr< const SymbolicNode > def=nullptr)
构造分段函数节点.

引用了 PiecewiseNode(), LMCAS::SymbolicNode::SymbolicNode(), branches_ , 以及 default_expr_.

函数调用图:

◆ compute_hash()

std::size_t LMCAS::PiecewiseNode::compute_hash ( ) const
inlineoverrideprotectedvirtual

实现了 LMCAS::SymbolicNode.

在文件 bindings.hpp 第 51 行定义.

51 {
52 std::size_t seed = 0;
54 for (const auto& b : branches_) {
55 hash_combine(seed, b.expression->hash());
56 hash_combine(seed, b.condition->hash());
57 }
58 if (default_expr_) {
59 hash_combine(seed, default_expr_->hash());
60 }
61 return seed;
62 }
int type_priority() const override
void hash_combine(std::size_t &seed, std::size_t value)
将一个哈希值混合到种子中,用于组合多个字段的哈希.

引用了 LMCAS::b, branches_, default_expr_, LMCAS::hash_combine() , 以及 type_priority().

函数调用图:

◆ default_expr()

◆ equals()

bool LMCAS::SymbolicNode::equals ( const SymbolicNode & other) const
inlineinherited

判断两个节点是否结构相等.

参数
other待比较的节点
返回
相等返回 true

在文件 base.hpp 第 195 行定义.

195 {
196 if (this == &other) return true;
197 if (hash() != other.hash()) return false;
198 if (type_priority() != other.type_priority()) return false;
199 return compare_same_type(other) == 0;
200 }
std::size_t hash() const
获取节点哈希值(带缓存).

引用了 SymbolicNode(), compare_same_type(), hash() , 以及 type_priority().

被这些函数引用 LMCAS::complementary_square(), LMCAS::anonymous_namespace{relation_store.cpp}::expr_equals(), LMCAS::match_recursive(), LMCAS::tf_remove_exp_factor() , 以及 LMCAS::tf_substitute_expr().

函数调用图:
这是这个函数的调用关系图:

◆ hash()

std::size_t LMCAS::SymbolicNode::hash ( ) const
inlineinherited

获取节点哈希值(带缓存).

返回
哈希值

在文件 base.hpp 第 168 行定义.

168 {
169 if (!hash_computed.load(std::memory_order_acquire)) {
170 std::size_t h = compute_hash();
171 cached_hash.store(h, std::memory_order_relaxed);
172 hash_computed.store(true, std::memory_order_release);
173 return h;
174 }
175 return cached_hash.load(std::memory_order_relaxed);
176 }
virtual std::size_t compute_hash() const =0
std::atomic< std::size_t > cached_hash
std::atomic< bool > hash_computed

引用了 cached_hash, compute_hash() , 以及 hash_computed.

被这些函数引用 LMCAS::MatrixNode::compute_hash(), LMCAS::VariableNode::compute_hash() , 以及 equals().

函数调用图:
这是这个函数的调用关系图:

◆ is_number()

virtual bool LMCAS::SymbolicNode::is_number ( ) const
inlinevirtualinherited

被 LMCAS::NumberNode 重载.

在文件 base.hpp 第 201 行定义.

201{ return false; }

◆ is_one()

virtual bool LMCAS::SymbolicNode::is_one ( ) const
inlinevirtualinherited

被 LMCAS::NumberNode 重载.

在文件 base.hpp 第 202 行定义.

202{ return false; }

◆ is_positive()

virtual bool LMCAS::SymbolicNode::is_positive ( ) const
inlinevirtualinherited

被 LMCAS::NumberNode 重载.

在文件 base.hpp 第 204 行定义.

204{ return false; }

◆ is_zero()

virtual bool LMCAS::SymbolicNode::is_zero ( ) const
inlinevirtualinherited

◆ type_priority()

int LMCAS::PiecewiseNode::type_priority ( ) const
inlineoverridevirtual

实现了 LMCAS::SymbolicNode.

在文件 bindings.hpp 第 48 行定义.

48{ return 7; }

被这些函数引用 compute_hash().

这是这个函数的调用关系图:

类成员变量说明

◆ branches_

const std::vector<Branch> LMCAS::PiecewiseNode::branches_
private

在文件 bindings.hpp 第 22 行定义.

被这些函数引用 PiecewiseNode(), branches(), clone(), compare_same_type() , 以及 compute_hash().

◆ cached_hash

std::atomic<std::size_t> LMCAS::SymbolicNode::cached_hash {0}
mutableprotectedinherited

在文件 base.hpp 第 149 行定义.

被这些函数引用 SymbolicNode() , 以及 hash().

◆ default_expr_

const std::shared_ptr<const SymbolicNode> LMCAS::PiecewiseNode::default_expr_
private

在文件 bindings.hpp 第 23 行定义.

被这些函数引用 PiecewiseNode(), clone(), compare_same_type(), compute_hash() , 以及 default_expr().

◆ hash_computed

std::atomic<bool> LMCAS::SymbolicNode::hash_computed {false}
mutableprotectedinherited

在文件 base.hpp 第 150 行定义.

被这些函数引用 SymbolicNode() , 以及 hash().

◆ LMCAS_AST_NODE_FACTORY_FRIEND

LMCAS::PiecewiseNode::LMCAS_AST_NODE_FACTORY_FRIEND
private

在文件 bindings.hpp 第 20 行定义.


该类的文档由以下文件生成: