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



288
289
# File 'for_yard_product.rb', line 288

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 (Object) (defaults to: nil)

    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.

  • ArgumentError raised when using argument(s) with erased position

  • RangeError raised when dereferencing end iterator



381
382
# File 'for_yard_product.rb', line 381

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.

  • ArgumentError raised when using argument(s) with erased position



390
391
# File 'for_yard_product.rb', line 390

def EMap.for_each first, last
end

Instance Method Details

#add(position, key, value) ⇒ True|False #add(key, value) ⇒ True|False

Overloads:

  • #add(position, key, value) ⇒ True|False

    Insert element with an object using a hint and return true if a new element was inserted or false if an equivalent element already existed. Do not return iterator object. More efficient if you do not need inserted position (removed by GC).

    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:

    • (True|False)

      true if a new element was inserted or false if an equivalent element already existed.

  • #add(key, value) ⇒ True|False

    Insert element with an object and return true if a new element was inserted or false if an equivalent element already existed. Do not return iterator object. More efficient if you do not need inserted position (removed by GC).

    Parameters:

    • key (Object)

      key object to be pointed by the inserted elements.

    • value (Object)

      value object to be pointed by the inserted elements.

    Returns:

    • (True|False)

      true if a new element was inserted or false if an equivalent element already existed.



332
333
# File 'for_yard_product.rb', line 332

def add *args
end

#beginEMap::Iterator

Return iterator to beginning

Returns:



291
292
# File 'for_yard_product.rb', line 291

def begin
end

#clearObject

Clear content



300
301
# File 'for_yard_product.rb', line 300

def clear
end

#endEMap::Iterator

Return iterator to end

Returns:



294
295
# File 'for_yard_product.rb', line 294

def end
end

#erase(position) ⇒ Object #erase(frist, last) ⇒ Object

Overloads:

  • #erase(position) ⇒ Object

    Erase an element from the container

    Parameters:

    Raises:

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

    • ArgumentError raised when using argument with erased position

  • #erase(frist, last) ⇒ Object

    Erase a range of elements ([first,last)) from the container. 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

    • ArgumentError raised when use argument with erased position



361
362
# File 'for_yard_product.rb', line 361

def erase *args
end

#find(arg) ⇒ EMap::Iterator

Searches the container for an element with an object equivalent to the argument.

Parameters:

  • arg (Object)

    to search equivalency.

Returns:

  • (EMap::Iterator)

    iterator pointing the element with equivalent object.

Raises:

  • ArgumentError raised when using argument(s) with erased position



367
368
# File 'for_yard_product.rb', line 367

def find arg
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 and return new iterator object

    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 and return new iterator 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.



319
320
# File 'for_yard_product.rb', line 319

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



345
346
# File 'for_yard_product.rb', line 345

def insert_or_assign *args
end

#lower_boundEMap::Iterator

Return iterator to lower bound

Returns:



306
307
# File 'for_yard_product.rb', line 306

def lower_bound 
end

#sizeInteger

Return container size

Returns:

  • (Integer)

    Return container size



297
298
# File 'for_yard_product.rb', line 297

def size
end

#upper_boundEMap::Iterator

Return iterator to upper bound

Returns:



303
304
# File 'for_yard_product.rb', line 303

def upper_bound
end