[#37892] 配列の重複検出用Hashの使いまわし — wanabe <s.wanabe@...>
ワナベと申します。
[#37898] [Bug #1105] Ruby1.9でのrescue節の例外ハンドラのマッチの処理 — Tatsuji Kawai <redmine@...>
Bug #1105: Ruby1.9でのrescue節の例外ハンドラのマッチの処理
[#37910] [Bug:1.9] lack consistency in hash iteration — Yusuke ENDOH <mame@...>
遠藤です。
まつもと ゆきひろです
[#37918] [BUG: 1.9] encoding warning — SASADA Koichi <ko1@...>
ささだです.
[#37921] [Feature:trunk] with_index_from — Yusuke ENDOH <mame@...>
遠藤です。
At Thu, 5 Feb 2009 23:18:49 +0900,
遠藤です。
At Fri, 6 Feb 2009 00:58:59 +0900,
[#37936] zombie processes by drb tests — Tanaka Akira <akr@...>
OpenBSD で、test-all をすると、drb のところで、テストに 100
咳といいます。
[#37956] proposal: Module#method_adding — SASADA Koichi <ko1@...>
ささだです.
[#37959] [Bug:trunk] I can modify literals — Yusuke ENDOH <mame@...>
遠藤です。
[#37980] Re: [ruby-changes:10687] Ruby:r22250 (trunk): * iseq.c (simple_default_value): allow plain strings as default — SASADA Koichi <ko1@...>
ささだです.
[#37995] Add POSTARG support to rb_scan_args() — Akinori MUSHA <akinori.musha@...>
rb_scan_args()をPOSTARG対応にするパッチです。
[#37998] [Feature:1.9] {Array,Enumerable}#uniq_by, #uniq_by! — Nobuyoshi Nakada <nobu@...>
なかだです。
[#38005] Is URI.decode() broken? — MOROHASHI Kyosuke <moronatural@...>
もろはしです。いつもお世話になっております。
なかだです。
成瀬です、
xibbarこと藤岡です。
成瀬です。
NARUSE, Yui さんは書きました:
成瀬です。
(2009年03月03日 22:45), NARUSE, Yui さんは書きました:
成瀬です。
In article <4A9E44DD.6050706@airemix.jp>,
成瀬です。
小崎@思いつきを適当に書いてみるテスト
In article <20090907091830.2C7A.A69D9226@jp.fujitsu.com>,
> In article <20090907091830.2C7A.A69D9226@jp.fujitsu.com>,
2009/09/07 14:38, Tanaka Akira wrote:
In article <4AA5EA67.1040504@airemix.jp>,
[#38007] [Feature #1159] StringScanner に文字ベースでのインデックスを返すメソッドがほしい — Akira Matsuda <redmine@...>
Feature #1159: StringScanner に文字ベースでのインデックスを返すメソッドがほしい
[#38018] circular require in openssl — Tanaka Akira <akr@...>
以下のように、openssl には環状の require があり、警告が出ます。
In article <87vdrcul7y.fsf@fsij.org>,
まつもと ゆきひろです
In article <E1LYyoE-0005P0-Hi@x61.netlab.jp>,
[#38022] ENCODING_FIXED と ENCODING_NONE の廃止 — "NARUSE, Yui" <naruse@...>
成瀬です。
In article <49986A0A.5060602@airemix.jp>,
成瀬です。
In article <49995412.6040000@airemix.jp>,
[#38048] Add option hash support to rb_scan_args() — "Akinori MUSHA" <knu@...>
rb_scan_args() にoption hash対応を組み込むのはどうでしょうか。
[#38067] Re: [ruby-cvs:29304] Ruby:r22086 (trunk): * ruby.c (process_options): set initial default_external before -r. — "Yugui (Yuki Sonoda)" <yugui@...>
Yuguiです。
[#38075] [Bug #1198] corrupted iteratoin during "enum_for :inject" — Shyouhei Urabe <redmine@...>
Bug #1198: corrupted iteratoin during "enum_for :inject"
[#38080] [Feature:trunk] nested loop construct — Yukihiro Matsumoto <matz@...>
まつもと ゆきひろです
ささだです.
[#38096] 多重代入やメソッド引数の展開でto_aが呼ばれます — nagachika <nagachika00@...>
nagachika と申します。
前田です。
まつもと ゆきひろです
前田です。
In article <704d5db90907141754p285e6e51xdd3208b27d556906@mail.gmail.com>,
[#38098] ブロック引数と括弧・引数なしsuper — Shugo Maeda <shugo@...>
前田です。
まつもと ゆきひろです
[ruby-dev:37998] [Feature:1.9] {Array,Enumerable}#uniq_by, #uniq_by!
なかだです。
ブロックの値にしたがって一意のものを選ぶ、Array#uniq_byというの
はどうでしょうか。
Index: array.c
===================================================================
--- array.c (revision 22100)
+++ array.c (working copy)
@@ -2875,13 +2875,40 @@ ary_add_hash(VALUE hash, VALUE ary)
}
-static VALUE
-ary_make_hash(VALUE ary)
+static inline VALUE
+ary_tmp_hash_new(void)
{
VALUE hash = rb_hash_new();
-
RBASIC(hash)->klass = 0;
+ return hash;
+}
+
+static VALUE
+ary_make_hash(VALUE ary)
+{
+ VALUE hash = ary_tmp_hash_new();
return ary_add_hash(hash, ary);
}
+static VALUE
+ary_add_hash_by(VALUE hash, VALUE ary)
+{
+ long i;
+
+ for (i = 0; i < RARRAY_LEN(ary); ++i) {
+ VALUE v = rb_ary_elt(ary, i), k = rb_yield(v);
+ if (rb_hash_lookup2(hash, k, Qundef) == Qundef) {
+ rb_hash_aset(hash, k, v);
+ }
+ }
+ return hash;
+}
+
+static VALUE
+ary_make_hash_by(VALUE ary)
+{
+ VALUE hash = ary_tmp_hash_new();
+ return ary_add_hash_by(hash, ary);
+}
+
static inline void
ary_recycle_hash(VALUE hash)
@@ -3063,4 +3090,43 @@ rb_ary_uniq(VALUE ary)
}
+static int
+push_value(st_data_t key, st_data_t val, st_data_t ary)
+{
+ rb_ary_push((VALUE)ary, (VALUE)val);
+ return ST_DELETE;
+}
+
+static VALUE
+rb_ary_uniq_by_bang(VALUE ary)
+{
+ VALUE hash;
+ long size;
+
+ RETURN_ENUMERATOR(ary, 0, 0);
+ hash = ary_make_hash_by(ary);
+ size = RHASH_SIZE(hash);
+ if (RARRAY_LEN(ary) == size) return Qnil;
+ ary_resize_capa(ary, size);
+ ARY_SET_LEN(ary, 0);
+ st_foreach(RHASH_TBL(hash), push_value, ary);
+ ary_recycle_hash(hash);
+ return ary;
+}
+
+static VALUE
+rb_ary_uniq_by(VALUE ary)
+{
+ VALUE hash;
+ long size;
+
+ RETURN_ENUMERATOR(ary, 0, 0);
+ hash = ary_make_hash_by(ary);
+ size = RHASH_SIZE(hash);
+ ary = ary_new(rb_obj_class(ary), size);
+ st_foreach(RHASH_TBL(hash), push_value, ary);
+ ary_recycle_hash(hash);
+ return ary;
+}
+
/*
* call-seq:
@@ -3920,4 +3986,6 @@ Init_Array(void)
rb_define_method(rb_cArray, "uniq", rb_ary_uniq, 0);
rb_define_method(rb_cArray, "uniq!", rb_ary_uniq_bang, 0);
+ rb_define_method(rb_cArray, "uniq_by", rb_ary_uniq_by, 0);
+ rb_define_method(rb_cArray, "uniq_by!", rb_ary_uniq_by_bang, 0);
rb_define_method(rb_cArray, "compact", rb_ary_compact, 0);
rb_define_method(rb_cArray, "compact!", rb_ary_compact_bang, 0);
Index: enum.c
===================================================================
--- enum.c (revision 22100)
+++ enum.c (working copy)
@@ -1794,4 +1794,29 @@ enum_cycle(int argc, VALUE *argv, VALUE
}
+static VALUE
+enum_uniq_by_i(VALUE i, VALUE hash, int argc, VALUE *argv)
+{
+ return rb_hash_aset(hash, rb_yield_values(argc, argv), i);
+}
+
+static int
+push_value(st_data_t key, st_data_t val, st_data_t ary)
+{
+ rb_ary_push((VALUE)ary, (VALUE)val);
+ return ST_DELETE;
+}
+
+static VALUE
+enum_uniq_by(VALUE obj)
+{
+ VALUE hash = rb_hash_new(), uniq;
+
+ RBASIC(hash)->klass = 0;
+ rb_block_call(obj, id_each, 0, 0, enum_uniq_by_i, hash);
+ uniq = rb_ary_new2(RHASH_SIZE(hash));
+ st_foreach(RHASH_TBL(hash), push_value, uniq);
+ return uniq;
+}
+
/*
* The <code>Enumerable</code> mixin provides collection classes with
@@ -1853,4 +1878,5 @@ Init_Enumerable(void)
rb_define_method(rb_mEnumerable, "drop_while", enum_drop_while, 0);
rb_define_method(rb_mEnumerable, "cycle", enum_cycle, -1);
+ rb_define_method(rb_mEnumerable, "uniq_by", enum_uniq_by, 0);
id_eqq = rb_intern("===");
--
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
中田 伸悦