Class: Datadog::DI::SnapshotPruner::Node Private
- Inherits:
-
Object
- Object
- Datadog::DI::SnapshotPruner::Node
- Defined in:
- lib/datadog/di/snapshot_pruner/node.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A JSON object of an encoded snapshot: its byte range, its nesting level, its parent and child objects, and the flags that rank it for pruning.
Constant Summary collapse
- PRUNE_FIRST_BIT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Bit of the packed priority set for an object truncated for depth or promoted to a pruning candidate, ranking it ahead of every object without the bit.
1 << 61
- LEVEL_SHIFT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Shift of the level within the packed priority.
44- NOT_CAPTURED_BIT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Bit of the packed priority set for an object carrying a
notCapturedReason. 1 << 43
Instance Attribute Summary collapse
-
#children ⇒ Array<Node>
readonly
private
The objects nested directly in this object.
-
#end_offset ⇒ Integer
readonly
private
The byte offset just after the object's closing brace.
-
#level ⇒ Integer
readonly
private
The nesting level of the object, 0 for the root object.
-
#not_captured ⇒ Boolean
(also: #not_captured?)
readonly
private
Whether the object carries a
notCapturedReasonmember. -
#not_captured_depth ⇒ Boolean
(also: #not_captured_depth?)
readonly
private
Whether the object's
notCapturedReasonisdepth. -
#parent ⇒ Node?
readonly
private
The enclosing object, nil for the root object.
-
#promoted ⇒ Boolean
(also: #promoted?)
readonly
private
Whether the object was promoted to a pruning candidate because all of its children were resolved.
-
#pruned_child_count ⇒ Integer
readonly
private
The number of children already resolved from the pruning queue, whether selected for pruning or subsumed by promotion.
-
#start_offset ⇒ Integer
readonly
private
The byte offset of the object's opening brace.
Instance Method Summary collapse
-
#add_child(child) ⇒ void
private
Appends a directly nested object.
-
#all_children_pruned? ⇒ Boolean
private
Returns whether every child has been resolved from the pruning queue.
-
#close(end_offset) ⇒ void
private
Records the position of the object's closing brace.
-
#each_leaf {|leaf| ... } ⇒ void
private
Yields every leaf of the subtree.
-
#initialize(start_offset:, level:, parent:) ⇒ void
constructor
private
Initializes an open object whose closing brace has not been read.
-
#leaf? ⇒ Boolean
private
Returns whether the object is a leaf.
-
#mark_not_captured ⇒ void
private
Flags the object as carrying a
notCapturedReasonmember. -
#mark_not_captured_depth ⇒ void
private
Flags the object as truncated for depth.
-
#priority ⇒ Integer
private
Packs the pruning sort key (prune-first bit, level, not-captured flag, size) into one Integer, so that ranking two objects is one Integer comparison.
-
#promote ⇒ void
private
Turns the object, whose children are all selected, into a pruning candidate that ranks ahead of every object without the prune-first bit.
-
#record_pruned_child ⇒ void
private
Records one child resolved from the pruning queue.
-
#size ⇒ Integer
private
Returns the encoded size of the object.
Constructor Details
#initialize(start_offset:, level:, parent:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes an open object whose closing brace has not been read.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 30 def initialize(start_offset:, level:, parent:) @start_offset = start_offset @end_offset = start_offset @level = level @parent = parent @children = [] @pruned_child_count = 0 @not_captured = false @not_captured_depth = false @promoted = false end |
Instance Attribute Details
#children ⇒ Array<Node> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The objects nested directly in this object.
60 61 62 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 60 def children @children end |
#end_offset ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The byte offset just after the object's closing brace.
48 49 50 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 48 def end_offset @end_offset end |
#level ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The nesting level of the object, 0 for the root object.
52 53 54 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 52 def level @level end |
#not_captured ⇒ Boolean (readonly) Also known as: not_captured?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether the object carries a notCapturedReason member.
69 70 71 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 69 def not_captured @not_captured end |
#not_captured_depth ⇒ Boolean (readonly) Also known as: not_captured_depth?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether the object's notCapturedReason is depth.
74 75 76 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 74 def not_captured_depth @not_captured_depth end |
#parent ⇒ Node? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The enclosing object, nil for the root object.
56 57 58 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 56 def parent @parent end |
#promoted ⇒ Boolean (readonly) Also known as: promoted?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether the object was promoted to a pruning candidate because all of its children were resolved.
80 81 82 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 80 def promoted @promoted end |
#pruned_child_count ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The number of children already resolved from the pruning queue, whether selected for pruning or subsumed by promotion.
65 66 67 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 65 def pruned_child_count @pruned_child_count end |
#start_offset ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The byte offset of the object's opening brace.
44 45 46 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 44 def start_offset @start_offset end |
Instance Method Details
#add_child(child) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Appends a directly nested object.
116 117 118 119 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 116 def add_child(child) children << child nil end |
#all_children_pruned? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether every child has been resolved from the pruning queue.
158 159 160 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 158 def all_children_pruned? pruned_child_count >= children.size end |
#close(end_offset) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Records the position of the object's closing brace.
125 126 127 128 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 125 def close(end_offset) @end_offset = end_offset nil end |
#each_leaf {|leaf| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Yields every leaf of the subtree.
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 176 def each_leaf pending = [self] #: Array[Node] while (node = pending.pop) if node.leaf? yield node else pending.concat(node.children) end end nil end |
#leaf? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether the object is a leaf.
93 94 95 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 93 def leaf? children.empty? end |
#mark_not_captured ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Flags the object as carrying a notCapturedReason member.
133 134 135 136 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 133 def mark_not_captured @not_captured = true nil end |
#mark_not_captured_depth ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Flags the object as truncated for depth.
141 142 143 144 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 141 def mark_not_captured_depth @not_captured_depth = true nil end |
#priority ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Packs the pruning sort key (prune-first bit, level, not-captured flag, size) into one Integer, so that ranking two objects is one Integer comparison. The prune-first bit is set for an object truncated for depth and for an object promoted to a pruning candidate. The fields fit below 262 for levels below 217 and sizes below 2**43 bytes.
105 106 107 108 109 110 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 105 def priority @priority ||= ((not_captured_depth? || promoted?) ? PRUNE_FIRST_BIT : 0) | (level << LEVEL_SHIFT) | (not_captured? ? NOT_CAPTURED_BIT : 0) | size end |
#promote ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Turns the object, whose children are all selected, into a pruning candidate that ranks ahead of every object without the prune-first bit.
167 168 169 170 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 167 def promote @promoted = true @priority = nil end |
#record_pruned_child ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Records one child resolved from the pruning queue.
149 150 151 152 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 149 def record_pruned_child @pruned_child_count = pruned_child_count + 1 nil end |
#size ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the encoded size of the object.
86 87 88 |
# File 'lib/datadog/di/snapshot_pruner/node.rb', line 86 def size end_offset - start_offset end |