Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/multimap.rb,
lib/multiset.rb
Instance Method Summary collapse
-
#multimap ⇒ Object
Generates multiset from
self. -
#to_multimap ⇒ Object
Generates multiset from
self. -
#to_multiset ⇒ Object
Generates multiset from
self.
Instance Method Details
#multimap ⇒ Object
Generates multiset from self. In generated multiset, only one value is associated with a key (value in self).
selfを多重連想配列に変換し、その結果を返します。新しく生成される多重連想配列においてキーに割り当てられる値は、selfに含まれる1要素のみです。
491 492 493 494 495 |
# File 'lib/multimap.rb', line 491 def multimap ret = Multimap.new self.each_pair{ |key, val| ret[key] = Multiset[val] } ret end |
#to_multimap ⇒ Object
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
selfを多重連想配列に変換し、その結果を返します。新しく生成される多重連想配列においてキーに割り当てられる値は、selfにおけるキーの値をMultiset.parseによって多重集合に変換したものとなります。
(例)キー:aには:xと:yが1個ずつ、キー:bには:xが2個割り当てられた多重連想配列
{:a => [:x, :y], :b => [:x, :x]}.to_multimap
478 479 480 481 482 |
# File 'lib/multimap.rb', line 478 def to_multimap ret = Multimap.new self.each_pair{ |key, val| ret[key] = val } ret end |
#to_multiset ⇒ Object
Generates multiset from self. Keys of the Hash are treated as items in the multiset, while values of the Hash are number of items.
(example) {:a => 4, :b => 2}.to_multiset # Multiset with four :a's and two :b's
selfを多重集合に変換し、その結果を返します。Hashのキーを要素、Hashの値をその要素の要素数とします。
(例){:a => 4, :b => 2}.to_multiset # :aを4個、:bを2個含む多重集合
1182 1183 1184 1185 1186 |
# File 'lib/multiset.rb', line 1182 def to_multiset ret = Multiset.new self.each_pair{ |item, count| ret.renew_count(item, count) } ret end |