From: Mark Hahn Date: 2001-11-26T02:43:18+09:00 Subject: [ruby-talk:26462] Re: ++operator and sorted hashes > In c++ maps are sorted I have noticed before that Ruby is lacking a sorted map and a sorted set. I miss the sortedTreeMap class from Java, which is a good general implementation of sorted maps. I have an interesting algorithm for automatically balanced trees that I have been considering implementing in Ruby. -----Original Message----- From: Jakub Travnik [mailto:j.travnik@sh.cvut.cz] Sent: Sunday, November 25, 2001 6:45 AM To: ruby-talk ML; undisclosed-recipients: Subject: [ruby-talk:26450] Re: ++operator and sorted hashes Willi Kappler wrote: > Hi list, > > I'm new to ruby ( using 1.6.5 ) and comming from c++. The language is really great > and easy to learn. But there are some things that would be fine > if they were implemented: > > Is there a certain reason why the ++operator is not implemented ? > In c/c++: a=5; a++; > In ruby: a=5; a+=1 In Ruby everthing is object, a++ means add one in C. What this should mean for String? for Regexp? for Your own class? It does not have usefull object semantic. However a+=something is ok: a=10;a+=1 a='Hello'; a+=' world' a=MyClass.new; a+=MyClass.new (if MyClass have instance method + defined) > An other really usefull object is hash ( map in c++ stl ) > In c++ maps are sorted, in ruby there is a sort function, but it > returns an array. I thought that c++ uses sorted maps for speedup > reasons, so there must be an other reason why ruby doesn't sort them ? It is a implementation reason. there are some links that might explain more about hash tables: http://www.nist.gov/dads/HTML/hashtab.html http://www.wikipedia.com/wiki/Hash_table Jakub Travnik jabber://jtra@jabber.com ICQ: 66770334 (deprecated)