[#45942] win32ole and excel — Martin Stannard <martin@...>

Hi,

19 messages 2002/08/01

[#45948] "gets" blocking process not thread (in Windows only) — Matt Pattison <mfp@...>

The problem with my program is that (in Windows) gets seems to block the entire

13 messages 2002/08/01

[#46030] IO.readlines is slow ? — "Shashank Date" <ADATE@...>

I really like the convenience of doing:

18 messages 2002/08/02

[#46072] How to Load Script from a C Extension? — William Djaja Tjokroaminata <billtj@...>

Hi,

20 messages 2002/08/02

[#46107] embed or swig? — ptkwt@...1.aracnet.com (Phil Tomson)

I'm working a C++ project for a contract I'm doing. Originally, the

21 messages 2002/08/03

[#46128] Assoc Class (Hash Pairs) — Tom Sawyer <transami@...>

i've been thinking about posting this as an RCR.

28 messages 2002/08/03

[#46136] Should this work? — "Hal E. Fulton" <hal9000@...>

Should multiple assignment work for the

17 messages 2002/08/03

[#46192] Detecting when an instance variable is created/set — Harry Ohlsen <harryo@...>

Imagine we have a class like ...

22 messages 2002/08/04
[#46198] Re: Detecting when an instance variable is created/set — Tom Sawyer <transami@...> 2002/08/04

On Sun, 2002-08-04 at 06:03, Harry Ohlsen wrote:

[#46207] Re: Detecting when an instance variable is created/set — Harry Ohlsen <harryo@...> 2002/08/04

> > Can I write a method (of class Object or Kernel, perhaps) that will be

[#46226] Re: Detecting when an instance variable is created/set — Massimiliano Mirra <list@...> 2002/08/04

On Sun, Aug 04, 2002 at 10:32:44PM +0900, Harry Ohlsen wrote:

[#46264] Dynamic creation of classes and methods — Tomasz Wegrzanowski <taw@...>

I want to create classes and methods on fly.

11 messages 2002/08/05

[#46341] More questions on automation from na誰ve Windows user. — Chris Gehlker <gehlker@...>

Hi all,

15 messages 2002/08/05

[#46356] Coding challenge (on Ruby Garden) — David Alan Black <dblack@...>

Hello --

47 messages 2002/08/06

[#46357] Compiling Ruby to Native Code? — web2ed@... (Edward Wilson)

Having looked at OCaml, after following a post to this group, one

20 messages 2002/08/06

[#46426] Is There an Inverse of 'rb_define_method'? — William Djaja Tjokroaminata <billtj@...>

Hi,

15 messages 2002/08/06

[#46442] COM on Unix? — Chris Gehlker <gehlker@...>

As part of my crusade to make Ruby an automation language I read up a little

12 messages 2002/08/06

[#46443] Dup and Clone — "Justin Johnson" <justinj@...>

Could anyone kindly point out the difference between 'dup' and 'clone'?

17 messages 2002/08/06

[#46475] Named paramters again — "Justin Johnson" <justinj@...>

26 messages 2002/08/07
[#46534] Re: Named paramters again — "Gavin Sinclair" <gsinclair@...> 2002/08/07

[#46537] RE: Named paramters again — "Rich Kilmer" <rich@...> 2002/08/07

[#46550] GUI's and the Rouge, Part IV — Kero van Gelder <kero@...>

Funny, two savannah accounts for the same objective:

12 messages 2002/08/07

[#46565] Re: Unicode in Ruby now? — "Marcin 'Qrczak' Kowalczyk" <qrczak@...>

Wed, 7 Aug 2002 16:41:18 +0900, Curt Sampson <cjs@cynic.net> pisze:

12 messages 2002/08/07

[#46732] ambiguity between local variable assignment and writter method — Tom Sawyer <transami@...>

does anyone else find it annoying that local variable assignment is

56 messages 2002/08/09
[#46788] Re: ambiguity between local variable assignment and writter method — dblack@... 2002/08/10

Hi --

[#46791] Re: ambiguity between local variable assignment and writter method — Tom Sawyer <transami@...> 2002/08/10

On Fri, 2002-08-09 at 22:50, dblack@candle.superlink.net wrote:

[#46794] Re: ambiguity between local variable assignment and writter method — dblack@... 2002/08/10

Hi --

[#46734] Re: ambiguity between local variable assignment and writter method — Paul Brannan <pbrannan@...> 2002/08/09

On Sat, Aug 10, 2002 at 03:00:28AM +0900, Tom Sawyer wrote:

[#46737] Re: ambiguity between local variable assignment and writter method — Tom Sawyer <transami@...> 2002/08/09

On Fri, 2002-08-09 at 12:05, Paul Brannan wrote:

[#46739] Re: ambiguity between local variable assignment and writter method — Dave Thomas <Dave@...> 2002/08/09

Tom Sawyer <transami@transami.net> writes:

[#46741] Re: ambiguity between local variable assignment and writter method — GOTO Kentaro <gotoken@...> 2002/08/09

At Sat, 10 Aug 2002 03:44:45 +0900,

[#46748] Re: ambiguity between local variable assignment and writter method — Dave Thomas <Dave@...> 2002/08/09

GOTO Kentaro <gotoken@notwork.org> writes:

[#46753] Re: ambiguity between local variable assignment and writter method — Tom Sawyer <transami@...> 2002/08/09

On Fri, 2002-08-09 at 13:30, Dave Thomas wrote:

[#46841] Ah, I'm finally back from Japan ... — Dossy <dossy@...>

Not like anyone cares (or noticed) but my two week stay in Japan

12 messages 2002/08/10

[#46875] To be a Module, or not to be... — Holden Glova <dsafari@...>

-----BEGIN PGP SIGNED MESSAGE-----

12 messages 2002/08/11

[#46911] Choosing ruby? — Rhymes <raims@...>

27 messages 2002/08/11

[#46957] Handling forms on database driven websites — Philip Mak <pmak@...>

Ever since I learned Perl, Ruby and MySQL, I've built several database

10 messages 2002/08/12

[#47000] Primary Key Hash help — "Chris Morris" <chrismo@...>

I have a huge data file with rows like this:

17 messages 2002/08/12

[#47134] Data_Make_Struct Considered Dangerous? — William Djaja Tjokroaminata <billtj@...>

Hi,

39 messages 2002/08/13

[#47212] Ruby Weekly News — Dave@...

21 messages 2002/08/14

[#47292] Thought question: Where does "new" come from? — "Hal E. Fulton" <hal9000@...>

I've been brooding again on the circularities

28 messages 2002/08/15
[#47342] Re: Thought question: Where does "new" come from? — "Hal E. Fulton" <hal9000@...> 2002/08/15

----- Original Message -----

[#47346] Re: Thought question: Where does "new" come from? — dblack@... 2002/08/15

Hi --

[#47365] Re: Thought question: Where does "new" come from? — "MikkelFJ" <mikkelfj-anti-spam@...> 2002/08/15

[#47369] Re: Thought question: Where does "new" come from? — dblack@... 2002/08/15

Hello --

[#47372] Re: Thought question: Where does "new" come from? — "MikkelFJ" <mikkelfj-anti-spam@...> 2002/08/15

[#47377] Re: Thought question: Where does "new" come from? — dblack@... 2002/08/16

Hi --

[#47344] eruby editor — "Kyle Wilson" <kyle.wilson@...>

Hello. I was wondering if anyone knows of a text editor which will

17 messages 2002/08/15

[#47440] Help with a segv in mod_ruby — Dave Thomas <Dave@...>

14 messages 2002/08/16

[#47461] How do I dup file descriptors in ruby? (diverting STDERR) — "Richard A. Ryan" <ryan@...>

Hello,

12 messages 2002/08/16

[#47464] IDE vs. editor — Holden Glova <dsafari@...>

-----BEGIN PGP SIGNED MESSAGE-----

43 messages 2002/08/16

[#47547] Re: What Ruby needs. — "Shashank Date" <ADATE@...>

I do not have any problem with item 1) on your wish list as long as I don't

13 messages 2002/08/18

[#47559] Ruby Bot — Giuseppe Bilotta <bilotta78@...>

Hello,

14 messages 2002/08/18

[#47643] thread control — "Shashank Date" <ADATE@...>

I am trying to write a ruby script (Ruby 1.7.2 mswin32) which does the

21 messages 2002/08/20

[#47695] What makes a "good" Ruby extension? — Tim Hunter <cyclists@...>

So I'm reading the "Comparing Gui Toolkits" wiki page

14 messages 2002/08/20

[#47749] What New Language After Ruby? — William Djaja Tjokroaminata <billtj@...>

To Andrew Hunt and David Thomas:

74 messages 2002/08/21
[#47754] Re: What New Language After Ruby? — Wilkes Joiner <boognish23@...> 2002/08/21

Although activity seems to have died down, here are some links

[#47817] A Repeat: New Language After Ruby? — William Djaja Tjokroaminata <billtj@...>

Hi,

54 messages 2002/08/21
[#47820] RE: A Repeat: New Language After Ruby? — " JamesBritt" <james@...> 2002/08/21

[#47918] Win32 Scripting — Sean Middleditch <elanthis@...>

Hi,

13 messages 2002/08/22

[#48035] Why Ruby Uses Mark-and-Sweep GC? — William Djaja Tjokroaminata <billtj@...>

Hi,

39 messages 2002/08/23

[#48062] Ruby and Judy — Joseph McDonald <joe@...>

29 messages 2002/08/23

[#48082] Distributed Object Container — junderdown@... (Jason Underdown)

Is anyone out there in the Ruby community working on an object

23 messages 2002/08/24
[#48185] Re: Distributed Object Container — "Gavin Sinclair" <gsinclair@...> 2002/08/26

----- Original Message -----

[#48223] Ruby Based App Server — junderdown@... (Jason Underdown)

I posted a similar question a few days ago, but didn't get any

21 messages 2002/08/26

[#48264] Ruby developers: help push RPKG development and usage forward!! (it is like CPAN.pm, only Ruby) — itsnewsforme@... (M S)

A big complaint from people looking into Ruby is that they don't see

36 messages 2002/08/27
[#48292] Re: Ruby developers: help push RPKG development and usage forward!! (it is like CPAN.pm, only Ruby) — ts <decoux@...> 2002/08/27

>>>>> "M" == M S <itsnewsforme@yahoo.ca> writes:

[#48296] RE: Ruby developers: help push RPKG development and usage forward!! (it is like CPAN.pm, only Ruby) — "Rich Kilmer" <rich@...> 2002/08/27

Actually, it would be nice to have them online, but not necessarily

[#48336] Re: Ruby developers: help push RPKG development and usage forward!! (it is like CPAN.pm, only Ruby) — Massimiliano Mirra <list@...> 2002/08/27

On Tue, Aug 27, 2002 at 09:39:32PM +0900, Rich Kilmer wrote:

[#48358] RE: Ruby developers: help push RPKG development and usage forward!! (it is like CPAN.pm, only Ruby) — "Rich Kilmer" <rich@...> 2002/08/28

http://kt-www.jaist.ac.jp/~ttate/ruby/ruby-dl.html

[#48362] RE: Ruby developers: help push RPKG development and usage forward!! (it is like CPAN.pm, only Ruby) — Tom Sawyer <transami@...> 2002/08/28

On Tue, 2002-08-27 at 19:32, Rich Kilmer wrote:

[#48367] RE: Ruby developers: help push RPKG development and usage forward!!(it is like CPAN.pm, only Ruby) — "Rich Kilmer" <rich@...> 2002/08/28

You can just install it in another directory and then go to that

[#48369] RE: Ruby developers: help push RPKG development and usage forward!!(it is like CPAN.pm, only Ruby) — Tom Sawyer <transami@...> 2002/08/28

uh, sorry, how do i get 1.7.2? i tried anonymous cvs but it said NO. did

[#48371] RE: Ruby developers: help push RPKG development and usageforward!!(it is like CPAN.pm, only Ruby) — "Rich Kilmer" <rich@...> 2002/08/28

Nightly CVS snapshot:

[#48274] ANN: RJudy-0.1 - Judy Arrays for Ruby — Lyle Johnson <lyle@...>

All,

17 messages 2002/08/27

[#48477] Newbie converting brain from perl — William Pietri <william-news-383910@...>

20 messages 2002/08/28

[#48544] Best GC for Ruby? — "Justin Johnson" <justinj@...>

34 messages 2002/08/29

[#48573] FXRuby Threading Problem Solved? — Lyle Johnson <lyle@...>

All,

14 messages 2002/08/29

[#48584] suggestions to the Ruby community — stibbs <stibbs@...>

Hi, first i would like to state that i absolutely love Ruby more than any

85 messages 2002/08/29
[#48923] Re: suggestions to the Ruby community — <bbense+comp.lang.ruby.Sep.03.02@...> 2002/09/03

-----BEGIN PGP SIGNED MESSAGE-----

[#48930] RE: suggestions to the Ruby community — " JamesBritt" <james@...> 2002/09/03

> >I was surprised just now to find that there is no absolute requirement

[#49017] Re: suggestions to the Ruby community — <bbense+comp.lang.ruby.Sep.04.02@...> 2002/09/04

-----BEGIN PGP SIGNED MESSAGE-----

[#48657] ICFP Programming Contest — Alan Chen <alan@...>

http://icfpcontest.cse.ogi.edu/task.html

12 messages 2002/08/30

[#48705] Ruby aesthetics — vegai@...

Hello. I've been checking into python lately quite a lot, and I

192 messages 2002/08/31
[#49010] Re: Ruby aesthetics — "Hal E. Fulton" <hal9000@...> 2002/09/04

----- Original Message -----

[#49100] Re: Ruby aesthetics — Paul Prescod <paulp@...> 2002/09/05

On Thu, 5 Sep 2002, Hal E. Fulton wrote:

[#49112] Re: Ruby aesthetics — William Djaja Tjokroaminata <billtj@...> 2002/09/05

Hi,

[#49154] Re: Ruby aesthetics — Paul Prescod <paulp@...> 2002/09/05

On Thu, 5 Sep 2002, William Djaja Tjokroaminata wrote:

[#49161] Re: Ruby aesthetics — Christian Szegedy <szegedy@...> 2002/09/05

Paul Prescod wrote:

[#49173] Re: Ruby aesthetics — William Djaja Tjokroaminata <billtj@...> 2002/09/05

Hi,

[#49183] Re: Ruby aesthetics — <paul@...> 2002/09/05

On Fri, 6 Sep 2002, William Djaja Tjokroaminata wrote:

[#49189] Re: Ruby aesthetics — William Djaja Tjokroaminata <billtj@...> 2002/09/05

I think we have communicated very well; I agree with all you said. May I

[#49191] Re: Ruby aesthetics — <paul@...> 2002/09/05

On Fri, 6 Sep 2002, William Djaja Tjokroaminata wrote:

[#49272] Re: Ruby aesthetics — William Djaja Tjokroaminata <billtj@...> 2002/09/06

Hi Matz,

[#49293] Re: Ruby aesthetics — matz@... (Yukihiro Matsumoto) 2002/09/06

Hi,

[#49312] Re: Ruby aesthetics — <paul@...> 2002/09/06

On Sat, 7 Sep 2002, Yukihiro Matsumoto wrote:

[#49321] Re: Ruby aesthetics — dblack@... 2002/09/06

Hello --

Re: ANN: RJudy-0.1 - Judy Arrays for Ruby

From: Mauricio Fern疣dez <batsman.geo@...>
Date: 2002-08-28 02:25:10 UTC
List: ruby-talk #48365
On Tue, Aug 27, 2002 at 02:41:19PM +0900, Lyle Johnson wrote:
> All,
> 
> I've just uploaded RJudy, an extension module that provides a Ruby 
> interface to the Judy arrays library. This extension exposes four new 
> classes to Ruby (Judy1, JudyL, JudySL and JudyHash). The first three are 
> more-or-less direct wrappers of the current Judy API. The last is a 
> first cut at a more general replacement for Ruby's Hash (i.e. with 
> arbitrary-type keys), based on the approach described in the Judy 
> application note "Scalable Hashing".
> 
> The RDoc documentation for all this stuff is here:
> 
> 	http://www.knology.net/~lyle/rjudy
> 
> and the source tarball (which also includes those docs) is here:
> 
> 	http://www.knology.net/~lyle/rjudy-0.1.tar.gz
> 
> Very interesting stuff indeed (Judy, not my personal work). The 
> "JudyHash" class is still pretty rough by anyone's measure (i.e. 
> probably lots of opportunities for optimization) but it's already 
> consistently beating Ruby's Hash (in my admittedly limited benchmarking 
> tests). If you're interested in playing with this, I could use your help 
> in coming up with more challenging and meaningful benchmarks, as well as 
> examples. Also note that I haven't implemented all of Hash's methods 
> yet, so it's not yet a "drop-in" replacement for Hash.

I've replicated most of your code for the last several hours to use
JudyL inside the internal hash (st_*).
This way, all of Ruby could potentially be faster (including method
lookups and of course builtin hashes).

It's as rough as your code and then some more, but it already challenges
JudyHash's speed in some situations. It is little more than JudyHash's
code inside st_*, but hey, you can't expect much more from such a quick
hack :-)!

BTW, while testing my hashes against JudyHash I found some flaws in
the way you do the admittedly simple benchmarks in words.rb:
  * GC.start should be done between each test to make things a little
   more fair, otherwise the first to run has the advantage as the GC
   will be called more frequently in the last ones...
  * your code uses calloc instead of alloc(), so the Ruby GC heuristics
   don't work and no GC is called inside JudyHash
  * in Ruby hashes, a String key is duplicated if it isn't used in
  the hash already; JudyHash doesn't do that. This is why my Hash seemed
  to suck badly against JudyHash (9us against 3us to insert, about the
  same, 2.5us, to lookup) in words.rb, for the keys are new each time,
  and the associated values are never updated. This means a new String
  object is created in each insertion... In my hash, insertion
  will be much faster when the key doesn't need to be replicated.
  
  To test this behavior even /usr/share/dict/word could work...
head -10000 /usr/share/dict/word > /tmp/data
cat /tmp/data /tmp/data /tmp/data /tmp/data > /tmp/data2
cat /tmp/data2 /tmp/data2 /tmp/data2 /tmp/data2 > /tmp/data3
for n in /tmp/data*; do ./ruby -I/usr/local/lib/site_ruby/1.6/i386_linux \
	words.rb $n; done


I'm attaching a diff, please be indulgent: it's about 4:30AM in my locale
and I'm really in need of some sleep. Got no time to find a place to
upload all this, plus it's small...

Please take a look at the small attached patch...
I've had it build in 1.7.2 and I have had it running for some time,
seemingly OK, but I'm too tired now to do unit testing :-)

Some results here:

batsman@kodos:~/src/cvs/ruby-judy$ wc /tmp/data*
  10000   10000  122880 /tmp/data
  40000   40000  491520 /tmp/data2
 160000  160000 1966080 /tmp/data3
 640000  640000 7864320 /tmp/data4
 850000  850000 10444800 total
doneman@kodos:~/src/cvs/ruby-judy$ for n in /tmp/data*; do ./ruby -1@1PI1@ /usr/local/lib/site_ruby/1.6/i386-linux/jwords2.rb $n;
Time to insert 10000 words into a JudySL array: 28592 usec.
=> Average insertion time: 2.8592 usec/insertion.
Time to look up 10000 words in a JudySL array: 17007.0 usec.
=> Average lookup time: 1.7007 usec/word.

==================
Time to insert 10000 words into a JudyHash: 53110.99999999999 usec.
=> Average insertion time: 5.3111 usec/insertion.
Time to look up 10000 words in a JudyHash: 16263.0 usec.
=> Average lookup time: 1.6263 usec/word.

==================
Time to insert 10000 words into a Ruby Hash: 30890 usec.
=> Average insertion time: 3.089 usec/insertion.
Time to look up 10000 words in a Ruby Hash: 16794.0 usec.
=> Average lookup time: 1.6794 usec/word.
Time to insert 40000 words into a JudySL array: 91143.0 usec.
=> Average insertion time: 2.278575 usec/insertion.
Time to look up 40000 words in a JudySL array: 63044.0 usec.
=> Average lookup time: 1.5761 usec/word.

==================
Time to insert 40000 words into a JudyHash: 93122.00000000004 usec.
=> Average insertion time: 2.328050000000001 usec/insertion.
Time to look up 40000 words in a JudyHash: 80944.0 usec.
=> Average lookup time: 2.0236 usec/word.

==================
Time to insert 40000 words into a Ruby Hash: 101690.0 usec.
=> Average insertion time: 2.54225 usec/insertion.
Time to look up 40000 words in a Ruby Hash: 70016.0 usec.
=> Average lookup time: 1.7504 usec/word.
Time to insert 160000 words into a JudySL array: 352922.0000000001 usec.
=> Average insertion time: 2.205762500000001 usec/insertion.
Time to look up 160000 words in a JudySL array: 256844 usec.
=> Average lookup time: 1.605275 usec/word.

==================
Time to insert 160000 words into a JudyHash: 399579.0 usec.
=> Average insertion time: 2.49736875 usec/insertion.
Time to look up 160000 words in a JudyHash: 353830.0 usec.
=> Average lookup time: 2.2114375 usec/word.

==================
Time to insert 160000 words into a Ruby Hash: 397741.0 usec.
=> Average insertion time: 2.48588125 usec/insertion.
Time to look up 160000 words in a Ruby Hash: 285617.0 usec.
=> Average lookup time: 1.78510625 usec/word.
Time to insert 640000 words into a JudySL array: 1390958.0 usec.
=> Average insertion time: 2.173371875 usec/insertion.
Time to look up 640000 words in a JudySL array: 1023863.0 usec.
=> Average lookup time: 1.5997859375 usec/word.

==================
Time to insert 640000 words into a JudyHash: 1636917.0 usec.
=> Average insertion time: 2.5576828125 usec/insertion.
Time to look up 640000 words in a JudyHash: 1491516 usec.
=> Average lookup time: 2.33049375 usec/word.

==================
Time to insert 640000 words into a Ruby Hash: 1741098.0 usec.
=> Average insertion time: 2.720465625 usec/insertion.
Time to look up 640000 words in a Ruby Hash: 1309702 usec.
=> Average lookup time: 2.046409375000001 usec/word.
batsman@kodos:~/src/cvs/ruby-judy$


-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
  
         Why use Windows when you can have air conditioning?
         Why use Windows, when you can leave through the door?
	-- Konrad Blum

Attachments (1)

ruby-judy-0.0.1.patch (13 KB, text/x-diff)
diff -rwdu ruby/configure.in ruby-judy/configure.in
--- ruby/configure.in	Sun Aug 11 23:43:24 2002
+++ ruby-judy/configure.in	Tue Aug 27 17:46:42 2002
@@ -281,6 +281,7 @@
 AC_CHECK_LIB(crypt, crypt)
 AC_CHECK_LIB(dl, dlopen)	# Dynamic linking for SunOS/Solaris and SYSV
 AC_CHECK_LIB(dld, shl_load)	# Dynamic linking for HP-UX
+AC_CHECK_LIB(Judy, JudyLIns)	# Judy 
 
 dnl Checks for header files.
 AC_HEADER_DIRENT
diff -rwdu ruby/hash.c ruby-judy/hash.c
--- ruby/hash.c	Wed Jul 31 00:30:17 2002
+++ ruby-judy/hash.c	Wed Aug 28 03:15:01 2002
@@ -125,11 +125,10 @@
 {
     int status;
     st_table *tbl = RHASH(arg->hash)->tbl;
-    struct st_table_entry **bins = tbl->bins;
 
     if (key == Qundef) return ST_CONTINUE;
     status = (*arg->func)(key, value, arg->arg);
-    if (RHASH(arg->hash)->tbl != tbl || RHASH(arg->hash)->tbl->bins != bins){
+    if (RHASH(arg->hash)->tbl != tbl){
 	rb_raise(rb_eIndexError, "rehash occurred during iteration");
     }
     return status;
diff -rwdu ruby/st.c ruby-judy/st.c
--- ruby/st.c	Wed Jul 31 00:30:20 2002
+++ ruby-judy/st.c	Wed Aug 28 03:38:02 2002
@@ -11,27 +11,16 @@
 #include <malloc.h>
 #endif
 
+#include <Judy.h>
+
 typedef struct st_table_entry st_table_entry;
 
 struct st_table_entry {
-    unsigned int hash;
     char *key;
     char *record;
     st_table_entry *next;
 };
 
-#define ST_DEFAULT_MAX_DENSITY 5
-#define ST_DEFAULT_INIT_TABLE_SIZE 11
-
-    /*
-     * DEFAULT_MAX_DENSITY is the default for the largest we allow the
-     * average number of items per bin before increasing the number of
-     * bins
-     *
-     * DEFAULT_INIT_TABLE_SIZE is the default for the number of bins
-     * allocated initially
-     *
-     */
 static int numcmp();
 static int numhash();
 static struct st_hash_type type_numhash = {
@@ -66,73 +55,14 @@
 #define EQUAL(table,x,y) ((x)==(y) || (*table->type->compare)((x),(y)) == 0)
 
 #define do_hash(key,table) (unsigned int)(*(table)->type->hash)((key))
-#define do_hash_bin(key,table) (do_hash(key, table)%(table)->num_bins)
-
-/*
- * MINSIZE is the minimum size of a dictionary.
- */
-
-#define MINSIZE 8
-
-/*
-Table of prime numbers 2^n+a, 2<=n<=30.
-*/
-static long primes[] = {
-	8 + 3,
-	16 + 3,
-	32 + 5,
-	64 + 3,
-	128 + 3,
-	256 + 27,
-	512 + 9,
-	1024 + 9,
-	2048 + 5,
-	4096 + 3,
-	8192 + 27,
-	16384 + 43,
-	32768 + 3,
-	65536 + 45,
-	131072 + 29,
-	262144 + 3,
-	524288 + 21,
-	1048576 + 7,
-	2097152 + 17,
-	4194304 + 15,
-	8388608 + 9,
-	16777216 + 43,
-	33554432 + 35,
-	67108864 + 15,
-	134217728 + 29,
-	268435456 + 3,
-	536870912 + 11,
-	1073741824 + 85,
-	0
-};
+#define do_hash_bin(key,table) (do_hash(key, table) % HASHSIZE)
 
-static int
-new_size(size)
-    int size;
-{
-    int i;
+#define HASHARRAY(table,code) ((table)->PJLArray[(code) % HASHSIZE])
+#define HASHINDEX(code) ((code)/HASHSIZE)
+#define HASHNODE(ppv) (* (st_table_entry **)ppv)
+#define NEWNODE(ppv) *(ppv) = calloc(1, sizeof(st_table_entry))
 
-#if 0
-    for (i=3; i<31; i++) {
-	if ((1<<i) > size) return 1<<i;
-    }
-    return -1;
-#else
-    int newsize;
 
-    for (i = 0, newsize = MINSIZE;
-	 i < sizeof(primes)/sizeof(primes[0]);
-	 i++, newsize <<= 1)
-    {
-	if (newsize > size) return primes[i];
-    }
-    /* Ran out of polynomials */
-    return -1;			/* should raise exception */
-#endif
-}
 
 #ifdef HASH_LOG
 static int collision = 0;
@@ -153,6 +83,12 @@
     int size;
 {
     st_table *tbl;
+    int i;
+   
+    tbl = alloc(st_table);
+    //FIXME: optimize
+    for ( i = 0; i < HASHSIZE; i++ )
+        tbl->PJLArray[i] = 0;
 
 #ifdef HASH_LOG
     if (init_st == 0) {
@@ -161,13 +97,8 @@
     }
 #endif
 
-    size = new_size(size);	/* round up to prime number */
-
-    tbl = alloc(st_table);
     tbl->type = type;
     tbl->num_entries = 0;
-    tbl->num_bins = size;
-    tbl->bins = (st_table_entry **)Calloc(size, sizeof(st_table_entry*));
 
     return tbl;
 }
@@ -211,21 +142,28 @@
 {
     register st_table_entry *ptr, *next;
     int i;
+    PPvoid_t PValue;
+    Word_t Index;
+    st_table_entry *pNode, *pTmp;
 
-    for(i = 0; i < table->num_bins; i++) {
-	ptr = table->bins[i];
-	while (ptr != 0) {
-	    next = ptr->next;
-	    free(ptr);
-	    ptr = next;
+    for(i = 0; i < HASHSIZE; i++) {
+		Index = 0;
+		PValue = JudyLFirst(table->PJLArray[i], &Index, PJE0);
+		while (PValue) {
+			// go through all the positions inside the Judy array
+			pNode = HASHNODE(PValue);
+			while (pNode) {   // clear the collision list
+				pTmp = pNode;
+				pNode = pNode->next;
+				free(pTmp);	
 	}
+			PValue = JudyLNext(table->PJLArray[i], &Index, PJE0);
     }
-    free(table->bins);
-    free(table);
+		JudyLFreeArray(&table->PJLArray[i], PJE0);
 }
 
-#define PTR_NOT_EQUAL(table, ptr, hash_val, key) \
-((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key)))
+    free(table);
+}
 
 #ifdef HASH_LOG
 #define COLLISION collision++
@@ -234,14 +172,17 @@
 #endif
 
 #define FIND_ENTRY(table, ptr, hash_val, bin_pos) do {\
-    bin_pos = hash_val%(table)->num_bins;\
-    ptr = (table)->bins[bin_pos];\
-    if (PTR_NOT_EQUAL(table, ptr, hash_val, key)) {\
-	COLLISION;\
-	while (PTR_NOT_EQUAL(table, ptr->next, hash_val, key)) {\
-	    ptr = ptr->next;\
+    PPvoid_t PValue;\
+	\
+	bin_pos = HASHINDEX(hash_val);\
+    PValue = JudyLGet(HASHARRAY(table,hash_val), bin_pos, PJE0);\
+	if (PValue) {\
+		for ( ptr = HASHNODE(PValue); ptr; ptr = ptr->next)\
+			if ( EQUAL(table, ptr->key, key) ) \
+				break;\
 	}\
-	ptr = ptr->next;\
+	else {\
+		ptr = 0;\
     }\
 } while (0)
 
@@ -269,18 +210,15 @@
 #define ADD_DIRECT(table, key, value, hash_val, bin_pos)\
 do {\
     st_table_entry *entry;\
-    if (table->num_entries/(table->num_bins) > ST_DEFAULT_MAX_DENSITY) {\
-	rehash(table);\
-        bin_pos = hash_val % table->num_bins;\
-    }\
+	PPvoid_t PValue;\
     \
-    entry = alloc(st_table_entry);\
+    PValue = JudyLIns(&HASHARRAY(table,hash_val), bin_pos, PJE0);\
     \
-    entry->hash = hash_val;\
+	entry = alloc(st_table_entry);\
     entry->key = key;\
     entry->record = value;\
-    entry->next = table->bins[bin_pos];\
-    table->bins[bin_pos] = entry;\
+	entry->next = HASHNODE(PValue);\
+	*PValue = entry;\
     table->num_entries++;\
 } while (0)
 
@@ -292,17 +230,32 @@
 {
     unsigned int hash_val, bin_pos;
     register st_table_entry *ptr;
+	PPvoid_t PValue;
 
-    hash_val = do_hash(key, table);
-    FIND_ENTRY(table, ptr, hash_val, bin_pos);
 
-    if (ptr == 0) {
-	ADD_DIRECT(table, key, value, hash_val, bin_pos);
+    hash_val = do_hash(key, table);
+	PValue = JudyLIns( &HASHARRAY(table, hash_val), HASHINDEX(hash_val), PJE0);
+	if ( *PValue ) {
+		for ( ptr = HASHNODE(PValue); ptr; ptr = ptr->next )
+			if ( EQUAL(table, ptr->key, key) ) {
+				ptr->record = value;
+				return 1;
+			}
+		ptr = alloc(st_table_entry);
+		ptr->key = key;
+		ptr->record = value;
+		ptr->next = *PValue;
+		*PValue = ptr;
+		++table->num_entries;
 	return 0;
     }
     else {
-	ptr->record = value;
-	return 1;
+		*PValue = alloc(st_table_entry);
+		HASHNODE(PValue)->key = key;
+		HASHNODE(PValue)->record = value;
+		HASHNODE(PValue)->next = 0;
+		++table->num_entries;
+		return 0;
     }
 }
 
@@ -315,72 +268,47 @@
     unsigned int hash_val, bin_pos;
 
     hash_val = do_hash(key, table);
-    bin_pos = hash_val % table->num_bins;
+	bin_pos = HASHINDEX(hash_val);
     ADD_DIRECT(table, key, value, hash_val, bin_pos);
 }
 
-static void
-rehash(table)
-    register st_table *table;
-{
-    register st_table_entry *ptr, *next, **new_bins;
-    int i, old_num_bins = table->num_bins, new_num_bins;
-    unsigned int hash_val;
-
-    new_num_bins = new_size(old_num_bins+1);
-    new_bins = (st_table_entry**)Calloc(new_num_bins, sizeof(st_table_entry*));
-
-    for(i = 0; i < old_num_bins; i++) {
-	ptr = table->bins[i];
-	while (ptr != 0) {
-	    next = ptr->next;
-	    hash_val = ptr->hash % new_num_bins;
-	    ptr->next = new_bins[hash_val];
-	    new_bins[hash_val] = ptr;
-	    ptr = next;
-	}
-    }
-    free(table->bins);
-    table->num_bins = new_num_bins;
-    table->bins = new_bins;
-}
-
 st_table*
 st_copy(old_table)
     st_table *old_table;
 {
     st_table *new_table;
-    st_table_entry *ptr, *entry;
-    int i, num_bins = old_table->num_bins;
+    st_table_entry *oldptr, *ptr, **entry;
+	PPvoid_t PValue;
+	Word_t Index;
+    int i;
 
-    new_table = alloc(st_table);
+    new_table = st_init_table( old_table->type );
     if (new_table == 0) {
 	return 0;
     }
 
-    *new_table = *old_table;
-    new_table->bins = (st_table_entry**)
-	Calloc((unsigned)num_bins, sizeof(st_table_entry*));
+    new_table->num_entries = old_table->num_entries;
 
-    if (new_table->bins == 0) {
-	free(new_table);
-	return 0;
+    for(i = 0; i < HASHSIZE; i++) {
+		Index = 0;
+		PValue = JudyLFirst(old_table->PJLArray[i], &Index, PJE0);
+		while( PValue ) {
+			if ( *PValue ) {
+				entry = (st_table_entry **) JudyLIns(&new_table->PJLArray[i], Index, PJE0 );
+				*entry = alloc(st_table_entry);
+				(*entry)->key = HASHNODE(PValue)->key;
+				(*entry)->record = HASHNODE(PValue)->record;
+				(*entry)->next = 0;
+				for (oldptr = HASHNODE(PValue)->next; oldptr; oldptr = oldptr->next) {
+					ptr = alloc(st_table_entry);
+					// FIXME: check error in memory allocation
+					ptr->key = ptr->key;
+					ptr->record = ptr->record;
+					ptr->next = *entry;
+					*entry = ptr;
     }
-
-    for(i = 0; i < num_bins; i++) {
-	new_table->bins[i] = 0;
-	ptr = old_table->bins[i];
-	while (ptr != 0) {
-	    entry = alloc(st_table_entry);
-	    if (entry == 0) {
-		free(new_table->bins);
-		free(new_table);
-		return 0;
 	    }
-	    *entry = *ptr;
-	    entry->next = new_table->bins[i];
-	    new_table->bins[i] = entry;
-	    ptr = ptr->next;
+			PValue = JudyLNext(old_table->PJLArray[i], &Index, PJE0);
 	}
     }
     return new_table;
@@ -394,33 +322,27 @@
 {
     unsigned int hash_val;
     st_table_entry *tmp;
-    register st_table_entry *ptr;
+    register st_table_entry **ptr, *ptr2;
 
     hash_val = do_hash_bin(*key, table);
-    ptr = table->bins[hash_val];
-
+    ptr = (st_table_entry **) JudyLGet(HASHARRAY(table, hash_val), 
+				HASHINDEX(hash_val), PJE0);
     if (ptr == 0) {
 	if (value != 0) *value = 0;
 	return 0;
     }
 
-    if (EQUAL(table, *key, ptr->key)) {
-	table->bins[hash_val] = ptr->next;
-	table->num_entries--;
-	if (value != 0) *value = ptr->record;
-	*key = ptr->key;
-	free(ptr);
-	return 1;
-    }
-
-    for(; ptr->next != 0; ptr = ptr->next) {
-	if (EQUAL(table, ptr->next->key, *key)) {
-	    tmp = ptr->next;
-	    ptr->next = ptr->next->next;
-	    table->num_entries--;
-	    if (value != 0) *value = tmp->record;
-	    *key = tmp->key;
-	    free(tmp);
+	for( tmp = 0, ptr2 = *ptr; ptr2; tmp = ptr2, ptr2 = ptr2->next ) {
+		if (EQUAL(table, ptr2->key, *key)) {
+			if(value) *value = ptr2->record;
+			if(tmp) 
+				tmp->next = ptr2->next;
+			else // head of the list
+				*ptr = ptr2->next;
+			free( ptr2 );
+			if ( ! *ptr )
+				JudyLDel(&HASHARRAY(table,hash_val), HASHINDEX(hash_val), PJE0);
+			--table->num_entries;
 	    return 1;
 	}
     }
@@ -437,15 +359,17 @@
 {
     unsigned int hash_val;
     register st_table_entry *ptr;
+	PPvoid_t pValue;
 
     hash_val = do_hash_bin(*key, table);
-    ptr = table->bins[hash_val];
+    pValue = JudyLGet(HASHARRAY(table,hash_val), HASHINDEX(hash_val), PJE0);
 
-    if (ptr == 0) {
+    if (pValue == 0) {
 	if (value != 0) *value = 0;
 	return 0;
     }
 
+	ptr = HASHNODE(pValue);
     for(; ptr != 0; ptr = ptr->next) {
 	if ((ptr->key != never) && EQUAL(table, ptr->key, *key)) {
 	    table->num_entries--;
@@ -485,12 +409,20 @@
     char *arg;
 {
     st_table_entry *ptr, *last, *tmp;
+	PPvoid_t PValue;
+	Word_t Index;
     enum st_retval retval;
     int i;
 
-    for(i = 0; i < table->num_bins; i++) {
+    for(i = 0; i < HASHSIZE; i++) {
 	last = 0;
-	for(ptr = table->bins[i]; ptr != 0;) {
+	Index = 0;
+	if ( table->PJLArray[i] == 0 )  // empty JudyL array
+		continue; 
+	PValue = JudyLFirst(table->PJLArray[i], &Index, PJE0);
+	while ( PValue ) {
+		ptr = HASHNODE(PValue);
+	while ( ptr != 0 ) {
 	    retval = (*func)(ptr->key, ptr->record, arg);
 	    switch (retval) {
 	    case ST_CONTINUE:
@@ -502,7 +434,7 @@
 	    case ST_DELETE:
 		tmp = ptr;
 		if (last == 0) {
-		    table->bins[i] = ptr->next;
+		    HASHNODE(PValue) = ptr->next;
 		}
 		else {
 		    last->next = ptr->next;
@@ -510,9 +442,11 @@
 		ptr = ptr->next;
 		free(tmp);
 		table->num_entries--;
-	    }
-	}
-    }
+	    } // switch 
+	    } // while to scan collision list
+		PValue = JudyLNext(table->PJLArray[i], &Index, PJE0);
+	} // while to scan Judy array
+    } // for
 }
 
 static int
diff -rwdu ruby/st.h ruby-judy/st.h
--- ruby/st.h	Wed Jan  5 05:37:12 2000
+++ ruby-judy/st.h	Wed Aug 28 01:19:43 2002
@@ -6,6 +6,8 @@
 
 #define ST_INCLUDED
 
+#include <Judy.h>
+
 typedef struct st_table st_table;
 
 struct st_hash_type {
@@ -13,11 +15,14 @@
     int (*hash)();
 };
 
+#define HASHSIZE 256
+#define LOG_HASHSIZE 8
+// make these coherent
+
 struct st_table {
     struct st_hash_type *type;
-    int num_bins;
     int num_entries;
-    struct st_table_entry **bins;
+    Pvoid_t PJLArray[HASHSIZE];
 };
 
 #define st_is_member(table,key) st_lookup(table,key,(char **)0)

In This Thread