@@ -947,6 +947,7 @@ function _deleteat!(B::BitVector, i::Int)
947947end
948948
949949function deleteat! (B:: BitVector , i:: Integer )
950+ i isa Bool && depwarn (" passing Bool as an index is deprecated" , :deleteat! )
950951 i = Int (i)
951952 n = length (B)
952953 1 <= i <= n || throw (BoundsError (B, i))
@@ -987,25 +988,68 @@ function deleteat!(B::BitVector, inds)
987988
988989 (p, s) = y
989990 checkbounds (B, p)
991+ p isa Bool && throw (ArgumentError (" invalid index $p of type Bool" ))
990992 q = p+ 1
991993 new_l -= 1
992994 y = iterate (inds, s)
993995 while y != = nothing
994996 (i, s) = y
995997 if ! (q <= i <= n)
998+ i isa Bool && throw (ArgumentError (" invalid index $i of type Bool" ))
996999 i < q && throw (ArgumentError (" indices must be unique and sorted" ))
9971000 throw (BoundsError (B, i))
9981001 end
9991002 new_l -= 1
10001003 if i > q
1001- copy_chunks! (Bc, p , Bc, Int (q), Int (i- q))
1004+ copy_chunks! (Bc, Int (p) , Bc, Int (q), Int (i- q))
10021005 p += i- q
10031006 end
10041007 q = i+ 1
10051008 y = iterate (inds, s)
10061009 end
10071010
1008- q <= n && copy_chunks! (Bc, p, Bc, Int (q), Int (n- q+ 1 ))
1011+ q <= n && copy_chunks! (Bc, Int (p), Bc, Int (q), Int (n- q+ 1 ))
1012+
1013+ delta_k = num_bit_chunks (new_l) - length (Bc)
1014+ delta_k < 0 && _deleteend! (Bc, - delta_k)
1015+
1016+ B. len = new_l
1017+
1018+ if new_l > 0
1019+ Bc[end ] &= _msk_end (new_l)
1020+ end
1021+
1022+ return B
1023+ end
1024+
1025+ function deleteat! (B:: BitVector , inds:: AbstractVector{Bool} )
1026+ length (inds) == length (B) || throw (BoundsError (B, inds))
1027+
1028+ n = new_l = length (B)
1029+ y = findfirst (inds)
1030+ y === nothing && return B
1031+
1032+ Bc = B. chunks
1033+
1034+ p = y
1035+ s = y + 1
1036+ checkbounds (B, p)
1037+ q = p + 1
1038+ new_l -= 1
1039+ y = findnext (inds, s)
1040+ while y != = nothing
1041+ i = y
1042+ s = y + 1
1043+ new_l -= 1
1044+ if i > q
1045+ copy_chunks! (Bc, Int (p), Bc, Int (q), Int (i- q))
1046+ p += i - q
1047+ end
1048+ q = i + 1
1049+ y = findnext (inds, s)
1050+ end
1051+
1052+ q <= n && copy_chunks! (Bc, Int (p), Bc, Int (q), Int (n - q + 1 ))
10091053
10101054 delta_k = num_bit_chunks (new_l) - length (Bc)
10111055 delta_k < 0 && _deleteend! (Bc, - delta_k)
@@ -1020,6 +1064,10 @@ function deleteat!(B::BitVector, inds)
10201064end
10211065
10221066function splice! (B:: BitVector , i:: Integer )
1067+ # TODO : after deprecation remove the four lines below
1068+ # as v = B[i] is enough to do both bounds checking
1069+ # and Bool check then just pass Int(i) to _deleteat!
1070+ i isa Bool && depwarn (" passing Bool as an index is deprecated" , :splice! )
10231071 i = Int (i)
10241072 n = length (B)
10251073 1 <= i <= n || throw (BoundsError (B, i))
@@ -1032,8 +1080,10 @@ end
10321080const _default_bit_splice = BitVector ()
10331081
10341082function splice! (B:: BitVector , r:: Union{AbstractUnitRange{Int}, Integer} , ins:: AbstractArray = _default_bit_splice)
1083+ r isa Bool && depwarn (" passing Bool as an index is deprecated" , :splice! )
10351084 _splice_int! (B, isa (r, AbstractUnitRange{Int}) ? r : Int (r), ins)
10361085end
1086+
10371087function _splice_int! (B:: BitVector , r, ins)
10381088 n = length (B)
10391089 i_f, i_l = first (r), last (r)
0 commit comments