algorithms icon indicating copy to clipboard operation
algorithms copied to clipboard

[CRBTreeMap] Segmentation fault at Leetcode #1429

Open alantudyk opened this issue 1 year ago • 4 comments

Only 1 line is different:

OK: https://leetcode.com/submissions/detail/1075862918/

@t.delete p if @t[p]

Not OK: https://leetcode.com/submissions/detail/1075860617/

@t.delete p

alantudyk avatar Oct 15 '23 13:10 alantudyk

I can confirm that deleting a non-existent element causes a segmentation fault sometimes. If you run rspec ten times or so you should see a segmentation fault.

GarrisonJ avatar Jan 08 '24 23:01 GarrisonJ

Causes seg fault with ruby 3.2.2

require 'algorithms'
include Containers

tree = CRBTreeMap.new

tree.push(2, 2)
tree.delete(3)

GarrisonJ avatar Jan 09 '24 00:01 GarrisonJ

A similar issue exists inside RubyRBTreeMap

require 'algorithms'
include Containers

tree = RubyRBTreeMap.new

tree.push(2,2)
tree.delete(3)
`delete_recursive': undefined method `left' for nil:NilClass (NoMethodError)

      if ( !isred(node.right) && !isred(node.right.left) )

GarrisonJ avatar Jan 09 '24 17:01 GarrisonJ

I have a fix waiting for a PR review.

GarrisonJ avatar Jan 09 '24 21:01 GarrisonJ