nahi / avl_tree

AVL tree and Red-black tree in Ruby
BSD 2-Clause "Simplified" License
66 stars 17 forks source link

Can't call #delete() with an invalid key #4

Closed eric closed 12 years ago

eric commented 12 years ago

I just got a report of this: https://github.com/eric/metriks/issues/13

It looks like the problem is that if you try to delete a key that wasn't found, it still tries to call #value on the result.

eric commented 12 years ago

I actually got further on it. The problem is when the key is of a different type:

https://github.com/eric/avl_tree/compare/delete-with-different-types

It looks like the problem is <=> returns nil if the types don't match, and there is no case for that.

nahi commented 12 years ago

Ah, thanks for the investigation. We removed 'key.to_s' so <=> could return nil now. I'm going to change trees to raise TypeError when <=> returns nil for both #insert and #delete. Do you think it's OK for you?

eric commented 12 years ago

Yeah, I think that makes sense. At least I'll be able to figure out where my bug is.