| Class | Multiset |
| In: |
multiset/libmultiset.rb
|
| Parent: | Object |
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.
listに含まれる要素からなる多重集合を生成します。 listを省略した場合、空の多重集合を生成します。
listにはEnumerableであるオブジェクトのみ 指定できます。そうでない場合、例外ArgumentErrorが 発生します。
Generates a multiset from items in list. If list is omitted, returns empty multiset.
list must be Enumerable. If not, ArgumentError is raised.
objectを多重集合に変換し生成します。
Generates a multiset converting object.
Multiset.parseと同様ですが、挙動がMultiset.parse_stringの設定に 影響されません(Multiset.parse_string(true)の場合と 同様とみなします)。
Same as Multiset.parse, but this method is not affected by the setting of Multiset.parse_string (treats Multiset.parse_string(true)) .
Multiset.parseの引数にStringを渡すことを許すか指定します。
StringはEnumerableなので、Multiset.parseでは引数として文字列を 渡すこともできます。しかしこれはバグの危険性があるため、 このメソッドで禁止することができます。
booleanにはtrueおよびfalseが指定できます。 falseを設定した場合、Multiset.parseやMultimap#[]=などで 文字列を直接指定した場合にArgumentErrorが発生します。 デフォルト値はtrueです。
booleanを省略した場合は、現在のこの値がtrueか falseかを返します。
この値はクラス変数で管理されているので、一度変更するとすべての インスタンスに影響が及びます。
Allows or prohibits Strings from being arguments of Multiset.parse .
String includes module Enumerable, therefore you can give a string as an argument of Multiset.parse . But this may cause bugs, so you can prohibit this.
boolean can be true or false. If this value is false, ArgumentError is raised whenever you specify a string as an argument of Multiset.parse , Multimap#[]= , and so on. This value is true by default.
If boolean is not specified, returns current value (true or false).
This value is stored in class variable, therefore this value has effect for all instances of Multiset.
selfに、addcount個のitemを追加します。 成功した場合はselfを、失敗した場合はnilを返します。
Adds addcount number of items to self. Returns self if succeeded, or nil if failed.
selfから、delcount個のitemを削除します。 成功した場合はselfを、失敗した場合はnilを返します。
Deletes delcount number of items from self. Returns self if succeeded, nil otherwise.
ブロックにselfの要素を順次与え、 結果が真であった要素をすべて削除します。 selfを返します。
Gives all items in self to given block, and deletes that item if the block returns true. Returns 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中に含まれる多重集合を平滑化します。 平滑化した多重集合が1つでもあればselfを、 そうでなければnilを返します。
Flattens multisets in self. Returns self if any item is flattened, nil otherwise.
selfに含まれている要素(重複は除く)からなる配列を返します。
Returns an array with all items in self, without duplication.
Multiset#mapと同様ですが、結果として生成される多重集合でselfが 置き換えられます。selfを返します。
Same as Multiset#map, but replaces self by resulting multiset. Returns self.
Multiset#map_withと同様ですが、結果として生成される多重集合で selfが置き換えられます。selfを返します。
Same as Multiset#map_with, but replaces self by resulting multiset. Returns self.
selfがotherに真に含まれているかどうかを返します。 「真に」とは、両者が一致する場合は含めないことを示します。
Returns whether self is a proper subset of other.
selfがotherを真に含んでいるかどうかを返します。 「真に」とは、両者が一致する場合は含めないことを示します。
Returns whether self is a proper superset of other.
selfの要素を無作為に1つ選んで返します。 すべての要素は等確率で選ばれます。
Returns one item in self randomly. All items are selected with same probability.
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の要素を取り除いた多重集合を返します。
Returns multiset such that items in other are removed from self.
selfをHashに変換して返します。 生成されるハッシュの構造については、Hash#to_multisetをご覧下さい。
Converts self to a Hash. See Hash#to_multiset about format of generated hash.
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).