Class: Immutable::Map::RedFork

Inherits:
Fork show all
Defined in:
lib/immutable/map.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Immutable::Map

Leaf

Instance Attribute Summary

Attributes inherited from Fork

#key, #left, #right, #value

Instance Method Summary collapse

Methods inherited from Fork

#[], #del, #empty?, #foldl_with_key, #foldr_with_key, #initialize

Methods inherited from Immutable::Map

#[], [], #delete, #each, empty, #foldl, #foldr, #insert, #inspect, #map, #map_with_key, singleton

Methods included from Foldable

#foldl, #length, #product, #sum

Constructor Details

This class inherits a constructor from Immutable::Map::Fork

Instance Method Details

#black?Boolean

Returns:

  • (Boolean)


331
332
333
# File 'lib/immutable/map.rb', line 331

def black?
  false
end

#ins(key, value) ⇒ Object



343
344
345
346
347
348
349
350
351
352
# File 'lib/immutable/map.rb', line 343

def ins(key, value)
  x = key <=> @key
  if x < 0
    RedFork[@left.ins(key, value), @key, @value, @right]
  elsif x > 0
    RedFork[@left, @key, @value, @right.ins(key, value)]
  else
    RedFork[@left, key, value, @right]
  end
end

#make_blackObject



339
340
341
# File 'lib/immutable/map.rb', line 339

def make_black
  BlackFork[left, key, value, right]
end

#make_redObject



335
336
337
# File 'lib/immutable/map.rb', line 335

def make_red
  self
end

#red?Boolean

Returns:

  • (Boolean)


327
328
329
# File 'lib/immutable/map.rb', line 327

def red?
  true
end