Class Multimap
In: multiset/libmultimap.rb
Parent: Object

概要(Basic information)

Rubyによる多重連想配列(マルチマップ)の実装です。 通常の連想配列(Rubyでは"Hash"クラス)と異なり、多重連想配列は 1つのキーに対して複数の要素が存在し得ます。

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

Ruby implementation of multimap. Unlike ordinary map, also known as associative array (see Ruby documentation for "Hash" class), multimap can contain two or more items for a key.

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

Methods

+   ==   []   []=   clear   delete   delete_if   delete_with   dup   each   each_key   each_pair   each_pair_list   each_pair_with   each_value   empty?   fetch   has_key?   has_value?   include?   index   indexes   indices   invert   key   key?   keys   length   member?   merge   merge!   new   reject   reject!   reject_with   replace   size   store   to_hash   value?   values   values_at  

Included Modules

Enumerable

Public Class methods

新しい多重連想配列を生成します。Hash#newと異なり、デフォルト値は 設定できません。

Generates a new multimap. Different from Hash#new , you can not specify default value.

Public Instance methods

+(other)

Alias for merge

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

Returns whether self is equal to other.

[](key)

Alias for fetch

[]=(key, value_list)

Alias for store

selfに格納された要素をすべて削除します。 selfを返します。

Removes all elements stored in self. Returns self.

keyに割り当てられた全ての値を削除し、その値を Multisetとして返します。

Deletes all values associated with key, and returns those values as a Multiset.

ブロックにselfのキーと値の組(値は1つ)を順次与え、 結果が真であった組をすべて削除します。 selfを返します。

Gives all pairs of a key and single value in self to given block, and deletes that element if the block returns true. Returns self.

delete_ifと同じですが、ブロックへの引数が(キー、キーに割り当てられた値、 その値がキーに割り当てられている個数)の3つの組で与えられます。

Same as delete_if, but arguments given to block is the tuple of three: (key, one value associated with the key, numbers of that value associated with the key).

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

Returns duplicated self.

each()

Alias for each_pair

selfのすべてのキーについて繰り返します。 selfを返します。

Iterates for each key in self. Returns self.

selfのすべてのキーと値の組について繰り返します。 selfを返します。

Iterates for each pair of a key and a value in self. Returns self.

selfのすべてのキーと、そのキーに割り当てられた すべての値(Multisetで与えられる)の組について繰り返します。 selfを返します。

Iterates for each pair of a key and all values associated with the key (list of values is given as Multiset) in self. Returns self.

selfのすべてのキーと値の組について、 ブロックに(キー、キーに割り当てられた値、その値が割り当てられた数) の組を与えながら繰り返します。selfを返します。

Iterates for each pair of a key and a value in self, giving the tuple of three to block: (key, one value associated with the key, numbers of that value associated with the key). Returns self.

selfのすべての値について繰り返します。 selfを返します。

Iterates for each value in self. Returns self.

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

Returns whether self has no element.

キーkeyに対応する値(複数存在しうる)を、 Multisetとして返します。Hash#fetchの場合と異なり、キーに対応する 値が存在しない場合の扱いを指定することはできません。 (そのような場合、空のMultisetが返ります。)

Returns values associated with key with format of Multiset. Different from Hash#fetch, you can not specify a value or a process when key has not associated with any value. If key has not associated with any value, Multimap#fetch returns empty Multiset.

selfにキーkeyかあるかどうかを返します。

Returns whether self has a key key.

selfに値valueかあるかどうかを返します。

Returns whether self has a value value.

include?(key)

Alias for has_key?

index(value)

Alias for key

indexes(*key_list)

Alias for values_at

indices(*key_list)

Alias for values_at

selfのキーと値を入れ替えたMultimapを返します。 例えばキー:aに対応する値が2つの:xと1つの:yであれば、変換結果は キー:xに:aが2つ、キー:yに:aが1つ対応するMultimapです。

Returns a Multimap whose keys are values in self, and values are keys in self. For example, If self has a key :a associated with two :x and one :y, returned multimap has two keys :x and :y, and their values are two :a and one :a respectively.

selfから値がvalueであるような要素を 検索し、それに対応するキーを返します。該当するキーが複数存在する場合、 そのうちの1つを返します。該当するキーが存在しなければ nilを返します。

Search a pair of key and value from self such that the value is equal to the argument value. If two or keys are matched, returns one of them. If no key is matched, returns nil.

key?(key)

Alias for has_key?

selfのすべてのキーを、配列として返します。

Returns an array in which keys in self are stored.

length()

Alias for size

member?(key)

Alias for has_key?

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

Returns merged multiset of self and other.

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

Add elements in other to self. Returns self.

delete_ifと同じですが、self自身からはキーと値の組を 削除せず、要素が削除された結果の多重連想配列を新たに生成して 返します。

Same as delete_if, but generates a new Multimap whose pairs of key and value are deleted, instead of deleting pairs in self.

delete_ifと同じですが、キーと値の組が1つも削除されなければ nilを返します。

Same as delete_if, but returns nil if no pair of key and value is deleted.

rejectと同じですが、ブロックへの引数が(キー、キーに割り当てられた値、 その値がキーに割り当てられている個数)の3つの組で与えられます。

Same as reject, but arguments given to block is the tuple of three: (key, one value associated with the key, numbers of that value associated with the key).

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

Replaces self by other. Returns self.

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

Returns number of all elements in self.

キーkeyに対応する値(複数存在しうる)を value_listで置き換えます。この際、 value_listMultiset.parseを用いてMultisetに変換されます。

value_listを返します。

Sets values associated with key to value_list. value_list is converted to a Multiset by Multiset.parse .

Returns value_list.

selfHashに変換して返します。 生成されるハッシュの構造については、Hash#to_multimapをご覧下さい。 その際、返されるハッシュにおいて値はすべてMultimap型となります。

Converts self to a Hash. See Hash#to_multimap about format of generated hash. All values in the returned hash are multimaps.

value?(value)

Alias for has_value?

selfのすべての値を、Multisetとして返します。

Returns a Multiset in which values in self are stored.

selfからkey_listの各キーに対応する値 (Multiset型)を取り出し、それらを配列として返します。 すなわち、Multisetを要素とする配列を返します。

Gets values (instances of Multiset) of self associated with key_list, and returns those values as an array. i.e. returns an array whose elements are multisets.

[Validate]