Class: Immutable::Map::BlackFork

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

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

Methods inherited from Immutable::Map

#==, [], #[], #delete, #each, empty, #eql?, #foldl, #foldr, #hash, #insert, #inspect, #map, #map_with_key, singleton, #to_h

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)


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_blackObject



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

def make_black
  self
end

#make_redObject



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