Class: Yk::EMap

Inherits:
Object
  • Object
show all
Defined in:
for_yard_product.rb

Overview

EMaps are associative containers with external iterators that store elements formed by a combination of a key and a value, following a specific order. For use, require 'Yk/ESet';include Yk;

Defined Under Namespace

Classes: Iterator

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|key| ... } ⇒ EMap

initlialize with a block which returns comparing basis like Enumerable::sort_by, however using <, not <=>.

Yield Parameters:

  • key (Object)

    object pointed by an element.

Yield Returns:

  • (Object)

    should be comparable with method, '<'.



196
197
# File 'for_yard_product.rb', line 196

def initialize
end

Class Method Details

.find(first, last, obj = nil) {|obj| ... } ⇒ EMap::Iterator

Searches the container for an element with an object equivalent to the third argument and/or validated with the provided block in a range of elements ([first,last)), 'obj' and returns an iterator to it if found, otherwise it returns an iterator to .

Parameters:

  • first (EMap::Iterator)

    first iterator.

  • last (EMap::Iterator)

    last iterator.

  • obj (defaults to: nil)

    Object to search equivalency.

Yield Parameters:

  • obj (Object)

    object argument pointed by an element passed for validation with the block

Yield Returns:

  • (Object)

    validation result from the block

Returns:

  • (EMap::Iterator)

    iterator pointing the element with equivalent object.

Raises:

  • ArgumentError raised when an argument is not a compatible iterator.

  • ArgumentError raised when first and last iterators are not from the same container.

  • ArgumentError raised when neither parameter, obj nor block is provided.

  • RangeError raised when dereferencing end iterator



262
263
# File 'for_yard_product.rb', line 262

def EMap.find first, last, obj = nil
end

.for_each(first, last) {|obj| ... } ⇒ Object

Applies given block to each of the elements in the range [first,last).

Parameters:

Yield Parameters:

  • obj (Object)

    object in an element

Raises:

  • ArgumentError raised when an argument is not a compatible iterator.

  • ArgumentError raised when first and last iterators are not from the same container.



270
271
# File 'for_yard_product.rb', line 270

def EMap.for_each first, last
end

Instance Method Details

#beginEMap::Iterator

Return iterator to beginning

Returns:



199
200
# File 'for_yard_product.rb', line 199

def begin
end

#clearObject

Clear content



208
209
# File 'for_yard_product.rb', line 208

def clear
end

#endEMap::Iterator

Return iterator to end

Returns:



202
203
# File 'for_yard_product.rb', line 202

def end
end

#erase(first, last) ⇒ Object

Removes from the set container a range of elements ([first,last)). Iterators specifying a range within the set container to be removed: [first,last). i.e., the range includes all the elements between first and last, including the element pointed by first but not the one pointed by last.

Parameters:

Raises:

  • ArgumentError raised when an argument is not a compatible iterator.

  • ArgumentError raised when first and last iterators are not from the same container.

  • RangeError raised when erasing end iterator



249
250
# File 'for_yard_product.rb', line 249

def erase first, last
end

#insert(position, key, value) ⇒ EMap::Iterator #insert(key, value) ⇒ Array

Overloads:

  • #insert(position, key, value) ⇒ EMap::Iterator

    Insert element with an object using a hint

    Parameters:

    • position (EMap::Iterator)

      Hint for the position where the element can be inserted.

    • key (Object)

      key object to be pointed by the inserted elements.

    • value (Object)

      value object to be pointed by the inserted elements.

    Returns:

    • (EMap::Iterator)

      An iterator pointing to either the newly inserted element or to the element that already had its equivalent in the container.

  • #insert(key, value) ⇒ Array

    Insert element with an object

    Parameters:

    • key (Object)

      key object to be pointed by the inserted elements.

    • value (Object)

      value object to be pointed by the inserted elements.

    Returns:

    • (Array)

      An array, with its first member set to an iterator pointing to either the newly inserted element or to the equivalent element already in the set. The second member in the array is set to true if a new element was inserted or false if an equivalent element already existed.



227
228
# File 'for_yard_product.rb', line 227

def insert *args
end

#insert_or_assign(k, v) ⇒ Array #insert_or_assign(position, k, v) ⇒ EMap::Iterator

Overloads:

  • #insert_or_assign(k, v) ⇒ Array

    If a key equivalent to 'k' already exists in the container, assigns 'v' to value corresponding to the key. If the key does not exist, inserts the new value as if by insert.

    Parameters:

    • k (Object)

      key object

    • v (Object)

      value object

    Returns:

    • (Array)

      An array, with its first member set to an iterator pointing to either the newly inserted element or to the equivalent element already in the set. The second member in the array is set to true if a new element was inserted or false if an equivalent element already existed.

  • #insert_or_assign(position, k, v) ⇒ EMap::Iterator

    Insert element with key and value using a hint

    Parameters:

    • position (EMap::Iterator)

      Hint for the position where the element can be inserted.

    • k (Object)

      key object

    • v (Object)

      value object

    Returns:

    • (EMap::Iterator)

      Iterator pointing at the element that was inserted or updated



240
241
# File 'for_yard_product.rb', line 240

def insert_or_assign *args
end

#lower_boundEMap::Iterator

Return iterator to lower bound

Returns:



214
215
# File 'for_yard_product.rb', line 214

def lower_bound 
end

#sizeInteger

Return container size

Returns:

  • (Integer)

    Return container size



205
206
# File 'for_yard_product.rb', line 205

def size
end

#upper_boundEMap::Iterator

Return iterator to upper bound

Returns:



211
212
# File 'for_yard_product.rb', line 211

def upper_bound
end