From: "Thies C. Arntzen" Date: 2006-08-13T03:35:13+09:00 Subject: Re: PATCH to make internal Hash class retain order... Brian McCallister schrieb: > On Aug 12, 2006, at 9:55 AM, Thies C. Arntzen wrote: > > > Hi there - > > > > beeing new to ruby (thru rails) and coming from a strong php > > background > > > > > * remember the order in which elements have been added to a Hash (at > > the cost of 2 extra pointers in every hash-bucket + 2 extra pointers > > per hash-table) > > * use this order for iterating (st_foreach will use this order) > > * implement a call Hash.order! allows the user to change the internal > > order;-) > > Nice :-) The better place for discussion hacking on the ruby > interpreter itself is probably ruby-core. i wasn't aware of that list;-) subscribed... > > How difficult would it be to do an OrderedHash data structure as a C > extension instead of in Ruby? i really believe that it needs to be a 1st class citizen - the reason it's done in C is because userland imposes too much overhead (i believe) and converting forward<->back to the normal Hash would be slow, memory intensive and ordering information would get lost on the way... also the amount of code added to the Hash class is ~20 lines of C-code - this code adds zero overhead. the bigger chunk of the code was added to the st.c which is the underlying library for handling hash-tables - and duplicating > 600 lines of code to add ~60 lines didn't seem very cool to me;-) best, thies