Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/multimap.rb,
lib/multiset.rb
Instance Method Summary collapse
-
#multimap ⇒ Object
selfを多重連想配列に変換し、その結果を返します。 新しく生成される多重連想配列においてキーに割り当てられる値は、selfに含まれる1要素のみです。. -
#to_multimap ⇒ Object
selfを多重連想配列に変換し、その結果を返します。 新しく生成される多重連想配列においてキーに割り当てられる値は、selfにおけるキーの値をMultiset.parseによって多重集合に 変換したものとなります。. -
#to_multiset ⇒ Object
selfを多重集合に変換し、その結果を返します。 キーを要素、キーに対応する値をその要素の要素数とします。.
Instance Method Details
#multimap ⇒ Object
selfを多重連想配列に変換し、その結果を返します。新しく生成される多重連想配列においてキーに割り当てられる値は、selfに含まれる1要素のみです。
Generates multiset from self. In generated multiset, only one value is associated with a key (value in self).
488 489 490 491 492 |
# File 'lib/multimap.rb', line 488 def multimap ret = Multimap.new self.each_pair{ |key, val| ret[key] = Multiset[val] } ret end |
#to_multimap ⇒ Object
selfを多重連想配列に変換し、その結果を返します。新しく生成される多重連想配列においてキーに割り当てられる値は、selfにおけるキーの値をMultiset.parseによって多重集合に変換したものとなります。
(例)キー:aには:xと:yが1個ずつ、キー:bには:xが2個割り当てられた多重連想配列
{:a => [:x, :y], :b => [:x, :x]}.to_multimap
Generates multiset from self. In generated multiset, values associated with a key are defined by the result of Multiset.parse(values_in_self) .
(example) Key :a is associated with values one :x and one :y, and key :b is associated with values two :x
{:a => [:x, :y], :b => [:x, :x]}.to_multimap
475 476 477 478 479 |
# File 'lib/multimap.rb', line 475 def to_multimap ret = Multimap.new self.each_pair{ |key, val| ret[key] = val } ret end |
#to_multiset ⇒ Object
selfを多重集合に変換し、その結果を返します。キーを要素、キーに対応する値をその要素の要素数とします。
(例){:a => 4, :b => 2}.to_multiset # :aを4個、:bを2個含む多重集合
Generates multiset from self. Keys are treated as elements, and values are number of elements in the multiset. For example,
{:a => 4, :b => 2}.to_multiset # Multiset with four :a's and two :b's
1124 1125 1126 1127 1128 |
# File 'lib/multiset.rb', line 1124 def to_multiset ret = Multiset.new self.each_pair{ |item, count| ret.renew_count(item, count) } ret end |