Class: Puppet::RbTreeMap::Node
- Defined in:
- lib/vendor/puppet/rb_tree_map.rb
Overview
:nodoc: all
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#key ⇒ Object
Returns the value of attribute key.
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #colorflip ⇒ Object
- #fixup ⇒ Object
-
#initialize(key, value) ⇒ Node
constructor
A new instance of Node.
- #move_red_left ⇒ Object
- #move_red_right ⇒ Object
- #red? ⇒ Boolean
- #rotate_left ⇒ Object
- #rotate_right ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(key, value) ⇒ Node
Returns a new instance of Node.
200 201 202 203 204 205 206 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 200 def initialize(key, value) @key = key @value = value @color = :red @left = nil @right = nil end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
199 200 201 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 199 def color @color end |
#key ⇒ Object
Returns the value of attribute key.
199 200 201 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 199 def key @key end |
#left ⇒ Object
Returns the value of attribute left.
199 200 201 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 199 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
199 200 201 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 199 def right @right end |
#value ⇒ Object
Returns the value of attribute value.
199 200 201 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 199 def value @value end |
Instance Method Details
#colorflip ⇒ Object
225 226 227 228 229 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 225 def colorflip @color = @color == :red ? :black : :red @left.color = @left.color == :red ? :black : :red @right.color = @right.color == :red ? :black : :red end |
#fixup ⇒ Object
276 277 278 279 280 281 282 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 276 def fixup rotate_left if @right && @right.red? rotate_right if (@left && @left.red?) && (@left.left && @left.left.red?) colorflip if (@left && @left.red?) && (@right && @right.red?) self end |
#move_red_left ⇒ Object
257 258 259 260 261 262 263 264 265 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 257 def move_red_left colorflip if (@right.left && @right.left.red?) @right.rotate_right rotate_left colorflip end self end |
#move_red_right ⇒ Object
267 268 269 270 271 272 273 274 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 267 def move_red_right colorflip if (@left.left && @left.left.red?) rotate_right colorflip end self end |
#red? ⇒ Boolean
221 222 223 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 221 def red? @color == :red end |
#rotate_left ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 231 def rotate_left r = @right r_key, r_value, r_color = r.key, r.value, r.color b = r.left r.left = @left @left = r @right = r.right r.right = b r.color, r.key, r.value = :red, @key, @value @key, @value = r_key, r_value self end |
#rotate_right ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 244 def rotate_right l = @left l_key, l_value, l_color = l.key, l.value, l.color b = l.right l.right = @right @right = l @left = l.left l.left = b l.color, l.key, l.value = :red, @key, @value @key, @value = l_key, l_value self end |
#to_hash ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/vendor/puppet/rb_tree_map.rb', line 208 def to_hash h = { :node => { :key => @key, :value => @value, :color => @color, } } h.merge!(:left => left.to_hash) if @left h.merge!(:right => right.to_hash) if @right h end |