From ef06a20198e6e40f29142fbaf860fdbea8a9cadf Mon Sep 17 00:00:00 2001 From: huangsimin Date: Wed, 10 Apr 2019 10:42:47 +0800 Subject: [PATCH] =?UTF-8?q?vbt=E6=B7=BB=E5=8A=A0=E4=BA=86=20size=20=3D=203?= =?UTF-8?q?=20=E6=97=B6=E5=80=99=E7=9A=84=E6=97=8B=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- priority_queuekey/vbt.go | 15 +++++++++++++++ vbt/vbt.go | 14 ++++++++++++++ vbtkey/vbtkey.go | 14 ++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/priority_queuekey/vbt.go b/priority_queuekey/vbt.go index fd351b5..a5d45f6 100644 --- a/priority_queuekey/vbt.go +++ b/priority_queuekey/vbt.go @@ -864,7 +864,22 @@ func (tree *vbTree) fixSizeWithRemove(cur *Node) { if rs >= ls*2+factor || ls >= rs*2+factor { cur = tree.fixSize(cur, ls, rs) } + } else if cur.size == 3 { + if cur.children[0] == nil { + if cur.children[1].children[0] == nil { + tree.lrotate3(cur) + } else { + tree.lrrotate3(cur) + } + } else if cur.children[1] == nil { + if cur.children[0].children[1] == nil { + tree.rrotate3(cur) + } else { + tree.rlrotate3(cur) + } + } } + cur = cur.parent } } diff --git a/vbt/vbt.go b/vbt/vbt.go index 4ce84c7..207f136 100644 --- a/vbt/vbt.go +++ b/vbt/vbt.go @@ -868,6 +868,20 @@ func (tree *Tree) fixSizeWithRemove(cur *Node) { if rs >= ls*2+factor || ls >= rs*2+factor { tree.fixSize(cur, ls, rs) } + } else if cur.size == 3 { + if cur.children[0] == nil { + if cur.children[1].children[0] == nil { + tree.lrotate3(cur) + } else { + tree.lrrotate3(cur) + } + } else if cur.children[1] == nil { + if cur.children[0].children[1] == nil { + tree.rrotate3(cur) + } else { + tree.rlrotate3(cur) + } + } } cur = cur.parent } diff --git a/vbtkey/vbtkey.go b/vbtkey/vbtkey.go index 18da20b..fb48e2b 100644 --- a/vbtkey/vbtkey.go +++ b/vbtkey/vbtkey.go @@ -877,6 +877,20 @@ func (tree *Tree) fixSizeWithRemove(cur *Node) { if rs >= ls*2+factor || ls >= rs*2+factor { tree.fixSize(cur, ls, rs) } + } else if cur.size == 3 { + if cur.children[0] == nil { + if cur.children[1].children[0] == nil { + tree.lrotate3(cur) + } else { + tree.lrrotate3(cur) + } + } else if cur.children[1] == nil { + if cur.children[0].children[1] == nil { + tree.rrotate3(cur) + } else { + tree.rlrotate3(cur) + } + } } cur = cur.parent }