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

#[], #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)


345
346
347
# File 'lib/immutable/map.rb', line 345

def black?
  false
end

#ins(key, value) ⇒ Object



357
358
359
360
361
362
363
364
365
366
# File 'lib/immutable/map.rb', line 357

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



353
354
355
# File 'lib/immutable/map.rb', line 353

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

#make_redObject



349
350
351
# File 'lib/immutable/map.rb', line 349

def make_red
  self
end

#red?Boolean

Returns:

  • (Boolean)


341
342
343
# File 'lib/immutable/map.rb', line 341

def red?
  true
end