From: Tom Sawyer Date: 2002-08-28T13:56:43+09:00 Subject: Re: ANN: RJudy-0.1 - Judy Arrays for Ruby well no one probably read the related post on a mixed Array + Hash class, but just the same i thought of one way to make a distinction between using the same object as both an Array and a Hash, by using differnt reference brackets depending on how you want to treat it. For an array we say: a = [ 'x', 'y', 'z' ] and use the same brackets to get access to the elements: puts a[1] # ==> y but funny for a hash: h = { :a=>'x', :b=>'y', :c=>'z' } we use the same brackets as the array's reference: puts h[:b] # ==> y why don't we use h{:b}, i wonder? b/c if we did then: m = ( 'x', :b=>'y', 'z' ) could be treated distinctly based on the brackets used: puts m[1] # ==> y (treat as array) puts m{:b} # ==> y (treat as hash) just some musings. ~transami On Tue, 2002-08-27 at 00:19, Tom Sawyer wrote: > Lyle, > > i don't recall if you ever expressed an opinion on the concept of a > Mixed Hash + Array type class. just to give you the quick idea if you > didn't follow those old threads: (i'll use ( .. ) for the literal > bracket notation of this Array+Hash entity) > > mix = ( 'w', :b => 'x', 'y', :d => 'z' ) > > from this you can see we have two elements with a specified key and two > without. concievably we could just treat this as an array: > > puts mix[0] # ==> w > puts mix[1] # ==> x > > or we could access it as a hash: > > puts mix[:b] # ==> x > puts mix[:d] # ==> z > > i did some work on this myself, but i don't have the time right now to > pursue it. but in doing so, i discovered the crux of difficulty that > would need to be addressed: the ambiguity between an integer hash key > and an array index, but if this could be thought through and a solution > arrived at, i belive it would make for a more elegent and powerful type > of sequence class. > > anyway, i bring this up simply becasue you're in the process of > implementing this great new hash class, so i thought you might want to > give it some consideration. > > ~transami > > p.s. if i get some time soon, i'll give RJudy a whril. thanks for the > great work! > > > > On Mon, 2002-08-26 at 23:41, 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. > > > > Have fun! > > > > Lyle > > > > > -- > ~transami > > -- ~transami