Class: Immutable::Map::BlackFork

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

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Fork

#key, #left, #right, #value

Instance Method Summary collapse

Methods inherited from Fork

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

Constructor Details

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

Instance Method Details

#black? ⇒ Boolean

Returns:

  • (Boolean)


374
375
376
# File 'lib/immutable/map.rb', line 374

def black?
  true
end

#ins(key, value) ⇒ Object



386
387
388
389
390
391
392
393
394
395
# File 'lib/immutable/map.rb', line 386

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

#make_black ⇒ Object



382
383
384
# File 'lib/immutable/map.rb', line 382

def make_black
  self
end

#make_red ⇒ Object



378
379
380
# File 'lib/immutable/map.rb', line 378

def make_red
  RedFork[left, key, value, right]
end

#red? ⇒ Boolean

Returns:

  • (Boolean)


370
371
372
# File 'lib/immutable/map.rb', line 370

def red?
  false
end