[#34011] Should --verbose be equal to -v ? — Yugui <yugui@...>

Yuguiです。

15 messages 2008/03/10
[#34012] Re: Should --verbose be equal to -v ? — Yukihiro Matsumoto <matz@...> 2008/03/10

まつもと ゆきひろです

[#34105] rational.rb, complex.rb and mathn.rb — Tadayoshi Funaba <tadf@...>

rational と complex が組み込みになったことで、lib/mathn.rb の意義は薄

29 messages 2008/03/22
[#34106] Re: rational.rb, complex.rb and mathn.rb — Tadayoshi Funaba <tadf@...> 2008/03/22

現時点で rational.rb と complex.rb を残しているのは、それが無難だから

[#34107] Re: rational.rb, complex.rb and mathn.rb — Tadayoshi Funaba <tadf@...> 2008/03/22

で、かなり選択肢を絞った叩き台です。

[#34120] Re: rational.rb, complex.rb and mathn.rb — keiju@... (石塚圭樹) 2008/03/24

けいじゅ@いしつかです.

[#34125] Re: rational.rb, complex.rb and mathn.rb — Shin-ichiro HARA <sinara@...> 2008/03/25

原です。

[#34130] Re: rational.rb, complex.rb and mathn.rb — Tadayoshi Funaba <tadf@...> 2008/03/25

> 私も Complex の組み込みは Rational とは比較にならないくらい、仕様が決め

[#34158] Complex組み込み — Masahiro TANAKA <masa16.tanaka@...>

Complexが組み込みになるそうですが、これはcomplex.rbを踏襲して、

49 messages 2008/03/27
[#34161] Re: Complex組み込み — Shin-ichiro HARA <sinara@...> 2008/03/28

原です。

[#34168] Re: Complex組み込み — Tadayoshi Funaba <tadf@...> 2008/03/28

> 今までの Complex は、complex.rb にほぼ残して、たとえば Rational 成分

[#34186] Re: Complex組み込み — Shin-ichiro HARA <sinara@...> 2008/03/31

原です。

[#34187] Re: Complex組み込み — Tadayoshi Funaba <tadf@...> 2008/03/31

> そうです。Complex が難しい、という話を書いておくと、

[#34193] Re: Complex組み込み — Yukihiro Matsumoto <matz@...> 2008/03/31

まつもと ゆきひろです

[#34203] Re: Complex組み込み — Tadayoshi Funaba <tadf@...> 2008/04/01

> |僕としては、/ 演算子の振舞いについて前向きに検討してほしいです。

[#34215] Re: Complex組み込み — Yukihiro Matsumoto <matz@...> 2008/04/02

まつもと ゆきひろです

[#34166] Re: Complex組み込み — Tadayoshi Funaba <tadf@...> 2008/03/28

> となるようですが、別の実装として、

[ruby-dev:34026] Re: MurmurHash problem

From: "NARUSE, Yui" <naruse@...>
Date: 2008-03-12 10:50:18 UTC
List: ruby-dev #34026
成瀬です。

というわけで、int32_t, uint32_t, intptr_t, uintptr_t を定義しつつ、
hash() をアライメント考慮させるパッチです。

U.Nakamura wrote:
> | あとは int と long の使い分けでしょうか。なんとなく、
> | * int はただの整数。
> | * long は文字列長や文字位置等、ポインタとの演算が行われうるもの。
> | かなぁと思っているのですが、LP64 だとint において 64bit 化の恩恵が受けられず、
> | LLP64 だと int == long != *void なので long を分ける意義がないなぁとか。
> | 後者は intptr_t にしてもよさそうな気もします。
> 
> longを禁止にすると私が喜ぶような気がします。
> が、世界中の拡張ライブラリ作者が泣くんじゃないですかね。

禁止は「ぎゃっ」どころのさわぎじゃなさそうですが、
Ruby 本体からの追放と非推奨化はできそうですよね。

-- 
NARUSE, Yui  <[email protected]>
DBDB A476 FDBD 9450 02CD 0EFC BCE3 C388 472E C1EA

Attachments (1)

murmurhash.patch (3.95 KB, text/x-diff)
--- configure.in	(revision 15758)
+++ configure.in	(working copy)
@@ -273,6 +273,19 @@ AC_CHECK_SIZEOF(float, 4)
 AC_CHECK_SIZEOF(double, 8)
 AC_CHECK_SIZEOF(time_t, 0)
 
+AC_CHECK_SIZEOF(int, 4)
+AC_CHECK_SIZEOF(short, 2)
+AC_CHECK_SIZEOF(long, 4)
+AC_CHECK_SIZEOF(long long, 0)
+AC_CHECK_SIZEOF(__int64, 0)
+AC_CHECK_SIZEOF(off_t, 0)
+AC_CHECK_SIZEOF(void*, 4)
+AC_CHECK_SIZEOF(float, 4)
+AC_CHECK_SIZEOF(double, 8)
+AC_CHECK_SIZEOF(time_t, 0)
+
+AC_CHECK_TYPES([int32_t, uint32_t, intptr_t, uintptr_t])
+
 dnl RUBY_REPLACE_TYPE [typename] [default type] [macro type] [included]
 AC_DEFUN([RUBY_REPLACE_TYPE], [dnl
     AC_CHECK_TYPE([$1],
--- include/ruby/defines.h	(revision 15758)
+++ include/ruby/defines.h	(working copy)
@@ -99,6 +99,51 @@ void xfree(void*);
 # define BDIGIT_DBL_SIGNED long
 #endif
 
+/* define additional integer types
+ *
+ * int32_t, uint32_t, intptr_t, uintptr_t is now defined.
+ */
+
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+
+#ifndef HAVE_INT32_T
+# if SIZEOF_INT == 4
+typedef int int32_t;
+# else
+#  error ---->> int32_t is not defined and no available fallbacks. <<----
+# endif
+#endif
+
+#ifndef HAVE_UINT32_T
+# if SIZEOF_INT == 4
+typedef unsigned int uint32_t
+# else
+#  error ---->> uint32_t is not defined and no available fallbacks. <<----
+# endif
+#endif
+
+#ifndef HAVE_INTPTR_T
+# if SIZEOF_LONG == SIZEOF_VOIDP
+typedef long intptr_t;
+# elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
+typedef long long intptr_t;
+# else
+#  error ---->> intptr_t is not defined and no available fallbacks. <<----
+# endif
+#endif
+
+#ifndef HAVE_UINTPTR_T
+# if SIZEOF_LONG == SIZEOF_VOIDP
+typedef unsigned long uintptr_t;
+# elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
+typedef unsigned long long uintptr_t;
+# else
+#  error ---->> uintptr_t is not defined and no available fallbacks. <<----
+# endif
+#endif
+
 #ifdef __CYGWIN__
 #undef _WIN32
 #endif
--- string.c	(revision 15758)
+++ string.c	(working copy)
@@ -1686,40 +1686,88 @@ rb_str_concat(VALUE str1, VALUE str2)
 }
 
 /* MurmurHash described in http://murmurhash.googlepages.com/ */
-unsigned int
-hash(const unsigned char * data, int len, unsigned int h)
-{
-    const unsigned int m = 0x7fd652ad;
-    const int r = 16;
+#ifdef WORDS_BIGENDIAN
+#define swap32(x)	((((x)&0xFF)<<24)	\
+			|(((x)>>24)&0xFF)	\
+			|(((x)&0x0000FF00)<<8)	\
+			|(((x)&0x00FF0000)>>8)	)
+#define htov32(x) swap32(x)
+#else
+#define htov32(x) x
+#endif
+static uint32_t
+hash(const unsigned char * data, intptr_t len, uint32_t h)
+{
+    const uint32_t m = 0xc6a4a793;
+    const int32_t r = 16;
+    intptr_t align = (intptr_t)data & 3;
 
     h += 0xdeadbeef;
 
-    while(len >= 4) {
-	h += *(unsigned int *)data;
-	h *= m;
-	h ^= h >> r;
+    if (len < 4) {
+    }
+    else if(align) {
+	uint32_t t = 0, d = 0, sl = 8 * (4-align), sr = 8 * align;
+	intptr_t pack;
+
+	switch(align) {
+	case 1: t |= data[2] << 16;
+	case 2: t |= data[1] << 8;
+	case 3: t |= data[0];
+	default:t <<= (8 * align);
+	}
+	data += 4-align;
+	len -= 4-align;
+
+	while (len >= 4) {
+	    d = htov32(*(uint32_t *)data);
+	    t = (t >> sr) | (d << sl);
+	    h += t;
+	    h *= m;
+	    h ^= h >> r;
+	    t = d;
+	    data += 4;
+	    len -= 4;
+	}
+
+	pack = len < align ? len : align;
+	d = 0;
+	switch(pack) {
+	case 3: d |= data[2] << 16;
+	case 2: d |= data[1] << 8;
+	case 1: d |= data[0];
+	case 0: h += (t >> sr) | (d << sl);
+	    h *= m;
+	    h ^= h >> r;
+	}
+	data += pack;
+	len -= pack;
+    }
+    else {
+	while (len >= 4) {
+	    h += htov32(*(uint32_t *)data);
+	    h *= m;
+	    h ^= h >> r;
 
-	data += 4;
-	len -= 4;
+	    data += 4;
+	    len -= 4;
+	}
     }
 
-    switch(len) {
-      case 3:
-	h += data[2] << 16;
-      case 2:
-	h += data[1] << 8;
-      case 1:
-	h += data[0];
+    switch(len)
+    {
+    case 3: h += data[2] << 16;
+    case 2: h += data[1] << 8;
+    case 1: h += data[0];
 	h *= m;
 	h ^= h >> r;
-    };
-
+    }
     h *= m;
     h ^= h >> 10;
     h *= m;
     h ^= h >> 17;
 
-    return h;
+    return (int32_t)h;
 }
 
 int

In This Thread