Class: Yk::EMSet

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

Overview

EMSets are containers with external iterators that store elements following a specific order, and where multiple elements can have equivalent values. For use, require 'Yk/ESet';include Yk;

Defined Under Namespace

Classes: Iterator

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|obj| ... } ⇒ EMSet

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



148
149
# File 'for_yard_product.rb', line 148

def initialize
end

Class Method Details

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

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:

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



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

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



233
234
# File 'for_yard_product.rb', line 233

def EMSet.for_each first, last
end

Instance Method Details

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

Overloads:

  • #add(position, obj) ⇒ True

    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 (EMSet::Iterator)

      Hint for the position where the element can be inserted.

    • obj (Object)

      Object to be pointed by the inserted elements.

    Returns:

    • (True)

      Always return true.

  • #add(obj) ⇒ True

    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)

      Always return true.



188
189
# File 'for_yard_product.rb', line 188

def add *args
end

#beginEMSet::Iterator

Return iterator to beginning

Returns:



151
152
# File 'for_yard_product.rb', line 151

def begin
end

#clearObject

Clear content



160
161
# File 'for_yard_product.rb', line 160

def clear
end

#endEMSet::Iterator

Return iterator to end

Returns:



154
155
# File 'for_yard_product.rb', line 154

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



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

def erase *args
end

#find(arg) ⇒ EMSet::Iterator

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

Parameters:

  • arg (Object)

    to search equivalency.

Returns:

  • (EMSet::Iterator)

    iterator pointing the element with equivalent object.

Raises:

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



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

def find arg
end

#insert(position, obj) ⇒ EMSet::Iterator #insert(obj) ⇒ EMSet::Iterator

Overloads:

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

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

    Parameters:

    • position (EMSet::Iterator)

      Hint for the position where the element can be inserted.

    • obj (Object)

      Object to be pointed by the inserted elements.

    Returns:

    • (EMSet::Iterator)

      An iterator pointing to either the newly inserted element.

  • #insert(obj) ⇒ EMSet::Iterator

    Insert element and return new iterator object

    Parameters:

    • obj (Object)

      key object to be pointed by the inserted elements.

    Returns:

    • (EMSet::Iterator)

      An iterator pointing to either the newly inserted element.



177
178
# File 'for_yard_product.rb', line 177

def insert *args
end

#lower_boundEMSet::Iterator

Return iterator to lower bound

Returns:



166
167
# File 'for_yard_product.rb', line 166

def lower_bound 
end

#sizeInteger

Return container size

Returns:

  • (Integer)

    Return container size



157
158
# File 'for_yard_product.rb', line 157

def size
end

#upper_boundEMSet::Iterator

Return iterator to upper bound

Returns:



163
164
# File 'for_yard_product.rb', line 163

def upper_bound
end