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?, extract, #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

#length, #product, #sum

Constructor Details

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

Instance Method Details

#black?Boolean

Returns:

  • (Boolean)


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

def black?
  false
end

#ins(key, value) ⇒ Object



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

def ins(key, value)
  if key < self.key
    RedFork[left.ins(key, value), self.key, self.value, right]
  elsif key > self.key
    RedFork[left, self.key, self.value, right.ins(key, value)]
  else
    RedFork[left, key, value, right]
  end
end

#make_blackObject



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

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

#make_redObject



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

def make_red
  self
end

#red?Boolean

Returns:

  • (Boolean)


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

def red?
  true
end