<INTERFACE> The <CD/BitArray/ structure <SEEALSO> <STRREF/BitVector/ <PP> The <STRREF NOLINK/BitArray/ structure provides compacted arrays of booleans, with one bit for each boolean value. A 0 (1) bit corresponds to the boolean value <CD/false/ (<CD/true/), respectively. These arrays can be used to implement sets of integers. Member testing takes constant time and, since a <CD/bitarray/ is mutable, adding and deleting elements are also constant time operations. In addition, the structure provides a complementary set of applicative operations. <SPEC> <INCLUDE>MONO_ARRAY <WHERETYPE><ID>elem<TY>bool</WHERETYPE> <SPEC> <VAL>fromString<TY>string -> array <RAISES> <PROTOTY> fromString <ARG/s/ </PROTOTY> creates an array from the string argument <ARG/s/, which should contain a hexadecimal representation of the bits set in the array. Characters 0-9, a-f and A-F are allowed. For example, <VAL>bits<TY>(int * int list) -> array <RAISES> <PROTOTY> bits (<ARG/sz/, <ARG/l/) </PROTOTY> creates an array of length <ARG/sz/ with the indices of its set bits given by <ARG/l/. Raises <VAL>getBits<TY>array -> int list <COMMENT> <PROTOTY> getBits <ARG/arr/ </PROTOTY> returns a list of indices of the bits set in <ARG/arr/, in increasing order. <SPEC> <VAL>toString<TY>array -> string <COMMENT> <PROTOTY> toString <ARG/arr/ </PROTOTY> encodes a bit array as a string. The bit array is zero-padded to the next length that is a multiple of 4. <SPEC> <VAL>isZero<TY>array -> bool <COMMENT> <PROTOTY> isZero <ARG/arr/ </PROTOTY> returns true if and only if no bits are set. <SPEC> <VAL>extend0<TY>(array * int) -> array <RAISES>extend1<TY>(array * int) -> array <RAISES> <PROTOTY> extend0 (<ARG/arr/, <ARG/len/) <PROTO> extend1 (<ARG/arr/, <ARG/len/) </PROTOTY> create a new arrays by extending the argument bit array by 0's or 1's to given length. If <ARG/arr/ is already as long as <ARG/len/, return a copy of the bit array. Raise <VAL>eqBits<TY>(array * array) -> bool <COMMENT> <PROTOTY> eqBits (<ARG/arr/, <ARG/arr2/) </PROTOTY> returns true if the set bits in the two arrays are the same. This is equivalent to: `getBits <ARG/arr/ = getBits <ARG/arr2/ </CODE> <SPEC> <VAL>equal<TY>(array * array) -> bool <COMMENT> <PROTOTY> equal (<ARG/arr/, <ARG/arr2/) </PROTOTY> returns true if the two arrays are equivalent, i.e., have the same length and set bits. <SPEC> <VAL>andb<TY>(array * array * int) -> array <VAL>orb<TY>(array * array * int) -> array <VAL>xorb<TY>(array * array * int) -> array <COMMENT> <PROTOTY> andb (<ARG/arr/, <ARG/arr2/, <ARG/len/) <PROTO> orb (<ARG/arr/, <ARG/arr2/, <ARG/len/) <PROTO> xorb (<ARG/arr/, <ARG/arr2/, <ARG/len/) </PROTOTY> creates a new array of length <ARG/len/ by logically combining the bits of <ARG/arr/ and <ARG/arr2/ using and, or and xor, respectively. If necessary, the arrays are implicitly extended by 0 to be the same length as the new array. <SPEC> <VAL>notb<TY>array -> array <COMMENT> <PROTOTY> notb <ARG/arr/ </PROTOTY> creates a new array with all bits of original array inverted. <SPEC> <VAL>lshift<TY>(array * int) -> array <RAISES> <PROTOTY> lshift (<ARG/arr/, <ARG/n/) </PROTOTY> creates a new array by inserting <ARG/n/ 0's on the right of <ARG/arr/. The new array has length <MATH/<ARG/n/ + <MTEXT><VALREF>length</VALREF></MTEXT> <ARG/arr//. Raises <VAL>rshift<TY>(array * int) -> array <RAISES> <PROTOTY> rshift (<ARG/arr/, <ARG/n/) </PROTOTY> creates a new array of length <MATH/max(0,<MTEXT><VALREF>length</VALREF></MTEXT> <ARG/arr/ - <ARG/n/)/ consisting of bits <MATH/n,n+1,...,<MTEXT><VALREF>length</VALREF></MTEXT> <ARG/arr/ - 1/ of <ARG/arr/. If <MATH/<ARG/n/ &GREATEREQ; <MTEXT><VALREF>length</VALREF></MTEXT> <ARG/arr//, the new array has length 0. <SPEC> <VAL>setBit<TY>(array * int) -> unit <RAISES>clrBit<TY>(array * int) -> unit <RAISES> <PROTOTY> setBit (<ARG/arr/, <ARG/i/) <PROTO> clrBit (<ARG/arr/, <ARG/i/) </PROTOTY> updates the value at index <ARG/i/ to new value, true and false, respectively. These are equivalent to: `update(arr,i,true) update(arr,i,false)` respectively. Raises <VALREF>length</VALREF></MTEXT> <ARG/arr//. <SPEC> <VAL>union<TY>array -> array -> unit <VAL>intersection<TY>array -> array -> unit <COMMENT> <PROTOTY> union <ARG/arr/ <ARG/arr2/ <PROTO> intersection <ARG/arr/ <ARG/arr2/ </PROTOTY> Or (respectively, and) <ARG/arr2/ into <ARG/arr/. The array <ARG/arr2/ is implicitly truncated or extended by 0's to match the length of the <ARG/arr/. <SPEC> <VAL>complement<TY>array -> unit <COMMENT> <PROTOTY> complement <ARG/arr/ </PROTOTY> inverts all the bits in <ARG/arr/.` </INTERFACE>