Class Multiset
In: multiset.rb
Parent: Object

概要(Basic information)

Rubyによる多重集合(マルチセット)の実装です。 通常の集合(Rubyでは"set"ライブラリ)と異なり、多重集合は 同一の要素を複数格納することができます。

メソッド名は基本的にSetクラスに合わせてあります。またSetクラスが持つ メソッドの大部分を実装していますが、いくつか未実装なものもあります。

Ruby implementation of multiset. Unlike ordinary set(see Ruby documentation for "set" library), multiset can contain two or more same items.

Most methods’ names are same as those of Set class, and all other than a few methods in Set class is implemented on Multiset class.

  • Set[:a,:b,:c,:b,:b,:c] => #<Set: {:b, :c, :a}>
  • Multiset[:a,:b,:c,:b,:b,:c] => #<Multiset:#3 :b, #2 :c, #1 :a>

インストール(Installation)

インストールはsetup.rbによって行われます。詳しくはINSTALL.ja.txtをご覧下さい。

setup.rb performs installation. See INSTALL.en.txt for more information.

更新履歴(Revision history)

  • Version 0.10(2008/2/9)
    • 公開開始。
  • Version 0.11(2008/2/12)
    • メソッド「&」の実装が誤っていたのを修正。
    • ドキュメントの間違いを修正。
  • Version 0.12(2008/2/16)
  • Version 0.13(2008/3/1)
  • Version 0.131(2008/3/2)
    • ドキュメントの間違いを修正。
  • Version 0.132(2008/4/23)
    • GNU LGPLの文書を添付していなかったので追加。申し訳ありません。

  • Version 0.10(2008/2/9)
    • First distribution.
  • Version 0.11(2008/2/12)
    • Fixed wrong implementation of method "&".
    • Fixed wrong documentation.
  • Version 0.12(2008/2/16)
  • Version 0.13(2008/3/1)
  • Version 0.131(2008/3/2)
    • Fixed wrong documentation.
  • Version 0.132(2008/4/23)
    • Added the text of GNU LGPL to the archive. I‘m very sorry…

著作権表示(Copyright)

Author:Maraigue(f52.aaa.livedoor.jp/~maraigue/)
Version:0.132(2008/4/23)
Copyright:(C)2008 Maraigue

このプログラムはBSDライセンスにて提供する 無 保 証 のプログラムです。 詳細はBSDLicense.txtをご覧下さい。

日本語の参考訳は以下のURLにあります。 sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license ただし、法的にはBSDLicense.txtに書かれた英語の文章のみが有効です。

setup.rbはMinero Aoki氏(i.loveruby.net/)の制作です。 setup.rbのみは、GNU LGPL(version 2.1)のライセンスが適用されます。 GNU LGPLについてはGNU_LGPL.txtをご覧下さい。

This program is distributed with ABSOLUTELY NO WARRANTY, under BSD License. See BSDLicense.txt for more detail.

setup.rb is made by Minero Aoki(i.loveruby.net/). Only setup.rb is distributed under GNU LGPL(version 2.1). See GNU_LGPL.txt for more detail.

Methods

&   +   -   <<   ==   []   add   classify   classify_with   clear   collect   collect!   collect_with   collect_with!   count   delete   delete_all   delete_if   delete_with   dup   each   each_item   each_pair   empty?   flatten   flatten!   include?   items   length   listing   map   map!   map_with   map_with!   member?   merge   merge!   new   proper_subset?   proper_superset?   rand   reject!   renew_count   replace   size   subset?   subtract   subtract!   superset?   to_a   to_hash   to_s   to_set   |  

Included Modules

Enumerable

Public Class methods

listに含まれる要素からなる多重集合を生成します。 newを用いる場合と異なり、引数の1つ1つが多重集合の要素になります。

主に多重集合のリテラルを生成するのに用います。

Generates multiset from items in list. Unlike using new, each argument is one item in generated multiset.

This method is mainly used when you generate literal of multiset.

listに含まれる要素からなる多重集合を生成します。 listを省略した場合、空の多重集合を生成します。

listにはEnumerableであるオブジェクトのみ 指定できます。そうでない場合、例外ArgumentErrorが 発生します。

Generates multiset from items in list. If list is omitted, returns empty multiset.

list must be Enumerable. If not, ArgumentError is raised.

Public Instance methods

selfotherの積集合からなる多重集合を返します。

Returns intersection of self and other.

+(other)

Alias for merge

-(other)

Alias for subtract

<<(item, addcount = 1)

Alias for add

selfotherと等しいかどうかを返します。

Returns whether self is equal to other.

selfに、addcount個のitemを追加します。 成功した場合はselfを、失敗した場合はnilを返します。

Adds addcount number of items to self. Returns self if succeeded, or nil if failed.

selfの要素を、与えられたブロックからの返り値によって分類します。 { ブロックからの返り値 => 該当する要素を含む多重集合 } の形をしたハッシュを返します。

Classify items in self by returned value from block. Returns a Hash with format of { value_from_block => item_in_self }.

classifyと同様ですが、ブロックには要素とその個数の組が与えられます。

Same as classify, but the pair of item and its number is given to block.

selfの要素をすべて削除します。 selfを返します。

Deletes all items in self. Returns self.

collect()

Alias for map

collect!()

Alias for map!

collect_with()

Alias for map_with

collect_with!()

Alias for map_with!

self中に含まれるitemの個数を返します。

Returns number of items in self.

