Log in

No account? Create an account
brad's life [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Ruby, Continuations, Evas, Balanced trees.... [Jul. 1st, 2002|06:35 pm]
Brad Fitzpatrick
Been having fun with Ruby & Evas.

My only qualm with Ruby is its lack of any balanced tree implementation in the standard library. But then, few languages do.

But there's a Ruby wrapper around GNU libavl which'll work.

I need balanced trees to quickly schedule animation update events to happen some time in the future, and be able to quickly remove items at the beginning and run them if necessary while I'm selecting on: X events, remote control events, and timeouts. (well, the last I'm not really selecting on, but yeah....)

I could just write my own hack class around Array and say, "fuck it, there won't be enough pending animations to make the insertion time matter", but that'd only bite me in the ass later as I do more cool stuff.

And I'm realizing that I'm redoing a lot of what evan did in his further port to Ruby, but I don't care.... I'm having fun learning the language.

From: evan
2002-07-01 06:43 pm (UTC)
class ThingtoRun
  include Comparable
  def <=>(other)
    self.time <=> other.time
  # ...

array = []
array << ThingtoRun.new
# etc

And yeah, further gives you all that and a bag of chips (continuations). I need to put that up... some people at the Seattle Ruby group were interested in it.
(Reply) (Thread)
From: evan
2002-07-01 06:44 pm (UTC)
Oh, and the C-based Ruby used a minheap, which is much cooler:
Array-based implementation [no allocation/deallocation!], O(1) for getting the soonest event, and O(log n) to add an event (I think?).
(Reply) (Parent) (Thread)
From: evan
2002-07-01 06:45 pm (UTC)
s/C-based Ruby/C-based further/
(Reply) (Parent) (Thread)
[User Picture]From: brad
2002-07-01 09:08 pm (UTC)
"C-based Ruby".sub(/Ruby/, "further")
(Reply) (Parent) (Thread)
From: evan
2002-07-01 10:38 pm (UTC)
I will talk to you on the 4th about how Perl's Inline module works. I wanna make something like that for Ruby...
(Reply) (Parent) (Thread)