Class: Yk::ESet

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

Overview

ESets are containers with external iterators that store unique elements 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 {|obj| ... } ⇒ ESet

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

Yield Parameters:

  • obj (Object)

    object pointed by an element.

Yield Returns:

  • (Object)

    should be comparable with method, '<'.



8
9
# File 'for_yard_product.rb', line 8

def initialize
end

Class Method Details

.find(first, last, obj = nil) {|obj| ... } ⇒ ESet::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 (ESet::Iterator)

    first iterator.

  • last (ESet::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:

  • (ESet::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



84
85
# File 'for_yard_product.rb', line 84

def ESet.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



93
94
# File 'for_yard_product.rb', line 93

def ESet.for_each first, last
end

Instance Method Details

#add(position, obj) ⇒ True|False #add(obj) ⇒ True|False

Overloads:

  • #add(position, obj) ⇒ 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 (ESet::Iterator)

      Hint for the position where the element can be inserted.

    • obj (Object)

      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(obj) ⇒ 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:

    • obj (Object)

      key 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.



48
49
# File 'for_yard_product.rb', line 48

def add *args
end

#beginESet::Iterator

Return iterator to beginning

Returns:



11
12
# File 'for_yard_product.rb', line 11

def begin
end

#clearObject

Clear content



20
21
# File 'for_yard_product.rb', line 20

def clear
end

#endESet::Iterator

Return iterator to end

Returns:



14
15
# File 'for_yard_product.rb', line 14

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



64
65
# File 'for_yard_product.rb', line 64

def erase *args
end

#find(arg) ⇒ ESet::Iterator

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

Parameters:

  • arg (Object)

    to search equivalency.

Returns:

  • (ESet::Iterator)

    iterator pointing the element with equivalent object.

Raises:

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



70
71
# File 'for_yard_product.rb', line 70

def find arg
end

#insert(position, obj) ⇒ ESet::Iterator #insert(obj) ⇒ Array

Overloads:

  • #insert(position, obj) ⇒ ESet::Iterator

    Insert element with an object using a hint and return new iterator object

    Parameters:

    • position (ESet::Iterator)

      Hint for the position where the element can be inserted.

    • obj (Object)

      Object to be pointed by the inserted elements.

    Returns:

    • (ESet::Iterator)

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

  • #insert(obj) ⇒ Array

    Insert element and return new iterator object

    Parameters:

    • obj (Object)

      key 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.



37
38
# File 'for_yard_product.rb', line 37

def insert *args
end

#lower_boundESet::Iterator

Return iterator to lower bound

Returns:



26
27
# File 'for_yard_product.rb', line 26

def lower_bound 
end

#sizeInteger

Return container size

Returns:

  • (Integer)

    Return container size



17
18
# File 'for_yard_product.rb', line 17

def size
end

#upper_boundESet::Iterator

Return iterator to upper bound

Returns:



23
24
# File 'for_yard_product.rb', line 23

def upper_bound
end