Class: Immutable::Map::Fork
- Inherits:
-
Immutable::Map
- Object
- Immutable::Map
- Immutable::Map::Fork
- Defined in:
- lib/immutable/map.rb
Overview
:nodoc:
Constant Summary
Constants inherited from Immutable::Map
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #del(key) ⇒ Object
- #each {|key, value| ... } ⇒ Object
- #empty? ⇒ Boolean
- #foldl_with_key(e, &block) ⇒ Object
- #foldr_with_key(e, &block) ⇒ Object
-
#initialize(left, key, value, right) ⇒ Fork
constructor
A new instance of Fork.
Methods inherited from Immutable::Map
#delete, empty, #foldl, #foldr, #insert, #inspect, #map, #map_with_key, singleton
Constructor Details
#initialize(left, key, value, right) ⇒ Fork
Returns a new instance of Fork.
131 132 133 |
# File 'lib/immutable/map.rb', line 131 def initialize(left, key, value, right) @left, @key, @value, @right = left, key, value, right end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
129 130 131 |
# File 'lib/immutable/map.rb', line 129 def key @key end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
129 130 131 |
# File 'lib/immutable/map.rb', line 129 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
129 130 131 |
# File 'lib/immutable/map.rb', line 129 def right @right end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
129 130 131 |
# File 'lib/immutable/map.rb', line 129 def value @value end |
Class Method Details
.extract(val) ⇒ Object
135 136 137 138 |
# File 'lib/immutable/map.rb', line 135 def self.extract(val) accept_self_instance_only(val) [val.left, val.key, val.value, val.right] end |
Instance Method Details
#[](key) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/immutable/map.rb', line 148 def [](key) if key < self.key left[key] elsif key > self.key right[key] else value end end |
#del(key) ⇒ Object
158 159 160 161 162 163 164 165 166 |
# File 'lib/immutable/map.rb', line 158 def del(key) if key < self.key del_left(left, self.key, self.value, right, key) elsif key > self.key del_right(left, self.key, self.value, right, key) else app(left, right) end end |
#each {|key, value| ... } ⇒ Object
168 169 170 171 172 |
# File 'lib/immutable/map.rb', line 168 def each(&block) left.each(&block) yield key, value right.each(&block) end |
#empty? ⇒ Boolean
144 145 146 |
# File 'lib/immutable/map.rb', line 144 def empty? false end |
#foldl_with_key(e, &block) ⇒ Object
187 188 189 190 |
# File 'lib/immutable/map.rb', line 187 def foldl_with_key(e, &block) l = @left.foldl_with_key(e, &block) @right.foldl_with_key(yield(l, @key, @value), &block) end |
#foldr_with_key(e, &block) ⇒ Object
178 179 180 181 |
# File 'lib/immutable/map.rb', line 178 def foldr_with_key(e, &block) r = @right.foldr_with_key(e, &block) @left.foldr_with_key(yield(@key, @value, r), &block) end |