[#13765] GenerativeHash — TAKAHASHI Masayoshi <maki@...>

高橋征義です。

17 messages 2001/07/08
[#13769] Re: GenerativeHash — matz@... (Yukihiro Matsumoto) 2001/07/09

まつもと ゆきひろです

[#13774] mkmf.rb: cleaning facility — Takaaki Tateishi <ttate@...>

立石です.

14 messages 2001/07/09

[#13800] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — nobu.nakada@...

なかだです。

20 messages 2001/07/10
[#13801] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — WATANABE Hirofumi <eban@...> 2001/07/10

わたなべです。

[#13802] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — matz@... (Yukihiro Matsumoto) 2001/07/10

まつもと ゆきひろです

[#13804] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — WATANABE Hirofumi <eban@...> 2001/07/10

わたなべです。

[#13805] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — matz@... (Yukihiro Matsumoto) 2001/07/10

まつもと ゆきひろです

[#13806] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — WATANABE Hirofumi <eban@...> 2001/07/10

わたなべです。

[#13807] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — matz@... (Yukihiro Matsumoto) 2001/07/10

まつもと ゆきひろです

[#13808] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — "Akinori MUSHA" <knu@...> 2001/07/10

At Tue, 10 Jul 2001 15:23:04 +0900,

[#13809] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — WATANABE Hirofumi <eban@...> 2001/07/10

わたなべです。

[#13810] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — "Akinori MUSHA" <knu@...> 2001/07/10

At Tue, 10 Jul 2001 16:50:52 +0900,

[#13811] Re: [ruby-cvs] ruby: * ruby.h: fix a wrong function name: rb_iglob() -> rb_globi(). — "Akinori MUSHA" <knu@...> 2001/07/10

 もうひとつあった。

[#13828] supported platforms / K&R — "Akinori MUSHA" <knu@...>

 digest モジュールの各プラットフォームでの動作確認をお願いした

39 messages 2001/07/13
[#14389] Re: supported platforms / K&R — Koji Arai <JCA02266@...> 2001/08/08

新井です。

[#14399] Re: supported platforms / K&R — Takashi Shimizu <simtak@...> 2001/08/09

清水@biglobeです。

[#14404] Re: supported platforms / K&R — Koji Arai <JCA02266@...> 2001/08/09

新井です。

[#14461] Re: supported platforms / K&R — Takashi Shimizu <simtak@...> 2001/08/14

清水@biglobe です。

[#14466] Re: supported platforms / K&R — nobu.nakada@... 2001/08/14

なかだです。

[#14468] Re: supported platforms / K&R — Koji Arai <JCA02266@...> 2001/08/14

新井です。

[#14477] recursive malloc (Re: supported platforms / K&R) — Koji Arai <JCA02266@...> 2001/08/15

新井です。

[#14482] Re: recursive malloc (Re: supported platforms / K&R) — nobu.nakada@... 2001/08/15

なかだです。

[#14486] Re: recursive malloc (Re: supported platforms / K&R) — Koji Arai <JCA02266@...> 2001/08/15

新井です。

[#14490] Re: recursive malloc (Re: supported platforms/ K&R) — nobu.nakada@... 2001/08/15

なかだです。

[#14492] Re: recursive malloc (Re: supported platforms/ K&R) — Koji Arai <JCA02266@...> 2001/08/15

新井です。

[#14493] Re: recursive malloc (Re: supportedplatforms/ K&R) — nobu.nakada@... 2001/08/15

なかだです。

[#13878] Prototype for rb_gc_mark / volatile in ruby.h — Tietew <tietew@...>

Tietew です。

18 messages 2001/07/15
[#13880] Re: Prototype for rb_gc_mark / volatile in ruby.h — matz@... (Yukihiro Matsumoto) 2001/07/16

まつもと ゆきひろです

[#13940] IO#read — "Akinori MUSHA" <knu@...>

 IO#read を使って何度もストリームから読み込むような処理をする

20 messages 2001/07/19

[#13959] Re: [ruby-list:30682] Re: overwride method — "Akinori MUSHA" <knu@...>

At Fri, 20 Jul 2001 21:09:36 +0900,

95 messages 2001/07/20
[#13963] Re: [ruby-list:30682] Re: overwride method — GOTO Kentaro <gotoken@...> 2001/07/20

ごとけんです

[#13965] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/21

まつもと ゆきひろです

[#13967] Re: [ruby-list:30682] Re: overwride method — GOTO Kentaro <gotoken@...> 2001/07/21

ごとけんです

[#13969] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/21

まつもと ゆきひろです

[#13980] Re: [ruby-list:30682] Re: overwride method — GOTO Kentaro <gotoken@...> 2001/07/21

[ruby-dev:13969]>

[#13981] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/21

まつもと ゆきひろです

[#13984] Re: [ruby-list:30682] Re: overwride method — GOTO Kentaro <gotoken@...> 2001/07/22

ごとけんです

[#13993] Re: [ruby-list:30682] Re: overwride method — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/07/23

なひです。

[#13994] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/23

まつもと ゆきひろです

[#13995] Re: [ruby-list:30682] Re: overwride method — keiju@... (石塚圭樹) 2001/07/23

けいじゅ@日本ラショナルソフトウェアです.

[#13996] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/23

まつもと ゆきひろです

[#13997] Re: [ruby-list:30682] Re: overwride method — keiju@... (石塚圭樹) 2001/07/23

けいじゅ@日本ラショナルソフトウェアです.

[#13998] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/23

まつもと ゆきひろです

[#14000] Re: [ruby-list:30682] Re: overwride method — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/07/23

なひです。

[#14005] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/23

まつもと ゆきひろです

[#14016] Re: [ruby-list:30682] Re: overwride method — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/07/24

なひです。

[#14021] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/24

まつもと ゆきひろです

[#14022] Re: [ruby-list:30682] Re: overwride method — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/07/24

なひです。

[#14023] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/24

まつもと ゆきひろです

[#14037] Re: [ruby-list:30682] Re: overwride method — GOTO Kentaro <gotoken@...> 2001/07/24

ごとけんです

[#14039] Re: [ruby-list:30682] Re: overwride method — Masatoshi SEKI <m_seki@...> 2001/07/24

[#14040] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/24

まつもと ゆきひろです

[#14043] Re: [ruby-list:30682] Re: overwride method — m_seki@... 2001/07/24

[#14053] Re: [ruby-list:30682] Re: overwride method — matz@... (Yukihiro Matsumoto) 2001/07/25

まつもと ゆきひろです

[#14082] private instance variable と _dump/_load — Masatoshi SEKI <m_seki@...> 2001/07/25

[#14084] Re: private instance variable と _dump/_load — keiju@... (石塚圭樹) 2001/07/25

けいじゅ@日本ラショナルソフトウェアです.

[#14087] Re: private instance variable と _dump/_load — matz@... (Yukihiro Matsumoto) 2001/07/25

まつもと ゆきひろです

[#14089] Re: private instance variable と _dump/_load — keiju@... (石塚圭樹) 2001/07/25

けいじゅ@日本ラショナルソフトウェアです.

[#14094] Re: private instance variable と _dump/_load — matz@... (Yukihiro Matsumoto) 2001/07/26

まつもと ゆきひろです

[#14133] Re: private instance variable と _dump/_load — "Shin'ya Adzumi" <adzumi@...> 2001/07/27

あづみです。

[#14134] Re: private instance variable と _dump/_load — matz@... (Yukihiro Matsumoto) 2001/07/27

まつもと ゆきひろです

[#14140] Re: private instance variable と _dump/_load — Kazuhiro NISHIYAMA <zn@...> 2001/07/27

In <996211878.306635.31396.nullmailer@ev.netlab.jp>

[#14143] Re: private instance variable と _dump/_load — matz@... (Yukihiro Matsumoto) 2001/07/27

まつもと ゆきひろです

[#14144] Re: private instance variable と _dump/_load — Kazuhiro NISHIYAMA <zn@...> 2001/07/27

In <996255758.830993.629.nullmailer@ev.netlab.jp>

[#14066] Re: [ruby-list:30682] Re: overwride method — "Shin'ya Adzumi" <adzumi@...> 2001/07/25

あづみです。

[#14068] private instance variable (Re: Re: overwride method) — matz@... (Yukihiro Matsumoto) 2001/07/25

まつもと ゆきひろです

[#14099] Is private instance variable really needed? — Shugo Maeda <shugo@...> 2001/07/26

前田です。

[#14104] Re: Is private instance variable really needed? — matz@... (Yukihiro Matsumoto) 2001/07/26

まつもと ゆきひろです

[#14026] Exception in coerce — Shin-ichiro HARA <sinara@...>

原です。

21 messages 2001/07/24
[#14027] Re: Exception in coerce — matz@... (Yukihiro Matsumoto) 2001/07/24

まつもと ゆきひろです

[#14028] Re: Exception in coerce — Shin-ichiro HARA <sinara@...> 2001/07/24

原です。

[#14029] Re: Exception in coerce — matz@... (Yukihiro Matsumoto) 2001/07/24

まつもと ゆきひろです

[#14030] Re: Exception in coerce — matz@... (Yukihiro Matsumoto) 2001/07/24

まつもと ゆきひろです

[#14031] Re: Exception in coerce — Shin-ichiro HARA <sinara@...> 2001/07/24

原です。

[#14032] Re: Exception in coerce — matz@... (Yukihiro Matsumoto) 2001/07/24

まつもと ゆきひろです

[ruby-dev:13982] Re: GenerativeHash

From: nobu.nakada@...
Date: 2001-07-21 22:43:14 UTC
List: ruby-dev #13982
なかだです。

At Mon, 9 Jul 2001 21:17:24 +0900,
Nobuyoshi-Nakada wrote:
>   たぶんそうでしょうね。キーがある場合は検索が2回から1回に減る
> わけですが、ない場合は処理としてはかわりませんから。キーがなけ
> ればコールバックを呼んで挿入するという関数(ようするにfetch!)を、
> st.cに追加するのが一番速くなるとは思いますが。

  なんとなく。


Index: hash.c
===================================================================
RCS file: /cvs/ruby/src/ruby/hash.c,v
retrieving revision 1.49
diff -u -2 -p -r1.49 hash.c
--- hash.c	2001/06/22 09:12:19	1.49
+++ hash.c	2001/07/21 22:37:08
@@ -304,4 +304,11 @@ rb_hash_aref(hash, key)
 }
 
+NORETURN(static void key_not_found());
+static void
+key_not_found()
+{
+    rb_raise(rb_eIndexError, "key not found");
+}
+
 static VALUE
 rb_hash_fetch(argc, argv, hash)
@@ -323,5 +330,5 @@ rb_hash_fetch(argc, argv, hash)
 	}
 	if (argc == 1) {
-	    rb_raise(rb_eIndexError, "key not found");
+	    key_not_found();
 	}
 	return if_none;
@@ -331,4 +338,43 @@ rb_hash_fetch(argc, argv, hash)
 
 static VALUE
+fetch_bang_block(key, hash)
+    VALUE key, hash;
+{
+    VALUE val = rb_yield(key);
+    rb_hash_modify(hash);
+    return val;
+}
+
+static VALUE
+fetch_bang_default(key, arg)
+    VALUE key, *arg;
+{
+    rb_hash_modify(arg[0]);
+    return arg[1];
+}
+
+static VALUE
+rb_hash_fetch_bang(argc, argv, hash)
+    int argc;
+    VALUE *argv;
+    VALUE hash;
+{
+    VALUE key, val;
+
+    if (rb_block_given_p()) {
+	rb_scan_args(argc, argv, "1", &key);
+	st_update(RHASH(hash)->tbl, key, &val, fetch_bang_block, hash);
+    }
+    else if (rb_scan_args(argc, argv, "11", &key, &val) == 1) {
+	st_update(RHASH(hash)->tbl, key, &val, key_not_found, 0);
+    }
+    else {
+	argv[0] = hash;
+	st_update(RHASH(hash)->tbl, key, &val, fetch_bang_default, (VALUE)argv);
+    }
+    return val;
+}
+
+static VALUE
 rb_hash_default(hash)
     VALUE hash;
@@ -916,36 +962,4 @@ rb_f_getenv(obj, name)
 }
 
-static VALUE
-env_fetch(argc, argv)
-    int argc;
-    VALUE *argv;
-{
-    VALUE key, if_none;
-    char *nam, *env;
-
-    rb_scan_args(argc, argv, "11", &key, &if_none);
-    StringValue(key);
-    nam = RSTRING(key)->ptr;
-    if (strlen(nam) != RSTRING(key)->len) {
-	rb_raise(rb_eArgError, "bad environment variable name");
-    }
-    env = getenv(nam);
-    if (!env) {
-	if (rb_block_given_p()) {
-	    if (argc > 1) {
-		rb_raise(rb_eArgError, "wrong # of arguments", argc);
-	    }
-	    return rb_yield(key);
-	}
-	if (argc == 1) {
-	    rb_raise(rb_eIndexError, "key not found");
-	}
-	return if_none;
-    }
-    if (strcmp(nam, "PATH") == 0 && !rb_env_path_tainted())
-	return rb_str_new2(env);
-    return rb_tainted_str_new2(env);
-}
-
 static void
 path_tainted_p(path)
@@ -1150,4 +1164,54 @@ rb_f_setenv(obj, nm, val)
 
 static VALUE
+env_fetch_1(argc, argv, update)
+    int argc;
+    VALUE *argv;
+    int update;
+{
+    VALUE key, if_none;
+    char *nam, *env;
+
+    rb_scan_args(argc, argv, "11", &key, &if_none);
+    StringValue(key);
+    nam = RSTRING(key)->ptr;
+    if (strlen(nam) != RSTRING(key)->len) {
+	rb_raise(rb_eArgError, "bad environment variable name");
+    }
+    env = getenv(nam);
+    if (!env) {
+	if (rb_block_given_p()) {
+	    if (argc > 1) {
+		rb_raise(rb_eArgError, "wrong # of arguments (%d for %d)", argc, 1);
+	    }
+	    if_none = rb_yield(key);
+	}
+	else if (argc == 1) {
+	    key_not_found();
+	}
+	if (update) rb_f_setenv(envtbl, nam, if_none);
+	return if_none;
+    }
+    if (strcmp(nam, "PATH") == 0 && !rb_env_path_tainted())
+	return rb_str_new2(env);
+    return rb_tainted_str_new2(env);
+}
+
+static VALUE
+env_fetch(argc, argv)
+    int argc;
+    VALUE *argv;
+{
+    return env_fetch_1(argc, argv, 0);
+}
+
+static VALUE
+env_fetch_bang(argc, argv)
+    int argc;
+    VALUE *argv;
+{
+    return env_fetch_1(argc, argv, 1);
+}
+
+static VALUE
 env_keys()
 {
@@ -1469,4 +1533,5 @@ Init_Hash()
     rb_define_method(rb_cHash,"[]", rb_hash_aref, 1);
     rb_define_method(rb_cHash,"fetch", rb_hash_fetch, -1);
+    rb_define_method(rb_cHash,"fetch!", rb_hash_fetch_bang, -1);
     rb_define_method(rb_cHash,"[]=", rb_hash_aset, 2);
     rb_define_method(rb_cHash,"store", rb_hash_aset, 2);
@@ -1513,4 +1578,5 @@ Init_Hash()
     rb_define_singleton_method(envtbl,"[]", rb_f_getenv, 1);
     rb_define_singleton_method(envtbl,"fetch", env_fetch, -1);
+    rb_define_singleton_method(envtbl,"fetch!", env_fetch_bang, -1);
     rb_define_singleton_method(envtbl,"[]=", rb_f_setenv, 2);
     rb_define_singleton_method(envtbl,"store", rb_f_setenv, 2);
Index: st.c
===================================================================
RCS file: /cvs/ruby/src/ruby/st.c,v
retrieving revision 1.17
diff -u -2 -p -r1.17 st.c
--- st.c	2001/06/22 09:12:20	1.17
+++ st.c	2001/07/21 22:32:49
@@ -318,4 +318,30 @@ st_add_direct(table, key, value)
 }
 
+int
+st_update(table, key, value, callbk, arg)
+    st_table *table;
+    register char *key;
+    char **value;
+    char *(*callbk)();
+    char *arg;
+{
+    unsigned int hash_val, bin_pos;
+    register st_table_entry *ptr;
+
+    hash_val = do_hash(key, table);
+    FIND_ENTRY(table, ptr, hash_val, bin_pos);
+
+    if (ptr == 0) {
+	arg = (*callbk)(key, arg);
+	ADD_DIRECT(table, key, arg, hash_val, bin_pos);
+	if (value != 0) *value = arg;
+	return 0;
+    }
+    else {
+	if (value != 0) *value = ptr->record;
+	return 1;
+    }
+}
+
 static void
 rehash(table)
Index: st.h
===================================================================
RCS file: /cvs/ruby/src/ruby/st.h,v
retrieving revision 1.3
diff -u -2 -p -r1.3 st.h
--- st.h	2000/01/05 04:37:12	1.3
+++ st.h	2001/07/09 13:25:26
@@ -32,5 +32,5 @@ st_table *st_init_strtable();
 st_table *st_init_strtable_with_size();
 int st_delete(), st_delete_safe();
-int st_insert(), st_lookup();
+int st_insert(), st_lookup(), st_update();
 void st_foreach(), st_add_direct(), st_free_table(), st_cleanup_safe();
 st_table *st_copy();


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread

Prev Next