[Molby Document Home] [Contents]

Class: | IntGroup
Parent: | Object
Includes: | Enumerable

### Description

The class IntGroup represents an unordered set of non-negative integers.

### Public Class methods

new(arg1, arg2,...)
new(arg1, arg2,...) {|i| ...}

Create a new integer group. If no arguments are given, an empty group is returned. The arguments are either IntGroup, Range, Enumerable, or Numeric. In either case, the non-negative integers included in the arguments are added to the result. If a block is given, the block is called with the each integer in the given arguments, and the integer group consisting with the returned integers is returned.

### Public Instance methods

self[index] → Integer or nil

Get the index-th point in self. If the index is out of range, nil is returned.

add(IntGroup) → self

Add the points in the given group.

clear → self

Discard all integers included in self.

convolute(val) → (new)IntGroup

For each element n in self, get the n-th point in val, and return the result as a new group. If n is out of range, then that point is ignored.

See Also: IntGroup#deconvolute. If all points in self are within the range of val, then an equation `self.convolute(val).deconvolute(val) == self` holds.

deconvolute(val) → (new)IntGroup

For each element n in self, find the point n in val, and return the found indices as a new group. If n is not found in val, then that point is ignored.

See Also: IntGroup#convolute. If all points in self are found in val, then an equation `self.deconvolute(val).convolute(val) == self` holds.

delete(IntGroup) → self

Remove the points in the given group.

difference(val) → (new)IntGroup
self - val → (new)IntGroup

Returns a difference group.

each {|i| ...}

Call the block with each integer in self.

dup(IntGroup) → (new) IntGroup

(Deep) copy the given IntGroup.

index(val) → Integer
index { |item| ... } → Integer

Returns the index of the first element that is equal to the given value. In the second form, returns the index of the first element for which the associated block returns true. If no such element was found, returns nil.

inspect → String
to_s → String

Create a String in the form "IntGroup[...]".

intersection(val) → (new)IntGroup
self & val → (new)IntGroup

Returns an intersection group.

length → Integer
size → Integer

Returns the number of integers included in self.

member?(val) → bool
include?(val) → bool

Check whether the val is included in self.

offset(val) → self

Move all points by an integer value. A negative val is allowed, but it must be no smaller than -(self[0]), otherwise an exception is thrown.

range_at(val) → Range

Split self into consecutive chunks of integers, and return the val-th chunk as a Range. This method is relatively efficient, because it directly uses the internal representation of IntGroup.

sym_difference(val) → (new)IntGroup
self ^ val → (new)IntGroup

Returns a symmetric-difference group (i.e. a group containing elements that are included in either self or val but not both).

union(val) → (new)IntGroup
self + val → (new)IntGroup
self | val → (new)IntGroup

Returns a union group.