@@ -120,8 +120,7 @@ endfunction
120120function s: Remove (key ) abort
121121 if b: stw_root is s: null | return | endif " Empty tree
122122 let b: stw_root = s: Splay (b: stw_root , a: key )
123- " Check if key was in the tree
124- if a: key != b: stw_root .key | return | endif
123+ if a: key != b: stw_root .key | return | endif " Not in tree
125124 let b: stw_count -= 1
126125
127126 if b: stw_root .left is s: null
@@ -145,14 +144,14 @@ function s:RemoveRange(min, max) abort
145144 let b: stw_root = s: Splay (b: stw_root , a: min )
146145
147146 if b: stw_root .right is s: null
148- if b: stw_root . key >= a: min && b: stw_root .key <= a: max
147+ if a: min <= b: stw_root . key && b: stw_root .key <= a: max
149148 if b: stw_root .left isnot s: null | let b: stw_root .left .key += b: stw_root .key | endif
150149 let b: stw_root = b: stw_root .left
151150 let b: stw_count -= 1
152151 endif
153152 else
154153 " Do modified Hibbard deletion
155- if b: stw_root . key >= a: min && b: stw_root .key <= a: max " Should remove root node but keep left subtree
154+ if a: min <= b: stw_root . key && b: stw_root .key <= a: max " Should remove root node but keep left subtree
156155 let rootkey = b: stw_root .key
157156 let x = b: stw_root .left
158157 let b: stw_root = s: Splay (b: stw_root .right , a: max - rootkey + 1 )
@@ -166,14 +165,14 @@ function s:RemoveRange(min, max) abort
166165 else " Should keep root node and left subtree
167166 let b: stw_root .right = s: Splay (b: stw_root .right , a: max - b: stw_root .key + 1 )
168167 let b: stw_count -= s: NodeCount (b: stw_root .right .left )
169- if b: stw_root .right .key < a: max
170- let b: stw_root .right .left = s: null
171- else
168+ if b: stw_root .key + b: stw_root .right .key <= a: max
172169 if b: stw_root .right .right isnot s: null
173170 let b: stw_root .right .right .key += b: stw_root .right .key
174171 endif
175172 let b: stw_root .right = b: stw_root .right .right
176173 let b: stw_count -= 1
174+ else
175+ let b: stw_root .right .left = s: null
177176 endif
178177 endif
179178 endif
0 commit comments