2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 import java.io.IOException;
21 import java.io.ObjectInputStream;
22 import java.io.Serializable;
25 * The {@code BitSet} class implements a bit field. Each element in a
26 * {@code BitSet} can be on(1) or off(0). A {@code BitSet} is created with a
27 * given size and grows if this size is exceeded. Growth is always rounded to a
30 public class BitSet implements Serializable, Cloneable {
31 private static final long serialVersionUID = 7997698588986878753L;
33 private static final int OFFSET = 6;
35 private static final int ELM_SIZE = 1 << OFFSET;
37 private static final int RIGHT_BITS = ELM_SIZE - 1;
39 private static final long[] TWO_N_ARRAY = new long[] { 0x1L, 0x2L, 0x4L,
40 0x8L, 0x10L, 0x20L, 0x40L, 0x80L, 0x100L, 0x200L, 0x400L, 0x800L,
41 0x1000L, 0x2000L, 0x4000L, 0x8000L, 0x10000L, 0x20000L, 0x40000L,
42 0x80000L, 0x100000L, 0x200000L, 0x400000L, 0x800000L, 0x1000000L,
43 0x2000000L, 0x4000000L, 0x8000000L, 0x10000000L, 0x20000000L,
44 0x40000000L, 0x80000000L, 0x100000000L, 0x200000000L, 0x400000000L,
45 0x800000000L, 0x1000000000L, 0x2000000000L, 0x4000000000L,
46 0x8000000000L, 0x10000000000L, 0x20000000000L, 0x40000000000L,
47 0x80000000000L, 0x100000000000L, 0x200000000000L, 0x400000000000L,
48 0x800000000000L, 0x1000000000000L, 0x2000000000000L,
49 0x4000000000000L, 0x8000000000000L, 0x10000000000000L,
50 0x20000000000000L, 0x40000000000000L, 0x80000000000000L,
51 0x100000000000000L, 0x200000000000000L, 0x400000000000000L,
52 0x800000000000000L, 0x1000000000000000L, 0x2000000000000000L,
53 0x4000000000000000L, 0x8000000000000000L };
57 private transient boolean needClear;
59 private transient int actualArrayLength;
61 private transient boolean isLengthActual;
64 * Create a new {@code BitSet} with size equal to 64 bits.
69 * @see #clear(int, int)
70 * @see #set(int, boolean)
72 * @see #set(int, int, boolean)
76 actualArrayLength = 0;
77 isLengthActual = true;
81 * Create a new {@code BitSet} with size equal to nbits. If nbits is not a
82 * multiple of 64, then create a {@code BitSet} with size nbits rounded to
83 * the next closest multiple of 64.
86 * the size of the bit set.
87 * @throws NegativeArraySizeException
88 * if {@code nbits} is negative.
92 * @see #clear(int, int)
93 * @see #set(int, boolean)
95 * @see #set(int, int, boolean)
97 public BitSet(int nbits) {
99 throw new NegativeArraySizeException();
101 bits = new long[(nbits >> OFFSET) + ((nbits & RIGHT_BITS) > 0 ? 1 : 0)];
102 actualArrayLength = 0;
103 isLengthActual = true;
107 * Private constructor called from get(int, int) method
110 * the size of the bit set
112 private BitSet(long[] bits, boolean needClear, int actualArrayLength, boolean isLengthActual) {
114 this.needClear = needClear;
115 this.actualArrayLength = actualArrayLength;
116 this.isLengthActual = isLengthActual;
120 * Creates a copy of this {@code BitSet}.
122 * @return a copy of this {@code BitSet}.
125 public Object clone() {
127 BitSet clone = (BitSet) super.clone();
128 clone.bits = bits.clone();
130 } catch (CloneNotSupportedException e) {
131 throw new AssertionError(e); // android-changed
136 * Compares the argument to this {@code BitSet} and returns whether they are
137 * equal. The object must be an instance of {@code BitSet} with the same
141 * the {@code BitSet} object to compare.
142 * @return a {@code boolean} indicating whether or not this {@code BitSet} and
143 * {@code obj} are equal.
147 public boolean equals(Object obj) {
151 if (obj instanceof BitSet) {
152 long[] bsBits = ((BitSet) obj).bits;
153 int length1 = this.actualArrayLength, length2 = ((BitSet) obj).actualArrayLength;
154 if (this.isLengthActual && ((BitSet) obj).isLengthActual
155 && length1 != length2) {
158 // If one of the BitSets is larger than the other, check to see if
159 // any of its extra bits are set. If so return false.
160 if (length1 <= length2) {
161 for (int i = 0; i < length1; i++) {
162 if (bits[i] != bsBits[i]) {
166 for (int i = length1; i < length2; i++) {
167 if (bsBits[i] != 0) {
172 for (int i = 0; i < length2; i++) {
173 if (bits[i] != bsBits[i]) {
177 for (int i = length2; i < length1; i++) {
189 * Increase the size of the internal array to accommodate {@code len} bits.
190 * The new array max index will be a multiple of 64.
193 * the index the new array needs to be able to access.
195 private final void growLength(int len) {
196 long[] tempBits = new long[Math.max(len, bits.length * 2)];
197 System.arraycopy(bits, 0, tempBits, 0, this.actualArrayLength);
202 * Computes the hash code for this {@code BitSet}. If two {@code BitSet}s are equal
203 * the have to return the same result for {@code hashCode()}.
205 * @return the {@code int} representing the hash code for this bit
208 * @see java.util.Hashtable
211 public int hashCode() {
213 for (int i = 0, length = actualArrayLength; i < length; i++) {
214 x ^= bits[i] * (i + 1);
216 return (int) ((x >> 32) ^ x);
220 * Retrieves the bit at index {@code index}. Grows the {@code BitSet} if
221 * {@code index > size}.
224 * the index of the bit to be retrieved.
225 * @return {@code true} if the bit at {@code index} is set,
226 * {@code false} otherwise.
227 * @throws IndexOutOfBoundsException
228 * if {@code index} is negative.
232 * @see #clear(int, int)
233 * @see #set(int, boolean)
234 * @see #set(int, int)
235 * @see #set(int, int, boolean)
237 public boolean get(int index) {
239 int arrayPos = index >> OFFSET;
240 if (arrayPos < actualArrayLength) {
241 return (bits[arrayPos] & TWO_N_ARRAY[index & RIGHT_BITS]) != 0;
246 private void checkIndex(int index) {
248 throw new IndexOutOfBoundsException("index < 0");
252 private void checkRange(int fromIndex, int toIndex) {
253 if (fromIndex < 0 || toIndex < 0 || toIndex < fromIndex) {
254 throw new IndexOutOfBoundsException("fromIndex=" + fromIndex + " toIndex=" + toIndex);
259 * Retrieves the bits starting from {@code fromIndex} to {@code toIndex} and returns
260 * back a new bitset made of these bits. Grows the {@code BitSet} if {@code toIndex > size}.
263 * inclusive beginning position.
265 * exclusive ending position.
266 * @return new bitset of the range specified.
267 * @throws IndexOutOfBoundsException
268 * if {@code fromIndex} or {@code toIndex} is negative, or if
269 * {@code toIndex} is smaller than {@code fromIndex}.
272 public BitSet get(int fromIndex, int toIndex) {
273 checkRange(fromIndex, toIndex);
275 int last = actualArrayLength << OFFSET;
276 if (fromIndex >= last || fromIndex == toIndex) {
277 return new BitSet(0);
279 if (toIndex > last) {
283 int idx1 = fromIndex >> OFFSET;
284 int idx2 = (toIndex - 1) >> OFFSET;
285 long factor1 = (~0L) << (fromIndex & RIGHT_BITS);
286 long factor2 = (~0L) >>> (ELM_SIZE - (toIndex & RIGHT_BITS));
289 long result = (bits[idx1] & (factor1 & factor2)) >>> (fromIndex % ELM_SIZE);
291 return new BitSet(0);
293 return new BitSet(new long[] { result }, needClear, 1, true);
295 long[] newbits = new long[idx2 - idx1 + 1];
296 // first fill in the first and last indexes in the new bitset
297 newbits[0] = bits[idx1] & factor1;
298 newbits[newbits.length - 1] = bits[idx2] & factor2;
300 // fill in the in between elements of the new bitset
301 for (int i = 1; i < idx2 - idx1; i++) {
302 newbits[i] = bits[idx1 + i];
305 // shift all the elements in the new bitset to the right by fromIndex % ELM_SIZE
306 int numBitsToShift = fromIndex & RIGHT_BITS;
307 int actualLen = newbits.length;
308 if (numBitsToShift != 0) {
309 for (int i = 0; i < newbits.length; i++) {
310 // shift the current element to the right regardless of
312 newbits[i] = newbits[i] >>> (numBitsToShift);
314 // apply the last x bits of newbits[i+1] to the current
316 if (i != newbits.length - 1) {
317 newbits[i] |= newbits[i + 1] << (ELM_SIZE - (numBitsToShift));
319 if (newbits[i] != 0) {
324 return new BitSet(newbits, needClear, actualLen,
325 newbits[actualLen - 1] != 0);
329 * Sets the bit at index {@code index} to 1. Grows the {@code BitSet} if
330 * {@code index > size}.
333 * the index of the bit to set.
334 * @throws IndexOutOfBoundsException
335 * if {@code index} is negative.
338 * @see #clear(int, int)
340 public void set(int index) {
342 int len = (index >> OFFSET) + 1;
343 if (len > bits.length) {
346 bits[len - 1] |= TWO_N_ARRAY[index & RIGHT_BITS];
347 if (len > actualArrayLength) {
348 actualArrayLength = len;
349 isLengthActual = true;
355 * Sets the bit at index {@code index} to {@code val}. Grows the
356 * {@code BitSet} if {@code index > size}.
359 * the index of the bit to set.
361 * value to set the bit.
362 * @throws IndexOutOfBoundsException
363 * if {@code index} is negative.
366 public void set(int index, boolean val) {
375 * Sets the bits starting from {@code fromIndex} to {@code toIndex}. Grows the
376 * {@code BitSet} if {@code toIndex > size}.
379 * inclusive beginning position.
381 * exclusive ending position.
382 * @throws IndexOutOfBoundsException
383 * if {@code fromIndex} or {@code toIndex} is negative, or if
384 * {@code toIndex} is smaller than {@code fromIndex}.
387 public void set(int fromIndex, int toIndex) {
388 checkRange(fromIndex, toIndex);
390 if (fromIndex == toIndex) {
393 int len2 = ((toIndex - 1) >> OFFSET) + 1;
394 if (len2 > bits.length) {
398 int idx1 = fromIndex >> OFFSET;
399 int idx2 = (toIndex - 1) >> OFFSET;
400 long factor1 = (~0L) << (fromIndex & RIGHT_BITS);
401 long factor2 = (~0L) >>> (ELM_SIZE - (toIndex & RIGHT_BITS));
404 bits[idx1] |= (factor1 & factor2);
406 bits[idx1] |= factor1;
407 bits[idx2] |= factor2;
408 for (int i = idx1 + 1; i < idx2; i++) {
412 if (idx2 + 1 > actualArrayLength) {
413 actualArrayLength = idx2 + 1;
414 isLengthActual = true;
419 private void needClear() {
420 this.needClear = true;
424 * Sets the bits starting from {@code fromIndex} to {@code toIndex} to the given
425 * {@code val}. Grows the {@code BitSet} if {@code toIndex > size}.
428 * inclusive beginning position.
430 * exclusive ending position.
432 * value to set these bits.
433 * @throws IndexOutOfBoundsException
434 * if {@code fromIndex} or {@code toIndex} is negative, or if
435 * {@code toIndex} is smaller than {@code fromIndex}.
438 public void set(int fromIndex, int toIndex, boolean val) {
440 set(fromIndex, toIndex);
442 clear(fromIndex, toIndex);
447 * Clears all the bits in this {@code BitSet}.
450 * @see #clear(int, int)
452 public void clear() {
454 for (int i = 0; i < bits.length; i++) {
457 actualArrayLength = 0;
458 isLengthActual = true;
464 * Clears the bit at index {@code index}. Grows the {@code BitSet} if
465 * {@code index > size}.
468 * the index of the bit to clear.
469 * @throws IndexOutOfBoundsException
470 * if {@code index} is negative.
471 * @see #clear(int, int)
473 public void clear(int index) {
478 int arrayPos = index >> OFFSET;
479 if (arrayPos < actualArrayLength) {
480 bits[arrayPos] &= ~(TWO_N_ARRAY[index & RIGHT_BITS]);
481 if (bits[actualArrayLength - 1] == 0) {
482 isLengthActual = false;
488 * Clears the bits starting from {@code fromIndex} to {@code toIndex}. Grows the
489 * {@code BitSet} if {@code toIndex > size}.
492 * inclusive beginning position.
494 * exclusive ending position.
495 * @throws IndexOutOfBoundsException
496 * if {@code fromIndex} or {@code toIndex} is negative, or if
497 * {@code toIndex} is smaller than {@code fromIndex}.
500 public void clear(int fromIndex, int toIndex) {
501 checkRange(fromIndex, toIndex);
506 int last = (actualArrayLength << OFFSET);
507 if (fromIndex >= last || fromIndex == toIndex) {
510 if (toIndex > last) {
514 int idx1 = fromIndex >> OFFSET;
515 int idx2 = (toIndex - 1) >> OFFSET;
516 long factor1 = (~0L) << (fromIndex & RIGHT_BITS);
517 long factor2 = (~0L) >>> (ELM_SIZE - (toIndex & RIGHT_BITS));
520 bits[idx1] &= ~(factor1 & factor2);
522 bits[idx1] &= ~factor1;
523 bits[idx2] &= ~factor2;
524 for (int i = idx1 + 1; i < idx2; i++) {
528 if ((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0)) {
529 isLengthActual = false;
534 * Flips the bit at index {@code index}. Grows the {@code BitSet} if
535 * {@code index > size}.
538 * the index of the bit to flip.
539 * @throws IndexOutOfBoundsException
540 * if {@code index} is negative.
541 * @see #flip(int, int)
543 public void flip(int index) {
545 int len = (index >> OFFSET) + 1;
546 if (len > bits.length) {
549 bits[len - 1] ^= TWO_N_ARRAY[index & RIGHT_BITS];
550 if (len > actualArrayLength) {
551 actualArrayLength = len;
553 isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
558 * Flips the bits starting from {@code fromIndex} to {@code toIndex}. Grows the
559 * {@code BitSet} if {@code toIndex > size}.
562 * inclusive beginning position.
564 * exclusive ending position.
565 * @throws IndexOutOfBoundsException
566 * if {@code fromIndex} or {@code toIndex} is negative, or if
567 * {@code toIndex} is smaller than {@code fromIndex}.
570 public void flip(int fromIndex, int toIndex) {
571 checkRange(fromIndex, toIndex);
573 if (fromIndex == toIndex) {
576 int len2 = ((toIndex - 1) >> OFFSET) + 1;
577 if (len2 > bits.length) {
581 int idx1 = fromIndex >> OFFSET;
582 int idx2 = (toIndex - 1) >> OFFSET;
583 long factor1 = (~0L) << (fromIndex & RIGHT_BITS);
584 long factor2 = (~0L) >>> (ELM_SIZE - (toIndex & RIGHT_BITS));
587 bits[idx1] ^= (factor1 & factor2);
589 bits[idx1] ^= factor1;
590 bits[idx2] ^= factor2;
591 for (int i = idx1 + 1; i < idx2; i++) {
595 if (len2 > actualArrayLength) {
596 actualArrayLength = len2;
598 isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
603 * Checks if these two {@code BitSet}s have at least one bit set to true in the same
607 * {@code BitSet} used to calculate the intersection.
608 * @return {@code true} if bs intersects with this {@code BitSet},
609 * {@code false} otherwise.
611 public boolean intersects(BitSet bs) {
612 long[] bsBits = bs.bits;
613 int length1 = actualArrayLength, length2 = bs.actualArrayLength;
615 if (length1 <= length2) {
616 for (int i = 0; i < length1; i++) {
617 if ((bits[i] & bsBits[i]) != 0L) {
622 for (int i = 0; i < length2; i++) {
623 if ((bits[i] & bsBits[i]) != 0L) {
633 * Performs the logical AND of this {@code BitSet} with another
634 * {@code BitSet}. The values of this {@code BitSet} are changed accordingly.
637 * {@code BitSet} to AND with.
641 public void and(BitSet bs) {
642 long[] bsBits = bs.bits;
646 int length1 = actualArrayLength, length2 = bs.actualArrayLength;
647 if (length1 <= length2) {
648 for (int i = 0; i < length1; i++) {
649 bits[i] &= bsBits[i];
652 for (int i = 0; i < length2; i++) {
653 bits[i] &= bsBits[i];
655 for (int i = length2; i < length1; i++) {
658 actualArrayLength = length2;
660 isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
664 * Clears all bits in the receiver which are also set in the parameter
665 * {@code BitSet}. The values of this {@code BitSet} are changed accordingly.
668 * {@code BitSet} to ANDNOT with.
670 public void andNot(BitSet bs) {
671 long[] bsBits = bs.bits;
675 int range = actualArrayLength < bs.actualArrayLength ? actualArrayLength
676 : bs.actualArrayLength;
677 for (int i = 0; i < range; i++) {
678 bits[i] &= ~bsBits[i];
681 if (actualArrayLength < range) {
682 actualArrayLength = range;
684 isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
688 * Performs the logical OR of this {@code BitSet} with another {@code BitSet}.
689 * The values of this {@code BitSet} are changed accordingly.
692 * {@code BitSet} to OR with.
696 public void or(BitSet bs) {
697 int bsActualLen = bs.getActualArrayLength();
698 if (bsActualLen > bits.length) {
699 long[] tempBits = new long[bsActualLen];
700 System.arraycopy(bs.bits, 0, tempBits, 0, bs.actualArrayLength);
701 for (int i = 0; i < actualArrayLength; i++) {
702 tempBits[i] |= bits[i];
705 actualArrayLength = bsActualLen;
706 isLengthActual = true;
708 long[] bsBits = bs.bits;
709 for (int i = 0; i < bsActualLen; i++) {
710 bits[i] |= bsBits[i];
712 if (bsActualLen > actualArrayLength) {
713 actualArrayLength = bsActualLen;
714 isLengthActual = true;
721 * Performs the logical XOR of this {@code BitSet} with another {@code BitSet}.
722 * The values of this {@code BitSet} are changed accordingly.
725 * {@code BitSet} to XOR with.
729 public void xor(BitSet bs) {
730 int bsActualLen = bs.getActualArrayLength();
731 if (bsActualLen > bits.length) {
732 long[] tempBits = new long[bsActualLen];
733 System.arraycopy(bs.bits, 0, tempBits, 0, bs.actualArrayLength);
734 for (int i = 0; i < actualArrayLength; i++) {
735 tempBits[i] ^= bits[i];
738 actualArrayLength = bsActualLen;
739 isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
741 long[] bsBits = bs.bits;
742 for (int i = 0; i < bsActualLen; i++) {
743 bits[i] ^= bsBits[i];
745 if (bsActualLen > actualArrayLength) {
746 actualArrayLength = bsActualLen;
747 isLengthActual = true;
754 * Returns the number of bits this {@code BitSet} has.
756 * @return the number of bits contained in this {@code BitSet}.
760 return bits.length << OFFSET;
764 * Returns the number of bits up to and including the highest bit set.
766 * @return the length of the {@code BitSet}.
768 public int length() {
769 int idx = actualArrayLength - 1;
770 while (idx >= 0 && bits[idx] == 0) {
773 actualArrayLength = idx + 1;
777 int i = ELM_SIZE - 1;
778 long val = bits[idx];
779 while ((val & (TWO_N_ARRAY[i])) == 0 && i > 0) {
782 return (idx << OFFSET) + i + 1;
785 private final int getActualArrayLength() {
786 if (isLengthActual) {
787 return actualArrayLength;
789 int idx = actualArrayLength - 1;
790 while (idx >= 0 && bits[idx] == 0) {
793 actualArrayLength = idx + 1;
794 isLengthActual = true;
795 return actualArrayLength;
799 * Returns a string containing a concise, human-readable description of the
802 * @return a comma delimited list of the indices of all bits that are set.
805 public String toString() {
806 StringBuilder sb = new StringBuilder(bits.length / 2);
809 boolean comma = false;
810 for (int i = 0; i < bits.length; i++) {
812 bitCount += ELM_SIZE;
815 for (int j = 0; j < ELM_SIZE; j++) {
816 if (((bits[i] & (TWO_N_ARRAY[j])) != 0)) {
827 return sb.toString();
831 * Returns the position of the first bit that is {@code true} on or after {@code index}.
834 * the starting position (inclusive).
835 * @return -1 if there is no bits that are set to {@code true} on or after {@code index}.
837 public int nextSetBit(int index) {
840 if (index >= actualArrayLength << OFFSET) {
844 int idx = index >> OFFSET;
845 // first check in the same bit set element
846 if (bits[idx] != 0L) {
847 for (int j = index & RIGHT_BITS; j < ELM_SIZE; j++) {
848 if (((bits[idx] & (TWO_N_ARRAY[j])) != 0)) {
849 return (idx << OFFSET) + j;
855 while (idx < actualArrayLength && bits[idx] == 0L) {
858 if (idx == actualArrayLength) {
862 // we know for sure there is a bit set to true in this element
863 // since the bitset value is not 0L
864 for (int j = 0; j < ELM_SIZE; j++) {
865 if (((bits[idx] & (TWO_N_ARRAY[j])) != 0)) {
866 return (idx << OFFSET) + j;
874 * Returns the position of the first bit that is {@code false} on or after {@code index}.
877 * the starting position (inclusive).
878 * @return the position of the next bit set to {@code false}, even if it is further
879 * than this {@code BitSet}'s size.
881 public int nextClearBit(int index) {
884 int length = actualArrayLength;
885 int bssize = length << OFFSET;
886 if (index >= bssize) {
890 int idx = index >> OFFSET;
891 // first check in the same bit set element
892 if (bits[idx] != (~0L)) {
893 for (int j = index % ELM_SIZE; j < ELM_SIZE; j++) {
894 if (((bits[idx] & (TWO_N_ARRAY[j])) == 0)) {
895 return idx * ELM_SIZE + j;
900 while (idx < length && bits[idx] == (~0L)) {
907 // we know for sure there is a bit set to true in this element
908 // since the bitset value is not 0L
909 for (int j = 0; j < ELM_SIZE; j++) {
910 if (((bits[idx] & (TWO_N_ARRAY[j])) == 0)) {
911 return (idx << OFFSET) + j;
919 * Returns true if all the bits in this {@code BitSet} are set to false.
921 * @return {@code true} if the {@code BitSet} is empty,
922 * {@code false} otherwise.
924 public boolean isEmpty() {
928 int length = bits.length;
929 for (int idx = 0; idx < length; idx++) {
930 if (bits[idx] != 0L) {
938 * Returns the number of bits that are {@code true} in this {@code BitSet}.
940 * @return the number of {@code true} bits in the set.
942 public int cardinality() {
947 int length = bits.length;
948 // FIXME: need to test performance, if still not satisfied, change it to
949 // 256-bits table based
950 for (int idx = 0; idx < length; idx++) {
951 count += pop(bits[idx] & 0xffffffffL);
952 count += pop(bits[idx] >>> 32);
957 private final int pop(long x) {
958 // BEGIN android-note
959 // delegate to Integer.bitCount(i); consider using native code
961 x = x - ((x >>> 1) & 0x55555555);
962 x = (x & 0x33333333) + ((x >>> 2) & 0x33333333);
963 x = (x + (x >>> 4)) & 0x0f0f0f0f;
966 return (int) x & 0x0000003f;
969 private void readObject(ObjectInputStream ois) throws IOException,
970 ClassNotFoundException {
971 ois.defaultReadObject();
972 this.isLengthActual = false;
973 this.actualArrayLength = bits.length;
974 this.needClear = this.getActualArrayLength() != 0;