Class: Canon::TreeDiff::Core::NodeSignature
- Inherits:
-
Object
- Object
- Canon::TreeDiff::Core::NodeSignature
- Defined in:
- lib/canon/tree_diff/core/node_signature.rb
Overview
NodeSignature computes unique signatures for tree nodes
Based on XDiff (2002, U. Wisconsin) approach:
-
Signature is the path from root to node
-
Format: /ancestor1/ancestor2/…/node/type
-
Used for fast exact matching via hash lookup
Features:
-
Deterministic: Same path always produces same signature
-
Hierarchical: Parent-child relationships encoded
-
Type-aware: Distinguishes element vs text nodes
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#signature_string ⇒ Object
readonly
Returns the value of attribute signature_string.
Class Method Summary collapse
-
.for(node, include_attributes: true) ⇒ NodeSignature
Compute and cache signature for a node.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Check if two signatures are equal.
-
#hash ⇒ Integer
Hash value for use in Hash/Set.
-
#initialize(node, include_attributes: true) ⇒ NodeSignature
constructor
Initialize signature for a node.
-
#inspect ⇒ String
Detailed inspection.
-
#to_s ⇒ String
String representation.
Constructor Details
#initialize(node, include_attributes: true) ⇒ NodeSignature
Initialize signature for a node
24 25 26 27 28 29 |
# File 'lib/canon/tree_diff/core/node_signature.rb', line 24 def initialize(node, include_attributes: true) @node = node @include_attributes = include_attributes @path = compute_path @signature_string = compute_signature_string end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'lib/canon/tree_diff/core/node_signature.rb', line 18 def path @path end |
#signature_string ⇒ Object (readonly)
Returns the value of attribute signature_string.
18 19 20 |
# File 'lib/canon/tree_diff/core/node_signature.rb', line 18 def signature_string @signature_string end |
Class Method Details
.for(node, include_attributes: true) ⇒ NodeSignature
Compute and cache signature for a node
36 37 38 39 40 41 42 43 |
# File 'lib/canon/tree_diff/core/node_signature.rb', line 36 def self.for(node, include_attributes: true) if include_attributes node.signature ||= new(node, include_attributes: true) else # Don't cache loose signatures new(node, include_attributes: false) end end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Check if two signatures are equal
49 50 51 52 53 |
# File 'lib/canon/tree_diff/core/node_signature.rb', line 49 def ==(other) return false unless other.is_a?(NodeSignature) signature_string == other.signature_string end |
#hash ⇒ Integer
Hash value for use in Hash/Set
60 61 62 |
# File 'lib/canon/tree_diff/core/node_signature.rb', line 60 def hash signature_string.hash end |
#inspect ⇒ String
Detailed inspection
74 75 76 |
# File 'lib/canon/tree_diff/core/node_signature.rb', line 74 def inspect "#<NodeSignature #{signature_string.inspect}>" end |
#to_s ⇒ String
String representation
67 68 69 |
# File 'lib/canon/tree_diff/core/node_signature.rb', line 67 def to_s signature_string end |