[#26463] New Features for the Array Module — Daniel Cohen <danielc2017@...>
To Whom it May Concern:
[#26488] Add Standard Deviation Function to Math Module — Daniel Cohen <danielc2017@...>
This patch adds a Standard Deviation function to the Math Module. It takes
Hi,
OK,
Hi,
Matz,
Hi,
On Tue, Nov 3, 2009 at 16:56, Yusuke ENDOH <mame@tsg.ne.jp> wrote:
On Nov 3, 2009, at 8:28 PM, Cameron McBride wrote:
2009/11/4 Yusuke ENDOH <mame@tsg.ne.jp>:
[#26492] HashWithIndifferentAccess to core — Urabe Shyouhei <shyouhei@...>
Hello,
Hi,
On Tue, Nov 3, 2009 at 6:48 AM, Yukihiro Matsumoto <matz@ruby-lang.org> wro=
Just a thought: What about implementing this with an option on Hash:new,
Hi,
Hi,
2009/11/6 Yukihiro Matsumoto <matz@ruby-lang.org>:
Hi,
Hi,
I'm not sure that it really makes sense to add any of this to core.
On Sat, Nov 7, 2009 at 10:21 AM, Rick DeNatale <rick.denatale@gmail.com> wrote:
On Nov 7, 2009, at 1:57 PM, Jeremy Kemper wrote:
On Sat, Nov 7, 2009 at 3:14 PM, James Edward Gray II
Hi,
[#26497] [Bug #2326] 1.8.7 Segmentation fault — Johan Holmberg <redmine@...>
Bug #2326: 1.8.7 Segmentation fault
Issue #2326 has been updated by Hongli Lai.
[#26523] [Bug #2330] Non systematic segmentation fault with autoload rubyspec — Marc-Andre Lafortune <redmine@...>
Bug #2330: Non systematic segmentation fault with autoload rubyspec
Issue #2330 has been updated by Marc-Andre Lafortune.
Hi,
Argh... I can't reproduce my minimal case scenario anymore. Maybe
1) The minimal test case
Hi,
[#26540] [Bug #2336] pathname compare fails in windows — Roger Pack <redmine@...>
Bug #2336: pathname compare fails in windows
[#26560] [Feature #2340] Removing YAML/Syck — Yui NARUSE <redmine@...>
Feature #2340: Removing YAML/Syck
Issue #2340 has been updated by Yui NARUSE.
On Nov 6, 2009, at 4:02 AM, Yui NARUSE wrote:
> > Issue #2340 has been updated by Yui NARUSE.
Jon wrote:
> > If you're looking at alternatives, does http://pyyaml.org/wiki/LibYAML
On Sat, Nov 07, 2009 at 12:59:25AM +0900, NARUSE, Yui wrote:
Aaron Patterson wrote:
On Sat, Nov 07, 2009 at 09:21:06PM +0900, NARUSE, Yui wrote:
On Sat, Nov 7, 2009 at 2:52 PM, Aaron Patterson
2009/11/12 5:47, Charles Oliver Nutter wrote:
On Fri, Nov 6, 2009 at 16:00, James Edward Gray II
On Nov 6, 2009, at 9:48 AM, Nikolai Weibull wrote:
James Edward Gray II wrote:
On Fri, Nov 6, 2009 at 18:38, Joel VanderWerf <vjoel@path.berkeley.edu> wro=
Issue #2340 has been updated by Yui NARUSE.
[#26563] [Bug #2343] Timeout.timeout doesn't raise Timeout::Error by default — Hongli Lai <redmine@...>
Bug #2343: Timeout.timeout doesn't raise Timeout::Error by default
[#26623] Re: [ruby-cvs:32896] Ruby:r25678 (trunk): * ext/dl/cptr.c (rb_dlptr_s_malloc, rb_dlptr_initialize): adding — Tanaka Akira <akr@...>
In article <200911062250.nA6Mo69d010341@ci.ruby-lang.org>,
In article <87y6mhb180.fsf@fsij.org>,
On Thu, Nov 12, 2009 at 11:54:49AM +0900, Tanaka Akira wrote:
[#26632] [Feature #2347] Math::INFINITY — Marc-Andre Lafortune <redmine@...>
Feature #2347: Math::INFINITY
2009/11/9 Marc-Andre Lafortune <redmine@ruby-lang.org>:
[#26635] [Feature #2348] RBTree Should be Added to the Standard Library — James Gray <redmine@...>
Feature #2348: RBTree Should be Added to the Standard Library
Issue #2348 has been updated by James Gray.
Hi,
Hi,
Hi,
Yusuke ENDOH wrote:
2010/3/22 Bill Kelly <billk@cts.com>:
[#26650] [Feature #2350] Unicode specific functionality on String in 1.9 — Manfred Stienstra <redmine@...>
Feature #2350: Unicode specific functionality on String in 1.9
Issue #2350 has been updated by Yusuke Endoh.
On Thu, Mar 25, 2010 at 14:45, Yusuke Endoh <redmine@ruby-lang.org> wrote:
(2010/03/26 0:02), Nikolai Weibull wrote:
On Thu, Mar 25, 2010 at 18:24, NARUSE, Yui <naruse@airemix.jp> wrote:
On Thu, Mar 25, 2010 at 19:33, Nikolai Weibull <now@bitwi.se> wrote:
The problem is that the definition of #upcase doesn't only depend on the
On Fri, Mar 18, 2011 at 11:53, Magnus Holm <judofyr@gmail.com> wrote:
[#26652] [Bug #2351] system() hardlinked to /bin/sh — Marcus Franke <redmine@...>
Bug #2351: system() hardlinked to /bin/sh
Issue #2351 has been updated by Motohiro KOSAKI.
[#26668] [Bug #2353] hash.c:setenv causes crashes in Solaris — Christian Höltje <redmine@...>
Bug #2353: hash.c:setenv causes crashes in Solaris
[#26704] Maintainer confirmation process done. — "Yugui (Yuki Sonoda)" <yugui@...>
I'm sorry for my closing the maintainer confirmation process so late.
On Thu, Nov 12, 2009 at 05:29:55PM +0900, Yugui (Yuki Sonoda) wrote:
Aaron Patterson wrote:
[#26722] [Bug #2362] undefined variable has value? — Vit Ondruch <redmine@...>
Bug #2362: undefined variable has value?
[#26735] warnings on build — Roger Pack <rogerdpack@...>
As an FYI, I get these at compile time:
[#26736] [Bug #2365] Matrix: poor handling of coercion errors [patch] — Marc-Andre Lafortune <redmine@...>
Bug #2365: Matrix: poor handling of coercion errors [patch]
Issue #2365 has been updated by Marc-Andre Lafortune.
Hi,
Hi,
[#26745] [Bug #2371] [BUG] thread_free: locking _mutex must be NULL — Chris Schlaeger <redmine@...>
Bug #2371: [BUG] thread_free: locking _mutex must be NULL
[#26753] (send #2) cgi.rb cleanup — Ryan Davis <ryand-ruby@...>
(not sure why my previous email about this got dropped)
Hi,
[#26767] [Bug #2376] Kernel.__method__ rubyspec failures for 1.8.* — Vladimir Sizikov <redmine@...>
Bug #2376: Kernel.__method__ rubyspec failures for 1.8.*
[#26771] [Bug #2377] update documentation for IO#eof? — Roger Pack <redmine@...>
Bug #2377: update documentation for IO#eof?
[#26772] [Bug #2378] Regression in ParseDate.parsedate('nn-nn') — Vladimir Sizikov <redmine@...>
Bug #2378: Regression in ParseDate.parsedate('nn-nn')
Issue #2378 has been updated by Hiro Asari.
[#26774] Ruby constant lookup — Yehuda Katz <wycats@...>
Over the past six months or so, I have been working with the new Ruby 1.9
Hi,
Shugo,
Hi,
On Tue, Nov 17, 2009 at 1:29 AM, Shugo Maeda <shugo@ruby-lang.org> wrote:
Hi,
On Sun, Nov 22, 2009 at 8:08 PM, Shugo Maeda <shugo@ruby-lang.org> wrote:
On Mon, Nov 23, 2009 at 8:08 AM, Rick DeNatale <rick.denatale@gmail.com> wr=
Hi,
Shugo,
[#26788] [Bug #2380] IO#eof? behavior different with 1.9.1p243-mingw32 than other platforms — Ian Dees <redmine@...>
Bug #2380: IO#eof? behavior different with 1.9.1p243-mingw32 than other platforms
Issue #2380 has been updated by Vit Ondruch.
[#26837] [Bug #2389] REXML rails to format parsed SVGs created with inkscape — Alexey Froloff <redmine@...>
Bug #2389: REXML rails to format parsed SVGs created with inkscape
[#26852] Internals: #to_s .vs. #to_str? — Kurt Stephens <ks@...>
Is there a description of the semantic differences between #to_s and
[#26868] [Bug #2392] "Date.valid_civil?" issue in p383 — Ozgun Koyun <redmine@...>
Bug #2392: "Date.valid_civil?" issue in p383
[#26869] Caching #to_s for immutables (and a possible future for constant-folding) — Kurt Stephens <ks@...>
I have a proof-of-concept patch to MRI that caches #to_s values for
> =A0It reduces the number of #to_s Strings created during the MRI test sui=
The attached patch add caching of #to_s results to the main immutable
> Yes. =A0The MRI test suite runs at 45 sec with these changes and at 53 se=
I just ran rubyspec against it; ~ 5% time improvement.
Attached is a new version of the patch.
Hi,
On Tue, Dec 1, 2009 at 18:19, Yusuke ENDOH <mame@tsg.ne.jp> wrote:
Nikolai Weibull wrote:
[#26877] [Bug #2394] [BUG] pthread_mutex_lock: 22 revisited — Roger Pack <redmine@...>
Bug #2394: [BUG] pthread_mutex_lock: 22 revisited
[#26889] email from redmine — danielcavanagh@...
hi
[#26931] Re: something broke ruby floats — Ryan Davis <ryand-ruby@...>
CC'ing ruby-core@
[#26939] Methods with default params not at the end and with rest params — Vladimir Sizikov <vsizikov@...>
Hi,
Hi,
Hi Matz,
[#26943] [Bug #2412] CSV regression after revision 25952 — Alexey Froloff <redmine@...>
Bug #2412: CSV regression after revision 25952
[ruby-core:26593] Re: HashWithIndifferentAccess to core
Hi,
I've been toying with allowing custom hashing from the Ruby side for
the past 2 days and have a semi-functional version (patch attached
against subversion trunk 25671 - http://gist.github.com/228773),
however my lack of VM control frame knowledge pretty much blocks
progress atm.
Experimental API :
Hash#index_with(Object)
The general expected contract being the object implements 2 methods,
hash(a) and compare(a,b)
Here's a rough HashWithIndifferentAccess ( referenced as "hwia" moving
forward) implementation :
module Hwia
def hash(obj)
case obj
when Symbol, String
obj.to_s.hash
else
obj.hash
end
end
def compare(a,b)
if String === a && Symbol === b || String === b && Symbol === a
a.to_s <=> b.to_s
else
a <=> b
end
end
extend self
end
h = { "foo" => "bar" }
h.index_with(Hwia)
h[:foo] # "bar"
Hash#custom_index? #=> true | false
Hash#indexed_with #=> Object
Given the arguments accepted by st_hash_type members being restricted
to 1 and 2 arguments respectively, I opted for falling back to the
current
ruby control frame after consulting with Aman Gupta, who also uses
this in perftools.rb to get to self :
rb_thread_t *th = GET_THREAD();
VALUE hash = th->cfp->self;
Which works OK initially, but results in
2) Error:
test_index_with(TestHash):
TypeError: wrong argument type TestHash (expected Hash)
test/ruby/test_hash.rb:906:in `test_index_with'
after passing through rb_hash_aref in :
h.index_with(Hwia)
assert_equal Hwia, h.indexed_with
assert h.custom_index?
h["foo"] # fails
as th->cfp->self becomes TestHash in that scope.
Any thoughts / feedback much appreciated.Apologies for the naming
confusion in the original mailing list post as well.
The current source tree is available at : http://github.com/methodmissing/ruby/tree/custom_hashing
- Lourens
methodmissing:ruby lourens$ git diff --patch-with-stat github/
trunk..HEAD
gc.c | 1 +
hash.c | 70 +++++++++++++++++++++++++++++++++++++++
+++++++-
include/ruby/ruby.h | 2 +
test/ruby/test_hash.rb | 36 ++++++++++++++++++++++++
4 files changed, 107 insertions(+), 2 deletions(-)
diff --git a/gc.c b/gc.c
index 7711101..55cdb85 100644
--- a/gc.c
+++ b/gc.c
@@ -1697,6 +1697,7 @@ gc_mark_children(rb_objspace_t *objspace, VALUE
ptr, int lev)
case T_HASH:
mark_hash(objspace, obj->as.hash.ntbl, lev);
+ gc_mark(objspace, obj->as.hash.index_with, lev);
ptr = obj->as.hash.ifnone;
goto again;
diff --git a/hash.c b/hash.c
index ef8b9a8..66280b6 100644
--- a/hash.c
+++ b/hash.c
@@ -14,6 +14,7 @@
#include "ruby/ruby.h"
#include "ruby/st.h"
#include "ruby/util.h"
+#include "vm_core.h"
#ifdef __APPLE__
#include <crt_externs.h>
@@ -33,7 +34,7 @@ rb_hash_freeze(VALUE hash)
VALUE rb_cHash;
static VALUE envtbl;
-static ID id_hash, id_yield, id_default;
+static ID id_hash, id_yield, id_default, id_compare;
static int
rb_any_cmp(VALUE a, VALUE b)
@@ -99,11 +100,37 @@ rb_any_hash(VALUE a)
return (st_index_t)RSHIFT(hnum, 1);
}
+static int
+rb_custom_cmp(VALUE a, VALUE b)
+{
+ rb_thread_t *th = GET_THREAD();
+ VALUE hash = th->cfp->self;
+ Check_Type(hash, T_HASH);
+ return FIX2INT(rb_funcall(RHASH(hash)->index_with, id_compare, 2,
a, b));
+}
+
+static st_index_t
+rb_custom_hash(VALUE a)
+{
+ st_index_t hnum;
+ rb_thread_t *th = GET_THREAD();
+ VALUE hash = th->cfp->self;
+ Check_Type(hash, T_HASH);
+ hnum = FIX2LONG(rb_funcall(RHASH(hash)->index_with, id_hash, 1,
a));
+ hnum <<= 1;
+ return (st_index_t)RSHIFT(hnum, 1);
+}
+
static const struct st_hash_type objhash = {
rb_any_cmp,
rb_any_hash,
};
+static const struct st_hash_type customhash = {
+ rb_custom_cmp,
+ rb_custom_hash,
+};
+
static const struct st_hash_type identhash = {
st_numcmp,
st_numhash,
@@ -219,6 +246,7 @@ hash_alloc(VALUE klass)
OBJSETUP(hash, klass, T_HASH);
hash->ifnone = Qnil;
+ hash->index_with = Qnil;
return (VALUE)hash;
}
@@ -241,6 +269,7 @@ rb_hash_dup(VALUE hash)
FL_SET(ret, HASH_PROC_DEFAULT);
}
ret->ifnone = RHASH(hash)->ifnone;
+ ret->index_with = RHASH(hash)->index_with;
return (VALUE)ret;
}
@@ -492,7 +521,6 @@ VALUE
rb_hash_aref(VALUE hash, VALUE key)
{
VALUE val;
-
if (!RHASH(hash)->ntbl || !st_lookup(RHASH(hash)->ntbl, key,
&val)) {
return rb_funcall(hash, id_default, 1, key);
}
@@ -1080,6 +1108,7 @@ rb_hash_replace(VALUE hash, VALUE hash2)
}
rb_hash_foreach(hash2, replace_i, hash);
RHASH(hash)->ifnone = RHASH(hash2)->ifnone;
+ RHASH(hash)->index_with = RHASH(hash2)->index_with;
if (FL_TEST(hash2, HASH_PROC_DEFAULT)) {
FL_SET(hash, HASH_PROC_DEFAULT);
}
@@ -1852,6 +1881,37 @@ rb_hash_compare_by_id_p(VALUE hash)
return Qfalse;
}
+static VALUE
+rb_hash_index_with(VALUE hash, VALUE idx)
+{
+ if (rb_respond_to(idx, id_hash) && rb_respond_to(idx, id_compare)){
+ rb_hash_modify(hash);
+ RHASH(hash)->index_with = idx;
+ RHASH(hash)->ntbl->type = &customhash;
+ rb_hash_rehash(hash);
+ return hash;
+ }else{
+ rb_raise(rb_eRuntimeError, "a custom hashing scheme should
implement #hash(a) and #compare(a,b)");
+ }
+}
+
+static VALUE
+rb_hash_custom_index_p(VALUE hash)
+{
+ if (!RHASH(hash)->ntbl)
+ return Qfalse;
+ if (RHASH(hash)->ntbl->type == &customhash) {
+ return Qtrue;
+ }
+ return Qfalse;
+}
+
+static VALUE
+rb_hash_indexed_with(VALUE hash)
+{
+ return RHASH(hash)->index_with;
+}
+
static int path_tainted = -1;
static char **origenviron;
@@ -2647,6 +2707,7 @@ Init_Hash(void)
id_hash = rb_intern("hash");
id_yield = rb_intern("yield");
id_default = rb_intern("default");
+ id_compare = rb_intern("compare");
rb_cHash = rb_define_class("Hash", rb_cObject);
@@ -2716,6 +2777,11 @@ Init_Hash(void)
rb_define_method(rb_cHash,"compare_by_identity",
rb_hash_compare_by_id, 0);
rb_define_method(rb_cHash,"compare_by_identity?",
rb_hash_compare_by_id_p, 0);
+ rb_define_method(rb_cHash,"index_with", rb_hash_index_with, 1);
+ rb_define_method(rb_cHash,"indexed_with", rb_hash_indexed_with, 0);
+
+ rb_define_method(rb_cHash,"custom_index?",
rb_hash_custom_index_p, 0);
+#define RHASH_IDX_WITH(h) (RHASH(h)->index_with)
#define RHASH_SIZE(h) (RHASH(h)->ntbl ? RHASH(h)->ntbl-
>num_entries : 0)
#define RHASH_EMPTY_P(h) (RHASH_SIZE(h) == 0)
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index c860b25..4e3f7f9 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -871,4 +871,40 @@ class TestHash < Test::Unit::TestCase
def o.hash; 2<<100; end
assert_equal({x=>1}.hash, {x=>1}.hash)
end
+
+ module Hwia
+ def hash(obj)
+ case obj
+ when Symbol, String
+ obj.to_s.hash
+ else
+ obj.hash
+ end
+ end
+
+ def compare(a,b)
+ if String === a && Symbol === b || String === b && Symbol === a
+ a.to_s <=> b.to_s
+ else
+ a <=> b
+ end
+ end
+ extend self
+ end
+
+ def test_index_with
+ a = "foo"
+ assert(!{}.custom_index?)
+ h = { a => "bar" }
+ assert_equal nil, h.indexed_with
+ assert_raises(RuntimeError) do
+ h.index_with(Object.new)
+ end
+ h.index_with(Hwia)
+ assert_equal Hwia, h.indexed_with
+ assert h.custom_index?
+ h["foo"]
+ #assert_equal "bar", h["foo"]
+ #assert_equal "bar", h[:foo]
+ end
end
On 2009/11/07, at 13:10, Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: [ruby-core:26584] Re: HashWithIndifferentAccess to
> core"
> on Sat, 7 Nov 2009 20:06:07 +0900, Yugui <yugui@yugui.jp> writes:
>
> |How about Hash::Type class as an API for rb_hash_type?
>
> Depends on API, and performance.
>
> matz.
>