[#14206] undef_method :method_missing — Kenichi Komiya <kom@...1.accsnet.ne.jp>

154 messages 2001/08/04
[#14207] Re: undef_method :method_missing — nobu.nakada@... 2001/08/04

なかだです。

[#14208] Re: undef_method :method_missing — nobu.nakada@... 2001/08/05

なかだです。

[#14209] Virtual Machine — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14210] Re: Virtual Machine — Kenta MURATA <muraken2@...> 2001/08/05

むらけんです.

[#14212] Re: Virtual Machine — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14214] Re: Virtual Machine — SHIROYAMA Takayuki <psi@...> 2001/08/05

[#14220] Re: Virtual Machine — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14211] Common GUI framework(Re: Virtual Machine) — nobu.nakada@... 2001/08/05

なかだです。

[#14213] RE: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。どもっ。

[#14215] Re: Common GUI framework(Re: Virtual Machine) — akira yamada / やまだあきら <akira@...> 2001/08/05

[#14221] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14235] Re: Common GUI framework(Re: Virtual Machine) — IWATSUKI Hiroyuki <don@...> 2001/08/05

岩月と申します。

[#14237] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。どもっ。

[#14239] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/05

有馬です。

[#14241] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14244] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/05

有馬です。

[#14247] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。どもっ。

[#14263] Re: Common GUI framework(Re: Virtual Machine) — とみたまさひろ <tommy@...> 2001/08/05

とみたです。

[#14266] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14269] Re: Common GUI framework(Re: Virtual Machine) — とみたまさひろ <tommy@...> 2001/08/05

とみたです。

[#14275] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/05

有馬です。

[#14294] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14317] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/06

有馬です。

[#14321] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/06

金光です。どもっ。

[#14332] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/06

有馬です。

[#14335] Re: Common GUI framework(Re: Virtual Machine) — Kenta MURATA <muraken2@...> 2001/08/06

むらけんです.

[#14346] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/06

金光です。どもっ。

[#14356] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/06

有馬です。

[#14357] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/06

金光です。どもどもっ。

[#14243] Re: Common GUI framework(Re: Virtual Machine) — IWATSUKI Hiroyuki <don@...> 2001/08/05

岩月と申します。

[#14258] Re: Common GUI framework(Re: Virtual Machine) — akira yamada / やまだあきら <akira@...> 2001/08/05

[#14260] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。FOXとかもあるのかぁ。すげぇなぁ。

[#14277] Re: Common GUI framework(Re: Virtual Machine) — matz@... (Yukihiro Matsumoto) 2001/08/05

まつもと ゆきひろです

[#14295] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。御大、待ってましたっ。

[#14390] [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...>

なひです。

113 messages 2001/08/09
[#14391] Re: [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/09

なひです。書き忘れ。

[#14392] Re: [Patch] pp.rb and debug.rb — nobu.nakada@... 2001/08/09

なかだです。

[#14435] Re: [Patch] pp.rb and debug.rb — "K.Kosako" <kosako@...> 2001/08/13

nobu.nakada@nifty.ne.jpさんの

[#14437] Re: [Patch] pp.rb and debug.rb — nobu.nakada@... 2001/08/13

なかだです。

[#14449] Re: [Patch] pp.rb and debug.rb — Tanaka Akira <akr@...17n.org> 2001/08/14

In article <DJEGJLCFNEIMKDNMLFPHMEAHCBAA.nakahiro@sarion.co.jp>,

[#14450] Re: [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/14

なひです。

[#14452] Re: [Patch] pp.rb and debug.rb — Tanaka Akira <akr@...17n.org> 2001/08/14

In article <DJEGJLCFNEIMKDNMLFPHEEAICBAA.nakahiro@sarion.co.jp>,

[#14453] Re: [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/14

なひです。

[#14454] Re: [Patch] pp.rb and debug.rb — matz@... (Yukihiro Matsumoto) 2001/08/14

まつもと ゆきひろです

[#14455] Re: [Patch] pp.rb and debug.rb — Tanaka Akira <akr@...17n.org> 2001/08/14

In article <997774251.527258.14423.nullmailer@ev.netlab.jp>,

[#14474] Re: [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/15

なひです。

[#14498] Re: [Patch] pp.rb and debug.rb — Tanaka Akira <akr@...17n.org> 2001/08/16

In article <DJEGJLCFNEIMKDNMLFPHEEALCBAA.nakahiro@sarion.co.jp>,

[#14499] Re: [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/16

なひです。

[#14504] Re: [Patch] pp.rb and debug.rb — Tanaka Akira <akr@...17n.org> 2001/08/16

In article <DJEGJLCFNEIMKDNMLFPHEEAPCBAA.nakahiro@sarion.co.jp>,

[#14507] marshal API (was Re: [Patch] pp.rb and debug.rb) — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/16

なひです。

[#14510] Re: marshal API (was Re: [Patch] pp.rb and debug.rb) — Tanaka Akira <akr@...17n.org> 2001/08/16

In article <DJEGJLCFNEIMKDNMLFPHMEBACBAA.nakahiro@sarion.co.jp>,

[#14511] Re: marshal API (was Re: [Patch] pp.rb and debug.rb) — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/16

なひです。

[#14519] custom marshal (Re: Re: marshal API (was Re: [Patch] pp.rb and debug.rb)) — Tanaka Akira <akr@...17n.org> 2001/08/17

In article <DJEGJLCFNEIMKDNMLFPHIEBBCBAA.nakahiro@sarion.co.jp>,

[#14520] Re: marshal API (was Re: [Patch] pp.rb and debug.rb) — Tanaka Akira <akr@...17n.org> 2001/08/17

うぅむ。ぼーっとしてたら意味もなく Subject を変えてしまった。

[#14549] Re: custom marshal (Re: Re: marshal API (was Re: [Patch] pp.rb and debug.rb)) — Tanaka Akira <akr@...17n.org> 2001/08/22

In article <hvo66bnxe4b.fsf_-_@flux.etl.go.jp>,

[#14832] Re: custom marshal — GOTO Kentaro <gotoken@...> 2001/09/29

古い話題で恐縮ですが…

[#14833] Re: custom marshal — nobu.nakada@... 2001/09/29

なかだです。

[#14834] Re: custom marshal — Tanaka Akira <akr@...17n.org> 2001/10/01

In article <200109290948.f8T9mbh12942@sharui.nakada.kanuma.tochigi.jp>,

[#14835] Re: custom marshal — nobu.nakada@... 2001/10/01

なかだです。

[#14836] Re: custom marshal — matz@... (Yukihiro Matsumoto) 2001/10/01

まつもと ゆきひろです

[#14837] Re: custom marshal — Tanaka Akira <akr@...17n.org> 2001/10/02

In article <1001945748.240863.24023.nullmailer@ev.netlab.jp>,

[#14838] Re: custom marshal — nobu.nakada@... 2001/10/02

なかだです。

[#14839] Re: custom marshal — Tanaka Akira <akr@...17n.org> 2001/10/02

In article <200110020334.f923YLb08299@sharui.nakada.kanuma.tochigi.jp>,

[#14842] Re: custom marshal — nobu.nakada@... 2001/10/02

なかだです。

[#14843] Re: custom marshal — Tanaka Akira <akr@...17n.org> 2001/10/02

In article <200110021010.f92AAIb13474@sharui.nakada.kanuma.tochigi.jp>,

[#14844] Re: custom marshal — nobu.nakada@... 2001/10/02

なかだです。

[#14845] Re: custom marshal — matz@... (Yukihiro Matsumoto) 2001/10/02

まつもと ゆきひろです

[#14847] Re: custom marshal — matz@... (Yukihiro Matsumoto) 2001/10/02

まつもと ゆきひろです

[#14848] Re: custom marshal — nobu.nakada@... 2001/10/03

なかだです。

[#14852] Re: custom marshal — matz@... (Yukihiro Matsumoto) 2001/10/03

まつもと ゆきひろです

[#14465] Ruby/Bsearch — akira yamada / やまだあきら <akira@...>

16 messages 2001/08/14
[#14472] Re: Ruby/Bsearch — matz@... (Yukihiro Matsumoto) 2001/08/15

まつもと ゆきひろです

[#14595] SEGV at `$0 = "long long string"' — nobu.nakada@...

なかだです。

14 messages 2001/08/28

[ruby-dev:14584] Array#merge, Array#squeeze

From: "Akinori MUSHA" <knu@...>
Date: 2001-08-27 08:53:04 UTC
List: ruby-dev #14584
 最近 Ruby の中身に関わる時間が取れないのですが、書いている
プログラムで欲しくなったメソッドがあるので、実装してみました。

Array#merge(obj1[, obj2, ...])

	与えられたオブジェクトのうち、配列に含まれない要素を
	追加する。重複する要素は一つだけになる。

	a.merge(*x) と a.replace(a | x) はほぼ等価である。
	(|= を破壊的に行う)

Array#squeeze([obj, ...])
Array#squeeze!([obj, ...])

	同じ要素の連続を一つに圧縮する。引数が指定された場合は
	引数に含まれるもののみを対象に圧縮する。

	String#squeeze の配列版。


実装において、 ary_make_hash() の argc, argv 対応版が必要だった
ので ary_make_hash2() として用意し、 ary_make_hash() の下請けと
しました。


 ほかにもいいと思う人が多ければ 1.7 に入れたいなあと思いますが、
いかがでしょうか?名前や実装についても突っ込みがあればよろしく。


# union(!), unify(!) なども考えたが、ある程度対等な関係であれば
# | を使う方が見た目もよいので、ニュアンスからも merge が適当と
# 判断した。

-- 
                     /
                    /__  __            Akinori.org / MUSHA.org
                   / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp

"Freeze this moment a little bit longer, make each impression
  a little bit stronger..  Experience slips away -- Time stand still"

Index: array.c
===================================================================
RCS file: /src/ruby/array.c,v
retrieving revision 1.56
diff -u -r1.56 array.c
--- array.c	2001/08/23 06:02:14	1.56
+++ array.c	2001/08/27 08:40:12
@@ -1485,24 +1485,36 @@
 }
 
 static VALUE
-ary_make_hash(ary1, ary2)
-    VALUE ary1, ary2;
+ary_make_hash2(ary, argc2, argv2)
+    VALUE ary;
+    int argc2;
+    VALUE *argv2;
 {
     VALUE hash = rb_hash_new();
+    int argc1 = RARRAY(ary)->len;
+    VALUE *argv1 = RARRAY(ary)->ptr;
     int i;
 
-    for (i=0; i<RARRAY(ary1)->len; i++) {
-	rb_hash_aset(hash, RARRAY(ary1)->ptr[i], Qtrue);
+    for (i = 0; i < argc1; i++) {
+	rb_hash_aset(hash, argv1[i], Qtrue);
     }
-    if (ary2) {
-	for (i=0; i<RARRAY(ary2)->len; i++) {
-	    rb_hash_aset(hash, RARRAY(ary2)->ptr[i], Qtrue);
-	}
+    for (i = 0; i < argc2; i++) {
+	rb_hash_aset(hash, argv2[i], Qtrue);
     }
     return hash;
 }
 
 static VALUE
+ary_make_hash(ary1, ary2)
+    VALUE ary1, ary2;
+{
+    if (ary2)
+	return ary_make_hash2(ary1, RARRAY(ary2)->len, RARRAY(ary2)->ptr);
+    else
+	return ary_make_hash2(ary1, 0, 0);
+}
+
+static VALUE
 rb_ary_and(ary1, ary2)
     VALUE ary1, ary2;
 {
@@ -1552,6 +1564,44 @@
 }
 
 static VALUE
+rb_ary_merge(argc, argv, ary)
+    int argc;
+    VALUE *argv;
+    VALUE ary;
+{
+    VALUE hash = ary_make_hash2(ary, argc, argv);
+    VALUE *p;
+    long i, j, len;
+
+    rb_ary_modify(ary);
+
+    p = RARRAY(ary)->ptr;
+    len = RARRAY(ary)->len;
+
+    for (i = j = 0; j < len; j++) {
+	VALUE v = p[j];
+	if (st_delete(RHASH(hash)->tbl, &v, 0)) {
+	    p[i++] = p[j];
+	}
+    }
+
+    RARRAY(ary)->len = RARRAY(ary)->capa =
+      len = i + RHASH(hash)->tbl->num_entries;
+    REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
+
+    p = RARRAY(ary)->ptr;
+
+    for (j = 0; j < argc; j++) {
+	VALUE v = argv[j];
+	if (st_delete(RHASH(hash)->tbl, &v, 0)) {
+	    p[i++] = argv[j];
+	}
+    }
+
+    return ary;
+}
+
+static VALUE
 rb_ary_uniq_bang(ary)
     VALUE ary;
 {
@@ -1618,6 +1668,73 @@
 }
 
 static VALUE
+rb_ary_squeeze_bang(argc, argv, ary)
+    int argc;
+    VALUE *argv;
+    VALUE ary;
+{
+    int included;
+    long i, j, k, len;
+    VALUE *ptr, prev;
+
+    len = RARRAY(ary)->len;
+
+    if (len <= 1) return ary;
+
+    rb_ary_modify(ary);
+    ptr = RARRAY(ary)->ptr;
+
+    for (i = j = 0; ;) {
+	prev = ptr[j];
+
+	i++, j++;
+
+	if (len <= j) goto done;
+
+	if (argc > 0) {
+	    included = 0;
+
+	    for (k = 0; k < argc; k++) {
+		if (rb_equal(argv[k], ptr[j])) {
+		    included = 1;
+		    break;
+		}
+	    }
+	}
+	else {
+	    included = 1;
+	}
+
+	if (included) {
+	    while (rb_equal(prev, ptr[j])) {
+		j++;
+
+		if (len <= j) goto done;
+	    }
+	}
+
+	if (i != j) ptr[i] = ptr[j];
+    }
+
+  done:
+    RARRAY(ary)->len = RARRAY(ary)->capa = i;
+    REALLOC_N(RARRAY(ary)->ptr, VALUE, i);
+
+    return ary;
+}
+
+static VALUE
+rb_ary_squeeze(argc, argv, ary)
+    int argc;
+    VALUE *argv;
+    VALUE ary;
+{
+    ary = rb_ary_dup(ary);
+    rb_ary_squeeze_bang(argc, argv, ary);
+    return ary;
+}
+
+static VALUE
 rb_ary_nitems(ary)
     VALUE ary;
 {
@@ -1773,12 +1890,15 @@
     rb_define_method(rb_cArray, "&", rb_ary_and, 1);
     rb_define_method(rb_cArray, "|", rb_ary_or, 1);
 
+    rb_define_method(rb_cArray, "merge", rb_ary_merge, -1);
     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, "compact", rb_ary_compact, 0);
     rb_define_method(rb_cArray, "compact!", rb_ary_compact_bang, 0);
     rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0);
     rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, 0);
+    rb_define_method(rb_cArray, "squeeze", rb_ary_squeeze, -1);
+    rb_define_method(rb_cArray, "squeeze!", rb_ary_squeeze_bang, -1);
     rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0);
 
     cmp = rb_intern("<=>");

In This Thread

Prev Next