Algorithm based on “Introduction to Algorithms” by Cormen and others
Namespace
- CLASS RedBlackTree::NilNode
- CLASS RedBlackTree::Node
Methods
- #
- A
- B
- D
- E
- I
- M
- N
- P
- R
- S
Included Modules
Attributes
| [RW] | root | |
| [RW] | size |
Class Public methods
new()
Link
Instance Public methods
add(key)
Link
black_height(x = root)
Link
delete(z)
Link
# File benchmark/gc/redblack.rb, line 122 def delete(z) y = (z.left.nil? || z.right.nil?) ? z : successor(z) x = y.left.nil? ? y.right : y.left x.parent = y.parent if y.parent.nil? self.root = x else if y == y.parent.left y.parent.left = x else y.parent.right = x end end z.key = y.key if y != z if y.color == Node::BLACK delete_fixup(x) end self.size -= 1 return y end
empty?()
Link
insert(x)
Link
Also aliased as: <<
# File benchmark/gc/redblack.rb, line 78 def insert(x) insert_helper(x) x.color = Node::RED while x != root && x.parent.color == Node::RED if x.parent == x.parent.parent.left y = x.parent.parent.right if !y.nil? && y.color == Node::RED x.parent.color = Node::BLACK y.color = Node::BLACK x.parent.parent.color = Node::RED x = x.parent.parent else if x == x.parent.right x = x.parent left_rotate(x) end x.parent.color = Node::BLACK x.parent.parent.color = Node::RED right_rotate(x.parent.parent) end else y = x.parent.parent.left if !y.nil? && y.color == Node::RED x.parent.color = Node::BLACK y.color = Node::BLACK x.parent.parent.color = Node::RED x = x.parent.parent else if x == x.parent.left x = x.parent right_rotate(x) end x.parent.color = Node::BLACK x.parent.parent.color = Node::RED left_rotate(x.parent.parent) end end end root.color = Node::BLACK end
maximum(x = root)
Link
minimum(x = root)
Link
predecessor(x)
Link
search(key, x = root)
Link