[#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:37933] Re: [Bug:1.9] lack consistency in hash iteration
遠藤です。
2009/02/06 1:01 Yusuke ENDOH <mame@tsg.ne.jp>:
> 同じ要素を複数回 yield する可能性があります。
>
> $ ./ruby -e 'h = {1=>1,2=>2}; h.each {|x| p x; h.delete(2) }'
> [1, 1]
> [1, 1]
>
> すぐには解決策が思いつかないので、ちょっと考えます。
現状の st_foreach だと、Hash のイテレート中にハッシュの要素を削除すると
削除されていない要素でも取りこぼすことがあるようです。
a = (1..3).map do |i|
x = Object.new
def x.hash; 1; end
x
end
h = {}
a.each {|x| h[x] = true }
p h #=> {#<Object:0x81fcdb0>=>true, #<Object:0x81fcce8>=>true,
#<Object:0x81fcc5c>=>true}
h.each do |x|
p x
h.delete(a[0])
h.delete(a[1])
end
#=> [#<Object:0x81fcdb0>, true] だけしか出ない、[#<Object:0x81fcc5c>=>true, true] は出るはず
p h #=> {#<Object:0x81fcc5c>=>true}
原因はイテレートの終了条件が正しくないためですが、Hash の順序を
ループ構造で管理している限り解決できないような気がしました。
順序を双方向リストで管理すれば直りました。
Index: include/ruby/st.h
===================================================================
--- include/ruby/st.h (revision 22101)
+++ include/ruby/st.h (working copy)
@@ -75,7 +75,7 @@
#endif
st_index_t num_entries : ST_INDEX_BITS - 1;
struct st_table_entry **bins;
- struct st_table_entry *head;
+ struct st_table_entry *head, *back;
};
#define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0)
Index: st.c
===================================================================
--- st.c (revision 22101)
+++ st.c (working copy)
@@ -176,6 +176,7 @@
tbl->num_bins = size;
tbl->bins = (st_table_entry **)Calloc(size, sizeof(st_table_entry*));
tbl->head = 0;
+ tbl->back = 0;
return tbl;
}
@@ -244,6 +245,7 @@
}
table->num_entries = 0;
table->head = 0;
+ table->back = 0;
}
void
@@ -335,7 +337,7 @@
#define ADD_DIRECT(table, key, value, hash_val, bin_pos)\
do {\
- st_table_entry *entry, *head;\
+ st_table_entry *entry;\
if (table->num_entries/(table->num_bins) > ST_DEFAULT_MAX_DENSITY) {\
rehash(table);\
bin_pos = hash_val % table->num_bins;\
@@ -347,13 +349,14 @@
entry->key = key;\
entry->record = value;\
entry->next = table->bins[bin_pos];\
- if ((head = table->head) != 0) {\
- entry->fore = head;\
- (entry->back = head->back)->fore = entry;\
- head->back = entry;\
+ if (table->head != 0) {\
+ entry->fore = 0;\
+ (entry->back = table->back)->fore = entry;\
+ table->back = entry;\
}\
else {\
- table->head = entry->fore = entry->back = entry;\
+ table->head = table->back = entry;\
+ entry->fore = entry->back = 0;\
}\
table->bins[bin_pos] = entry;\
table->num_entries++;\
@@ -455,7 +458,7 @@
hash_val = ptr->hash % new_num_bins;
ptr->next = new_bins[hash_val];
new_bins[hash_val] = ptr;
- } while ((ptr = ptr->fore) != table->head);
+ } while ((ptr = ptr->fore) != 0);
}
}
@@ -502,10 +505,8 @@
entry->back = prev;
*tail = prev = entry;
tail = &entry->fore;
- } while ((ptr = ptr->fore) != old_table->head);
- entry = new_table->head;
- entry->back = prev;
- *tail = entry;
+ } while ((ptr = ptr->fore) != 0);
+ new_table->back = prev;
}
return new_table;
@@ -513,14 +514,16 @@
#define REMOVE_ENTRY(table, ptr) do \
{ \
- if (ptr == ptr->fore) { \
+ if (ptr->fore == 0 && ptr->back == 0) { \
table->head = 0; \
+ table->back = 0; \
} \
else { \
st_table_entry *fore = ptr->fore, *back = ptr->back; \
- fore->back = back; \
- back->fore = fore; \
+ if (fore) fore->back = back; \
+ if (back) back->fore = fore; \
if (ptr == table->head) table->head = fore; \
+ if (ptr == table->back) table->back = back; \
} \
table->num_entries--; \
} while (0)
@@ -613,7 +616,7 @@
{
st_table_entry *ptr, **last, *tmp;
enum st_retval retval;
- int i, end;
+ int i;
if (table->entries_packed) {
for (i = 0; i < table->num_entries; i++) {
@@ -651,7 +654,6 @@
if ((ptr = table->head) != 0) {
do {
- end = ptr->fore == table->head;
retval = (*func)(ptr->key, ptr->record, arg);
switch (retval) {
case ST_CHECK: /* check if hash is modified during iteration */
@@ -683,7 +685,7 @@
}
}
}
- } while (!end && table->head);
+ } while (ptr && table->head);
}
return 0;
}
@@ -694,7 +696,7 @@
{
st_table_entry *ptr, **last, *tmp;
enum st_retval retval;
- int i, end;
+ int i;
if (table->entries_packed) {
for (i = table->num_entries-1; 0 <= i; i--) {
@@ -732,7 +734,6 @@
if ((ptr = table->head) != 0) {
ptr = ptr->back;
do {
- end = ptr == table->head;
retval = (*func)(ptr->key, ptr->record, arg, 0);
switch (retval) {
case ST_CHECK: /* check if hash is modified during iteration */
@@ -766,7 +767,7 @@
free(tmp);
table->num_entries--;
}
- } while (!end && table->head);
+ } while (ptr && table->head);
}
return 0;
}
--
Yusuke ENDOH <mame@tsg.ne.jp>