selfから、delcount個のitemを削除します。 成功した場合はselfを、失敗した場合はnilを返します。

Deletes delcount number of items from self. Returns self if succeeded, nil otherwise.

selfに含まれるitemをすべて削除します。 selfを返します。

Deletes all items in self. Returns self.

ブロックにselfの要素を順次与え、 結果が真であった要素をすべて削除します。 selfを返します。

Gives all items in self to given block, and deletes that item if the block returns true. Returns self.

selfに含まれるすべての要素とその個数について、 その組をブロックに与え、結果が真であった要素をすべて削除します。 selfを返します。

Gives each pair of item and its number to given block, and deletes those items if the block returns true. Returns self.

selfの複製を生成して返します。

Returns duplicated self.

selfに含まれるすべての要素について繰り返します。 selfを返します。

Iterates for each item in self. Returns self.

selfに含まれるすべての要素について、重複を許さずに繰り返します。 selfを返します。

Iterates for each item in self, without duplication. Returns self.

selfに含まれるすべての要素とその個数について繰り返します。 selfを返します。

Iterates for each pair of item and its number in self. Returns self.

selfに要素がないかどうかを返します。

Returns whether self has no item.

self中に含まれる多重集合を平滑化したものを返します。

Generates a multiset such that multisets in self are flattened.

self中に含まれる多重集合を平滑化します。 平滑化した多重集合が1つでもあればselfを、 そうでなければnilを返します。

Flattens multisets in self. Returns self if any item is flattened, nil otherwise.

itemself中に含まれているかを返します。

Returns whether self has item.

selfに含まれている要素(重複は除く)からなる配列を返します。

Returns an array with all items in self, without duplication.

length()

Alias for size

selfの全要素を(重複を許して)並べた文字列を返します。 要素間の区切りはdelimの値を用い、 各要素の表示形式は与えられたブロックの返り値(なければObject#inspect)を用います。

Lists all items with duplication in self. Items are deliminated with delim, and items are converted to string in the given block. If block is omitted, Object#inspect is used.

selfの各要素をブロックに与え、返り値を集めたものからなる 多重集合を生成します。

Gives all items in self to given block, and generates a new multiset whose values are returned value from the block.

Multiset#mapと同様ですが、結果として生成される多重集合でselfが 置き換えられます。selfを返します。

Same as Multiset#map, but replaces self by resulting multiset. Returns self.

selfの要素とその個数の組をブロックに与えます。 ブロックから2要素の配列を受け取り、前者を要素、後者をその個数とした 多重集合を生成します。

Gives all pairs of items and their numbers in self to given block. The block must return an array of two items. Generates a new multiset whose values and numbers are the first and second item of returned array, respectively.

Multiset#map_withと同様ですが、結果として生成される多重集合で selfが置き換えられます。selfを返します。

Same as Multiset#map_with, but replaces self by resulting multiset. Returns self.

member?(item)

Alias for include?

selfotherの要素を合わせた多重集合を返します。

Returns merged multiset of self and other.

selfotherの要素を追加します。 selfを返します。

Merges other to self. Returns self.

selfotherに真に含まれているかどうかを返します。 「真に」とは、両者が一致する場合は含めないことを示します。

Returns whether self is a proper subset of other.

selfotherを真に含んでいるかどうかを返します。 「真に」とは、両者が一致する場合は含めないことを示します。

Returns whether self is a proper superset of other.

selfの要素を無作為に1つ選んで返します。 すべての要素は等確率で選ばれます。

Returns one item in self randomly. All items are selected with same probability.

delete_ifと同じですが、要素が1つも削除されなければnilを返します。

Same as delete_if, but returns nil if no item is deleted.

selfに含まれるitemの個数をnumber個にします。 numberが負の数であった場合は、number = 0とみなします。 成功した場合はselfを、失敗した場合はnilを返します。

Sets number of item to number in self. If number is negative, treats as number = 0. Returns self if succeeded, nil otherwise.

selfの内容をotherのものに置き換えます。 selfを返します。

Replaces self by other. Returns self.

selfに含まれている要素数を返します。

Returns number of all items in self.

selfotherに含まれているかどうかを返します。

Returns whether self is a subset of other.

selfからotherの要素を取り除いた多重集合を返します。

Returns multiset such that items in other are removed from self.

selfからotherの要素を削除します。 selfを返します。

Removes items in other from self. Returns self.

selfotherを含んでいるかどうかを返します。

Returns whether self is a superset of other.

selfを配列に変換して返します。

Converts self to an array.

selfHashに変換して返します。 生成されるハッシュの構造については、Hash#to_multisetをご覧下さい。

Converts self to a Hash. See Hash#to_multiset about format of generated hash.

selfの要素と要素数の組を並べた文字列を返します。 要素間の区切りはdelimの値を用い、 各要素の表示形式は与えられたブロックの返り値(なければObject#inspect)を用います。

Lists all items without duplication and its number in self. Items are deliminated with delim, and items are converted to string in the given block. If block is omitted, Object#inspect is used.

selfを通常の集合(Ruby標準添付のSet)に 変換したものを返します。

このメソッドを呼び出すと、require "set"が行われます。

なおSetをMultisetに変換するには、Multiset.new(instance_of_set)で 可能です。

Converts self to ordinary set (The Set class attached to Ruby by default).

require "set" is performed when this method is called.

To convert Set to Multiset, use Multiset.new(instance_of_set).

selfotherの和集合からなる多重集合を返します。

Returns union of self and other.

[Validate]