@@ -1949,7 +1949,7 @@ func (rc *runContainer16) andNot(a container) container {
19491949 case * bitmapContainer :
19501950 return rc .andNotBitmap (c )
19511951 case * runContainer16 :
1952- return rc .andNotRunContainer16 (c )
1952+ return rc .andNotRunContainer16 (c ). toEfficientContainer ()
19531953 }
19541954 panic ("unsupported container type" )
19551955}
@@ -2110,7 +2110,7 @@ func (rc *runContainer16) equals(o container) bool {
21102110
21112111func (rc * runContainer16 ) iaddReturnMinimized (x uint16 ) container {
21122112 rc .Add (x )
2113- return rc
2113+ return rc . toEfficientContainer ()
21142114}
21152115
21162116func (rc * runContainer16 ) iadd (x uint16 ) (wasNew bool ) {
@@ -2119,7 +2119,7 @@ func (rc *runContainer16) iadd(x uint16) (wasNew bool) {
21192119
21202120func (rc * runContainer16 ) iremoveReturnMinimized (x uint16 ) container {
21212121 rc .removeKey (x )
2122- return rc
2122+ return rc . toEfficientContainer ()
21232123}
21242124
21252125func (rc * runContainer16 ) iremove (x uint16 ) bool {
@@ -2379,7 +2379,7 @@ func (rc *runContainer16) xor(a container) container {
23792379 case * bitmapContainer :
23802380 return rc .xorBitmap (c )
23812381 case * runContainer16 :
2382- return rc .xorRunContainer16 (c )
2382+ return rc .xorRunContainer16 (c ). toEfficientContainer ()
23832383 }
23842384 panic ("unsupported container type" )
23852385}
@@ -2391,7 +2391,7 @@ func (rc *runContainer16) iandNot(a container) container {
23912391 case * bitmapContainer :
23922392 return rc .iandNotBitmap (c )
23932393 case * runContainer16 :
2394- return rc .iandNotRunContainer16 (c )
2394+ return rc .iandNotRunContainer16 (c ). toEfficientContainer ()
23952395 }
23962396 panic ("unsupported container type" )
23972397}
@@ -2406,7 +2406,7 @@ func (rc *runContainer16) inot(firstOfRange, endx int) container {
24062406 }
24072407 // TODO: minimize copies, do it all inplace; not() makes a copy.
24082408 rc = rc .Not (firstOfRange , endx )
2409- return rc
2409+ return rc . toEfficientContainer ()
24102410}
24112411
24122412func (rc * runContainer16 ) rank (x uint16 ) int {
@@ -2480,21 +2480,23 @@ func (rc *runContainer16) iandNotArray(ac *arrayContainer) container {
24802480 rcb := rc .toBitmapContainer ()
24812481 acb := ac .toBitmapContainer ()
24822482 rcb .iandNotBitmapSurely (acb )
2483- // TODO: check size and optimize the return value
2484- // TODO: is inplace modification really required? If not, elide the copy.
2485- rc2 := newRunContainer16FromBitmapContainer (rcb )
2486- * rc = * rc2
2487- return rc
2483+ answer := rcb .toEfficientContainer ()
2484+ if runrc , ok := answer .(* runContainer16 ); ok {
2485+ * rc = * runrc
2486+ return rc
2487+ }
2488+ return answer
24882489}
24892490
24902491func (rc * runContainer16 ) iandNotBitmap (bc * bitmapContainer ) container {
24912492 rcb := rc .toBitmapContainer ()
24922493 rcb .iandNotBitmapSurely (bc )
2493- // TODO: check size and optimize the return value
2494- // TODO: is inplace modification really required? If not, elide the copy.
2495- rc2 := newRunContainer16FromBitmapContainer (rcb )
2496- * rc = * rc2
2497- return rc
2494+ answer := rcb .toEfficientContainer ()
2495+ if runrc , ok := answer .(* runContainer16 ); ok {
2496+ * rc = * runrc
2497+ return rc
2498+ }
2499+ return answer
24982500}
24992501
25002502func (rc * runContainer16 ) xorRunContainer16 (x2 * runContainer16 ) container {
0 commit comments