Multiset library for Ruby Ruby用 多重集合(マルチセット)ライブラリ

[Japanese] [English]

Ruby implementation of multiset. Unlike ordinary set(see Ruby documentation for "set" library), multiset can store two or more same items. Rubyによる多重集合(マルチセット)の実装です。 通常の集合(Rubyでは"set"ライブラリ)と異なり、多重集合は同一の要素を複数格納することができます。

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>

Multisets are typically used for counting elements and their numbers of appearances in collections. 多重集合(マルチセット)の典型的な使い方として、コレクションの中に含まれる要素とその数を数える、というものがあります。

# Counting the appearances of characters in a string
# (Ruby 1.8.7 or later)
Multiset.new("abracadabra".each_char)
# => #<Multiset:#5 "a", #2 "b", #2 "r", #1 "c", #1 "d">

# The same
m = Multiset.new
"abracadabra".each_char do |c| # replace with 'each_byte' in Ruby 1.8.6 or before
  m << c
end
p m
# => #<Multiset:#5 "a", #2 "b", #2 "r", #1 "c", #1 "d">

# The same but works with Ruby 1.8.6 or before
Multiset.new("abracadabra".split(//))
# => #<Multiset:#5 "a", #2 "b", #2 "r", #1 "c", #1 "d">

Modified Specifications 仕様変更

Other Major Updates その他の大きな更新

Install/Download インストール/ダウンロード

The library is available via Rubygems. Use the command Rubygemsによるインストールに対応しています。以下のコマンドでインストールできます。

gem install multiset

.gem file is available at http://rubygems.org/gems/multiset. http://rubygems.org/gems/multisetから、.gemファイルを入手することもできます。

Source codes are available at http://github.com/maraigue/multiset. You can fork or propose fixes on the library via Git. ソースコードはhttps://github.com/maraigue/multisetからご覧頂けます。Git経由でプロジェクトをフォークしたり、修正の提案をしていただくことも可能です。

[Old versions]

*This program is distributed under MIT License (0.3.* or after) / BSD license (0.2.* or before). このプログラムはMITライセンス(0.3以降)およびBSDライセンス(0.2まで)にて公開しています。

Document ドキュメント

Ver. 0.5.* (almost the same for version 0.4.*) Ver. 0.2.* Ver. 0.132

[Reverse reference] [逆引きリファレンス] (Added on 2008/3/1)

Contact 連絡先

email to main(at-mark)hhiro.net . メールアドレス main(あっとまーく)hhiro.net


Back to top 戻る