[#48779] Ruby jobs — Phlip <phlip_cpp@...>

Rubies:

31 messages 2002/09/01

[#48886] cgi redirect — Tom Robinson <tom@...>

in perl, this is easy:

15 messages 2002/09/03

[#48917] New list: ruby-modules - for module developers... — Sean Chittenden <sean@...>

Howdy folks. I've put together a new list for ruby developers at

18 messages 2002/09/03

[#48978] option remember

Hi,

16 messages 2002/09/04

[#49042] Options for optimizing a large Ruby system — sera@... (Francis Hwang)

Hi everybody:

16 messages 2002/09/04

[#49107] RE: suggestions to the Ruby community — "Berger, Daniel" <djberge@...>

I've been following the documentation discussion with some interest. Some

35 messages 2002/09/05
[#49136] RE: suggestions to the Ruby community — " JamesBritt" <james@...> 2002/09/05

[#49294] OS-independent build of ruby — "reckless" <reckless2k@...>

Hi,

42 messages 2002/09/06
[#49318] Re: OS-independent build of ruby — ptkwt@...1.aracnet.com (Phil Tomson) 2002/09/06

In article <alali7$cth$01$1@news.t-online.com>,

[#49450] JRuby (was Re: OS-independent build of ruby) — Austin Ziegler <austin@...> 2002/09/08

JRuby exists ...

[#49297] Larry Wall's comments on Ruby — ptkwt@...1.aracnet.com (Phil Tomson)

http://interviews.slashdot.org/article.pl?sid=02/09/06/1343222&mode=thread&tid=145

29 messages 2002/09/06

[#49301] Re: Larry Wall's comments on Ruby — Andrew Hunt <andy@...>

61 messages 2002/09/06
[#49372] Re: Larry Wall's comments on Ruby — Reimer Behrends <behrends@...> 2002/09/07

Patrick May (patrick-may@monmouth.com) wrote:

[#49446] Re: Larry Wall's comments on Ruby — Austin Ziegler <austin@...> 2002/09/08

On Sat, 7 Sep 2002 14:21:22 +0900, Reimer Behrends wrote:

[#49333] Re: Larry Wall's comments on Ruby — Andrew Hunt <andy@...>

>yeah and as I said, depending on your background , Ruby is just as full

20 messages 2002/09/06

[#49627] Re: Larry Wall's comments on Ruby — "Marcin 'Qrczak' Kowalczyk" <qrczak@...>

Mon, 9 Sep 2002 14:26:37 +0900, Wirianto Djunaidi <ryo_saeba_009@yahoo.com> pisze:

83 messages 2002/09/09
[#49658] Re: Larry Wall's comments on Ruby — "Christoph" <chr_news@...> 2002/09/10

"Yukihiro Matsumoto" wrote

[#49707] Re: Larry Wall's comments on Ruby — David.Stagner@...

I think Gavin is right... we don't "add" strings, we concatenate them.

16 messages 2002/09/10

[#49766] RubyInline 1.0.4 Released! (fwd) — Pat Eyler <pate@...>

Woohoo! another cool new toy to play with!

34 messages 2002/09/10
[#49965] Re: Windows XP : RubyInline 1.0.4 Released! (fwd) — "Park Heesob" <phasis@...> 2002/09/12

Hi,

[#49787] call for commentary: review of Ruby for a magazine (long, sorry!) — Rick Wayne <fewayne@...>

hello again folks,

30 messages 2002/09/10

[#49849] private variables — ts <decoux@...>

81 messages 2002/09/11
[#50348] Re: private variables — William Djaja Tjokroaminata <billtj@...> 2002/09/16

Well, will these localized/private variables make it into the next Ruby

[#49988] not grasping the method overloading/multi-dispatch thing — dblack@...

Hello --

58 messages 2002/09/12
[#49990] Re: not grasping the method overloading/multi-dispatch thing — Friedrich Dominicus <frido@...> 2002/09/12

dblack@candle.superlink.net writes:

[#49992] Re: not grasping the method overloading/multi-dispatch thing — dblack@... 2002/09/12

Hi --

[#50040] Re: not grasping the method overloading/multi-dispatch thing — ptkwt@...1.aracnet.com (Phil Tomson) 2002/09/12

In article <3D80AD8D.27388.FBF0F18@localhost>,

[#50027] interesting Perl Journal move — Pat Eyler <pate@...>

The Perl Journal is being reborn yet again. This time, it will be an

21 messages 2002/09/12
[#50041] Re: interesting Perl Journal move — Jim Freeze <jim@...> 2002/09/12

On Fri, Sep 13, 2002 at 01:44:18AM +0900, Pat Eyler wrote:

[#50172] DbTalk 0.7 — Dalibor Sramek <dali@...>

I would like to announce a new release of my Ruby project DbTalk.

17 messages 2002/09/13

[#50224] MVC and OO Design? — jcb@... (MetalOne)

The Model View Controller Architecture has always had me a bit

18 messages 2002/09/14

[#50298] camelCaseTo_ruby_case.rb ?? — Thomas Sdergaard <tsondergaard@...>

Hi,

21 messages 2002/09/15
[#50304] Re: camelCaseTo_ruby_case.rb ?? — dblack@... 2002/09/16

Hello --

[#50312] Re: camelCaseTo_ruby_case.rb ?? — Joel VanderWerf <vjoel@...> 2002/09/16

[#50369] Why are parser tools rarely used in ruby? — "MikkelFJ" <mikkelfj-anti-spam@...>

Why is it that all the ruby source I find in the Ruby (windows) distribution

25 messages 2002/09/16

[#50374] Dependency "trees" - suggestions? — Massimiliano Mirra <list@...>

I'm struggling with building dependency "trees" for rpkg. What

15 messages 2002/09/16

[#50403] comments and continuing strings on the next line — Paul Brannan <pbrannan@...>

I have a tendency to write:

14 messages 2002/09/16

[#50466] Qt vs. FOX vs. ? (was Help on installing ruby-qt on windowsXP) — "Volkmann, Mark" <Mark.Volkmann@...>

> -----Original Message-----

16 messages 2002/09/17

[#50525] Matz, if you're reading, please scan this email — ser@... (Sean Russell)

I've found a problem with the Ruby interpreter, wherein the

23 messages 2002/09/18
[#51226] Re: Matz, if you're reading, please scan this email — Sean Chittenden <sean@...> 2002/09/24

> I've found a problem with the Ruby interpreter, wherein the

[#51281] Re: Matz, if you're reading, please scan this email — ts <decoux@...> 2002/09/25

>>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#51454] Re: Matz, if you're reading, please scan this email — Sean Chittenden <sean@...> 2002/09/26

> S> In the unit tests for libxml, I think I've pushed things to SEGV land

[#51592] Re: Matz, if you're reading, please scan this email — ts <decoux@...> 2002/09/27

>>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#51742] Re: Matz, if you're reading, please scan this email — Sean Chittenden <sean@...> 2002/09/28

> >>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#51748] Re: Matz, if you're reading, please scan this email — ts <decoux@...> 2002/09/28

>>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#51796] ruby bug in tight loops? (was: Re: Matz, if you're reading, please scan this email) — Sean Chittenden <sean@...> 2002/09/28

> S> :-/ You could be right, but, the IO context is created when reading

[#51825] Re: ruby bug in tight loops? (was: Re: Matz, if you're reading, please scan this email) — ts <decoux@...> 2002/09/29

>>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#51826] Re: ruby bug in tight loops? (was: Re: Matz, if you're reading, please scan this email) — Sean Chittenden <sean@...> 2002/09/29

> S> Good catch, I fixed this in the CVS version, however this is a

[#51831] Re: ruby bug in tight loops? (was: Re: Matz, if you're reading, please scan this email) — ts <decoux@...> 2002/09/29

>>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#50579] How to Efficiently Calculate the Pattern of Zeros and Ones? — William Djaja Tjokroaminata <billtj@...>

Hi,

11 messages 2002/09/18

[#50606] Python the new Lisp, what about Ruby then? — web2ed@... (Edward Wilson)

I've been reading that Python is the new lisp.

19 messages 2002/09/18
[#50614] Re: Python the new Lisp, what about Ruby then? — Tom Sawyer <transami@...> 2002/09/19

come on! python the new lisp? what's that suppose to mean? nothing

[#50629] RE: Python the new Lisp, what about Ruby then? — "Mike Campbell" <michael_s_campbell@...> 2002/09/19

> ruby though just may gain as great a heritage as lisp due to its highly

[#50652] Is better to subclass or to add methods to an existing class? — Vincent Foley <vinfoley@...>

I was discussing with a (Python) friend last night. I told him that one

31 messages 2002/09/19

[#50667] select and select — dblack@...

Hello --

99 messages 2002/09/19
[#50906] class documentation — "Mark Volkmann" <volkmann2@...> 2002/09/21

Is there a general concensus as to the best tool/format for documenting Ruby

[#50787] Re: select and select — Joel VanderWerf <vjoel@...> 2002/09/20

Yukihiro Matsumoto wrote:

[#50911] Re: select and select — matz@... (Yukihiro Matsumoto) 2002/09/21

Hi,

[#50912] Re: select and select — dblack@... 2002/09/21

Hi --

[#51168] Re: select and select — "Gavin Sinclair" <gsinclair@...> 2002/09/24

[#51184] Re: select and select — dblack@... 2002/09/24

Hi --

[#51196] Re: select and select — "Gavin Sinclair" <gsinclair@...> 2002/09/24

[#51199] Re: select and select — dblack@... 2002/09/24

Hi --

[#50732] don't understand cause of `sysread': Bad file descriptor (Errno::EBADF) — Robert McGovern <tarasis@...>

Was writting a script to poll an audiotron (www.audiotron.net) and

13 messages 2002/09/19

[#50762] Thoughts on improving usage of Regexp#match — "Hal E. Fulton" <hal9000@...>

Please feel free to point out obvious things

15 messages 2002/09/20

[#50850] Checking hash key's and values, with case insensitivity — khabibiuf@... (Khurram)

Hey all,

26 messages 2002/09/20

[#50867] Speed up suggestions — Tomas Brixi <tomas_brixi@...>

Hello,

18 messages 2002/09/20

[#50878] String interpolation at will? — "Hal E. Fulton" <hal9000@...>

Maybe I'm overlooking something obvious,

14 messages 2002/09/20
[#50880] RE: String interpolation at will? — Steve Tuckner <STUCKNER@...> 2002/09/20

Maybe this is too dangerous but

[#50958] are functions/methods "first class objects"? — David Garamond <davegaramond@...>

sorry this is a bit philosophical, but i just wonder whether ruby can be

17 messages 2002/09/22

[#50972] Re: Speed up suggestions — Tomas Brixi <tomas_brixi@...>

Thanks all for speedup tips.

22 messages 2002/09/23
[#50975] Re: Speed up suggestions — Ryan Davis <ryand@...> 2002/09/23

[#50983] Re: Speed up suggestions — Tomas Brixi <tomas_brixi@...> 2002/09/23

[#51156] adding overload to ruby — "Bulat Ziganshin" <bulatz@...>

Hello all and especially Matz,

285 messages 2002/09/24
[#51371] Re: adding overload to ruby — "Justin Johnson" <justinj@...> 2002/09/26

[#51372] Re: adding overload to ruby — "Bulat Ziganshin" <bulatz@...> 2002/09/26

Hello Justin,

[#51375] Re: adding overload to ruby — ts <decoux@...> 2002/09/26

>>>>> "B" == Bulat Ziganshin <bulatz@integ.ru> writes:

[#51376] Re: adding overload to ruby — "Bulat Ziganshin" <bulatz@...> 2002/09/26

Hello ts,

[#51378] Re: adding overload to ruby — ts <decoux@...> 2002/09/26

>>>>> "B" == Bulat Ziganshin <bulatz@integ.ru> writes:

[#51382] Re: adding overload to ruby — "Bulat Ziganshin" <bulatz@...> 2002/09/26

Hello ts,

[#51384] Re: adding overload to ruby — dblack@... 2002/09/26

Hi --

[#51388] Re: adding overload to ruby — "Bulat Ziganshin" <bulatz@...> 2002/09/26

Hello dblack,

[#51391] Re: adding overload to ruby — dblack@... 2002/09/26

Hi --

[#51413] Re: adding overload to ruby — "Justin Johnson" <justinj@...> 2002/09/26

[#51542] Re: adding overload to ruby — "Bulat Ziganshin" <bulatz@...> 2002/09/27

Hello Justin,

[#51574] R (was: adding overload to ruby) — Nikodemus Siivola <tsiivola@...> 2002/09/27

[#51576] Re: R (was: adding overload to ruby) — "Bulat Ziganshin" <bulatz@...> 2002/09/27

Hello Nikodemus,

[#51591] Re: R (was: adding overload to ruby) — Nikodemus Siivola <tsiivola@...> 2002/09/27

[#51621] Re: R — William Djaja Tjokroaminata <billtj@...> 2002/09/27

Hi,

[#51741] Re: R — Nikodemus Siivola <tsiivola@...> 2002/09/28

[#51747] Re: R — William Djaja Tjokroaminata <billtj@...> 2002/09/28

Hi,

[#51752] Re: R — dblack@... 2002/09/28

Hi --

[#51755] Re: R — William Djaja Tjokroaminata <billtj@...> 2002/09/28

Oh yes, in fact, this is one of our selling points, right? We show the

[#51918] Re: R — "Bulat Ziganshin" <bulatz@...> 2002/09/30

Hello William,

[#51923] Re: R — matz@... (Yukihiro Matsumoto) 2002/09/30

Hi,

[#51938] Re: R — "Bulat Ziganshin" <bulatz@...> 2002/09/30

Hello Yukihiro,

[#51949] Re: R — matz@... (Yukihiro Matsumoto) 2002/09/30

Hi,

[#51953] Re: R — "Bulat Ziganshin" <bulatz@...> 2002/09/30

Hello Yukihiro,

[#51593] RE: R (was: adding overload to ruby) — "Christian Boos" <cboos@...> 2002/09/27

Did you have a look at http://merd.net :

[#51462] Re: adding overload to ruby — William Djaja Tjokroaminata <billtj@...> 2002/09/26

Why not designing a new language with a mix of typed variable and untyped

[#51467] Re: adding overload to ruby — <bbense+comp.lang.ruby.Sep.26.02@...> 2002/09/26

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

[#51185] Object-Oriented struct Model in C — William Djaja Tjokroaminata <billtj@...>

Hi,

20 messages 2002/09/24

[#51389] Is Ruby's grammar LL(k)? — Mauricio =?unknown-8bit?Q?Fern=E1ndez?= <batsman.geo@...>

16 messages 2002/09/26

[#51444] Ruby/Tk or mod_ruby or what ?? — GBanschbach@...

Dear All,

16 messages 2002/09/26

[#51486] Ruby - common pitfalls? — Rudolf Polzer <AntiATField_adsgohere@...>

Is there a list of common pitfalls beginners in this language should

32 messages 2002/09/26

[#51530] Where Is Method Call Precedence? — William Djaja Tjokroaminata <billtj@...>

Hi,

40 messages 2002/09/27

[#51639] RE: REXML namespace support — "Volkmann, Mark" <Mark.Volkmann@...>

In my case I'm given a string which is a namespace prefix and I want to

14 messages 2002/09/27

[#51809] thoughts on typelessness — dblack@...

Hi --

136 messages 2002/09/29
[#51810] Re: thoughts on typelessness — William Djaja Tjokroaminata <billtj@...> 2002/09/29

Hi David,

[#51877] Re: thoughts on typelessness — Chris Gehlker <canyonrat@...> 2002/09/29

[#52055] Re: thoughts on typelessness — Bryan Murphy <bryan@...> 2002/10/01

Gavin Sinclair wrote:

[#52059] Re: thoughts on typelessness — Chris Gehlker <canyonrat@...> 2002/10/01

[#52062] Re: thoughts on typelessness — Bryan Murphy <bryan@...> 2002/10/01

Chris Gehlker wrote:

[#52081] Re: thoughts on typelessness — Chris Gehlker <canyonrat@...> 2002/10/01

[#52147] Re: thoughts on typelessness — William Djaja Tjokroaminata <billtj@...> 2002/10/01

Hi Dave,

[#52150] Re: thoughts on typelessness — Dave Thomas <Dave@...> 2002/10/01

William Djaja Tjokroaminata <billtj@y.glue.umd.edu> writes:

[#52151] Re: thoughts on typelessness — GOTO Kentaro <gotoken@...> 2002/10/01

At Wed, 2 Oct 2002 01:37:46 +0900,

[#52154] Re: thoughts on typelessness — Paul Brannan <pbrannan@...> 2002/10/01

On Wed, Oct 02, 2002 at 02:11:24AM +0900, GOTO Kentaro wrote:

[#51818] announce@ == less email (FAQ item?) — Ryan Davis <ryand-ruby@...>

ZenTest and ZenWeb were just released. I announced these to several

40 messages 2002/09/29

[#51974] Things That Newcomers to Ruby Should Know — William Djaja Tjokroaminata <billtj@...>

Things That Newcomers to Ruby Should Know

37 messages 2002/09/30
[#52128] Re: Things That Newcomers to Ruby Should Know — William Djaja Tjokroaminata <billtj@...> 2002/10/01

Thanks, Gabriele. I will try to incorporate your input. The "0 is

[#52965] Re: Things That Newcomers to Ruby Should Know — "Kontra, Gergely" <kgergely@...> 2002/10/11

>> - the ||= operator exists :-)

[#52970] Re: Things That Newcomers to Ruby Should Know — William Djaja Tjokroaminata <billtj@...> 2002/10/11

Hi,

[#52971] Re: Things That Newcomers to Ruby Should Know — dblack@... 2002/10/11

Hi --

Judy inside st_*

From: Mauricio Fern疣dez <batsman.geo@...>
Date: 2002-09-01 23:22:00 UTC
List: ruby-talk #48815
Attached is my latest development on the new st_* routines based on 
JudyL arrays. It is now nearly as fast as the standard hashing method,
and there shouldn't be many bugs left.

I won't be able to work on this for a while as I'm moving to
Stuttgart (Germany) tomorrow from Madrid (Spain), and I don't know when
I'll get a computer...

BTW, I've seen there's a Ruby Users Group in B.-W. :-)

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
  
Linux: Where Don't We Want To Go Today?
	-- Submitted by Pancrazio De Mauro, paraphrasing some well-known sales talk

Attachments (1)

ruby-judy-0.0.2.patch (15 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	Wed Aug 28 12:20:31 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	Fri Aug 30 10:44:30 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;
@@ -280,10 +279,12 @@
 {
     st_table *tbl;
 
+#ifndef HAVE_LIBJUDY
     tbl = st_init_table_with_size(&objhash, RHASH(hash)->tbl->num_entries);
     st_foreach(RHASH(hash)->tbl, rb_hash_rehash_i, tbl);
     st_free_table(RHASH(hash)->tbl);
     RHASH(hash)->tbl = tbl;
+#endif
 
     return hash;
 }
@@ -544,9 +545,12 @@
     VALUE hash, key, val;
 {
     rb_hash_modify(hash);
-    if (TYPE(key) != T_STRING || st_lookup(RHASH(hash)->tbl, key, 0)) {
+	if ( TYPE(key) != T_STRING ) {
 	st_insert(RHASH(hash)->tbl, key, val);
     }
+	else if ( st_update_if_present(RHASH(hash)->tbl, key, val) ) {
+	/* do nothing, as it was already in and has been updated*/
+    }
     else {
 	st_add_direct(RHASH(hash)->tbl, rb_str_new4(key), val);
     }
diff -rwdu ruby/st.c ruby-judy/st.c
--- ruby/st.c	Wed Jul 31 00:30:20 2002
+++ ruby-judy/st.c	Sun Sep  1 00:39:37 2002
@@ -11,27 +11,18 @@
 #include <malloc.h>
 #endif
 
+#include <Judy.h>
+
+#define HASH_LOG
+
 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 +57,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 +85,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 +99,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 +144,28 @@
 {
     register st_table_entry *ptr, *next;
     int i;
+    PPvoid_t PValue;
+    Word_t Index, Useless;
+    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;
+		JLF( PValue, table->PJLArray[i], Index);
+		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);	
 	}
+			JLN( PValue, table->PJLArray[i], Index);
     }
-    free(table->bins);
-    free(table);
+		JLFA( Useless, table->PJLArray[i] );
 }
 
-#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 +174,25 @@
 #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)) {\
+    PPvoid_t PValue;\
+	\
+	bin_pos = HASHINDEX(hash_val);\
+	/*FIXME: error handling? */\
+	/*FIXME: is JLG really faster than JudyLGet?*/\
+    JLG(PValue,HASHARRAY(table,hash_val), bin_pos);\
+	if (PValue) {\
+		ptr = HASHNODE(PValue);\
+		if ( ptr ) {\
+				if ( EQUAL(table, ptr->key, key) ) \
+					break;\
 	COLLISION;\
-	while (PTR_NOT_EQUAL(table, ptr->next, hash_val, key)) {\
-	    ptr = ptr->next;\
+				for ( ptr = ptr->next; ptr; ptr = ptr->next)\
+					if ( EQUAL(table, ptr->key, key) ) \
+						break;\
 	}\
-	ptr = ptr->next;\
+	}\
+	else {\
+		ptr = 0;\
     }\
 } while (0)
 
@@ -269,18 +220,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);\
+    JLI( PValue, HASHARRAY(table,hash_val), bin_pos );\
     \
-    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,12 +240,59 @@
 {
     unsigned int hash_val, bin_pos;
     register st_table_entry *ptr;
+	PPvoid_t PValue;
+
+
+    hash_val = do_hash(key, table);
+	JLI( PValue, HASHARRAY(table, hash_val), HASHINDEX(hash_val) );
+	if ( *PValue ) {
+		ptr = HASHNODE(PValue);
+		/* we layout the code this way to be able to count collisions */
+		if ( ptr ) {
+			if (EQUAL(table, ptr->key, key) ) {
+				ptr->record = value;
+				return 1;
+			}  
+			COLLISION;
+			for ( ptr = ptr->next; ptr; ptr = ptr->next )
+				if ( EQUAL(table, ptr->key, key) ) {
+					ptr->record = value;
+					return 1;
+				}
+		}
+		/* if it gets here, either the has was empty or no element had 
+		 * the same key */
+		ptr = alloc(st_table_entry);
+		ptr->key = key;
+		ptr->record = value;
+		ptr->next = *PValue;
+		*PValue = ptr;
+		++table->num_entries;
+		return 0;
+    }
+    else {
+		*PValue = alloc(st_table_entry);
+		HASHNODE(PValue)->key = key;
+		HASHNODE(PValue)->record = value;
+		HASHNODE(PValue)->next = 0;
+		++table->num_entries;
+		return 0;
+    }
+}
+
+int
+st_update_if_present(table, key, value)
+    st_table *table;
+    register char *key;
+    char *value;
+{
+    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) {
-	ADD_DIRECT(table, key, value, hash_val, bin_pos);
 	return 0;
     }
     else {
@@ -315,72 +310,46 @@
     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*));
-
-    if (new_table->bins == 0) {
-	free(new_table);
-	return 0;
-    }
+    new_table->num_entries = old_table->num_entries;
 
-    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;
+    for(i = 0; i < HASHSIZE; i++) {
+		Index = 0;
+		JLF( PValue, old_table->PJLArray[i], Index );
+		while( PValue ) {
+			//FIXME: should assert( *PValue ); ?
+			JLI( entry, new_table->PJLArray[i], Index );
+			*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 = oldptr->key;
+				ptr->record = oldptr->record;
+				ptr->next = *entry;
+				*entry = ptr;
 	    }
-	    *entry = *ptr;
-	    entry->next = new_table->bins[i];
-	    new_table->bins[i] = entry;
-	    ptr = ptr->next;
+			JLN( PValue, old_table->PJLArray[i], Index );
 	}
     }
     return new_table;
@@ -394,33 +363,27 @@
 {
     unsigned int hash_val;
     st_table_entry *tmp;
-    register st_table_entry *ptr;
-
-    hash_val = do_hash_bin(*key, table);
-    ptr = table->bins[hash_val];
+    register st_table_entry **ptr, *ptr2;
+	int useless;
 
+    hash_val = do_hash(*key, table);
+    JLG( ptr, HASHARRAY(table, hash_val), HASHINDEX(hash_val) );
     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 = (*ptr)->next;
+			free( ptr2 );
+			if ( ! *ptr ) 
+				JLD( useless, HASHARRAY(table,hash_val), HASHINDEX(hash_val) );
+			--table->num_entries;
 	    return 1;
 	}
     }
@@ -437,15 +400,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];
+    hash_val = do_hash(*key, table);
+    JLG( pValue, HASHARRAY(table,hash_val), HASHINDEX(hash_val) );
 
-    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--;
@@ -472,10 +437,10 @@
     st_table *table;
     char *never;
 {
-    int num_entries = table->num_entries;
+    //int num_entries = table->num_entries;
 
     st_foreach(table, delete_never, never);
-    table->num_entries = num_entries;
+    //table->num_entries = num_entries;
 }
 
 void
@@ -485,12 +450,21 @@
     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++) {
+		Index = 0;
+		if ( table->PJLArray[i] == 0 )  // empty JudyL array
+			continue; 
+		JLF( PValue, table->PJLArray[i], Index );
+		while ( PValue ) {
 	last = 0;
-	for(ptr = table->bins[i]; ptr != 0;) {
+			ptr = HASHNODE(PValue);
+			while ( ptr != 0 ) {
+				/*FIXME: sometimes crashes here with ptr->record == NULL !!!*/
 	    retval = (*func)(ptr->key, ptr->record, arg);
 	    switch (retval) {
 	    case ST_CONTINUE:
@@ -502,7 +476,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 +484,11 @@
 		ptr = ptr->next;
 		free(tmp);
 		table->num_entries--;
-	    }
-	}
-    }
+	    		} // switch 
+	    	} // while to scan collision list
+			JLN( PValue, table->PJLArray[i], Index );
+		} // while to scan Judy array
+    } // for
 }
 
 static int
@@ -563,3 +539,7 @@
 {
     return n;
 }
+
+/*
+ * vim: ts=4:
+ */
diff -rwdu ruby/st.h ruby-judy/st.h
--- ruby/st.h	Wed Jan  5 05:37:12 2000
+++ ruby-judy/st.h	Sun Sep  1 00:44:07 2002
@@ -6,6 +6,8 @@
 
 #define ST_INCLUDED
 
+#include <Judy.h>
+
 typedef struct st_table st_table;
 
 struct st_hash_type {
@@ -13,11 +15,12 @@
     int (*hash)();
 };
 
+#define HASHSIZE 1
+
 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)
@@ -32,6 +35,7 @@
 st_table *st_init_strtable_with_size();
 int st_delete(), st_delete_safe();
 int st_insert(), st_lookup();
+int st_update_if_present();
 void st_foreach(), st_add_direct(), st_free_table(), st_cleanup_safe();
 st_table *st_copy();
 

In This Thread

Prev Next