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, '<'.



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

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



272
273
# File 'for_yard_product.rb', line 272

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.



280
281
# File 'for_yard_product.rb', line 280

def EMap.for_each first, last
end

Instance Method Details

#beginEMap::Iterator

Return iterator to beginning

Returns:



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

def begin
end

#clearObject

Clear content



218
219
# File 'for_yard_product.rb', line 218

def clear
end

#endEMap::Iterator

Return iterator to end

Returns:



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

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



259
260
# File 'for_yard_product.rb', line 259

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.



237
238
# File 'for_yard_product.rb', line 237

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



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

def insert_or_assign *args
end

#lower_boundEMap::Iterator

Return iterator to lower bound

Returns:



224
225
# File 'for_yard_product.rb', line 224

def lower_bound 
end

#sizeInteger

Return container size

Returns:

  • (Integer)

    Return container size



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

def size
end

#upper_boundEMap::Iterator

Return iterator to upper bound

Returns:



221
222
# File 'for_yard_product.rb', line 221

def upper_bound
end