The BitArray structure provides a implementation of
monomorphic arrays of booleans implemented one bit per
element. The BitArray structure extends the
MONO_ARRAY signature
with bit-level operations.
Synopsis
signature BIT_ARRAY
structure BitArray :> BIT_ARRAY
Interface
include MONO_ARRAY
val fromString : string -> array option
val bits : (int * int list) -> array
val getBits : array -> int list
val toString : array -> string
val isZero : array -> bool
val extend0 : (array * int) -> array
val extend1 : (array * int) -> array
val eqBits : (array * array) -> bool
val equal : (array * array) -> bool
val andb : (array * array * int) -> array
val orb : (array * array * int) -> array
val xorb : (array * array * int) -> array
val notb : array -> array
val << : (array * word) -> array
val >> : (array * word) -> array
val setBit : (array * int) -> unit
val clrBit : (array * int) -> unit
val union : array -> array -> unit
val intersection : array -> array -> unit
val complement : array -> unit
val lshift : (array * int) -> array
val rshift : (array * int) -> array
Description
include MONO_ARRAY-
The
BIT_ARRAYsignature extends theMONO_ARRAYsignature from the Standard ML Basis Library. Note that while theMONO_ARRAYsignature includes a corresponding monomorphicvectortype, there is currently no implementation of a correspondingBitVectorstructure. val fromString : string -> array option-
fromString sreturnsSOME bawhen the stringsis a sequence of hexadecimal digits. The length ofbawill be4*(length s). ReturnsNONEof a non-hexadecimal character is encountered. val bits : (int * int list) -> array-
bits (n, ixs)returns a new arraybaof lengthn, whereba[ix]istruefor eachixin the list of indicesixs. This function raises theSizeexception ifn < 0and theSubscriptexception if any index is out of bounds. val getBits : array -> int list-
getBits bareturns a list of indicesixfor whichba[ix]is true in increasing order. val toString : array -> string-
toString bareturns a string representation of the array as a sequence of hexadecimal digits in little-endian order (i.e., ba[0] is represented as the high-order bit in the first digit). val isZero : array -> bool-
isZero bareturns true if, and only if, no elements aretrueinba. val extend0 : (array * int) -> array-
extend0 (ba, n)returns a new arrayba'that ismax(n, length ba)elements long, where thelength baelements ofba'are copied frombaand the remaining elements arefalse. This function raises theSizeexception ifn < 0. val extend1 : (array * int) -> array-
extend1 (ba, n)returns a new arrayba'that ismax(n, length ba)elements long, where thelength baelements ofba'are copied frombaand the remaining elements aretrue. This function raises theSizeexception ifn < 0. val eqBits : (array * array) -> bool-
eqBits (ba1, ba2)returns true if the two arrays have the sametrueentries. In other words, the following identity holdseqBits(ba1, ba2) = (getBits ba1 = getBits ba2) val equal : (array * array) -> bool-
equal (ba1, ba2)returns true if the two arrays are the same length and have the same elements. val andb : (array * array * int) -> array-
andb (ba1, ba2, n)returns a new arraybaof lengthn, where the elementba[ix]is the logical AND ofba1[ix]andba2[ix], where the inputs are extended withfalseas necessary. This function raises theSizeexception ifn < 0. val orb : (array * array * int) -> array-
orb (ba1, ba2, n)returns a new arraybaof lengthn, where the elementba[ix]is the logical OR ofba1[ix]andba2[ix], where the inputs are extended withfalseas necessary. This function raises theSizeexception ifn < 0. val xorb : (array * array * int) -> array-
xorb (ba1, ba2, n)returns a new arraybaof lengthn, where the elementba[ix]is the logical XOR ofba1[ix]andba2[ix], where the inputs are extended withfalseas necessary. This function raises theSizeexception ifn < 0. val notb : array -> array-
notb bareturns a new array of the same length asbawith the elements negated.
val << : (array * word) -> array-
<< (ba, n)`returns a new array by appending `nfalseelements on the end ofba. The new array will have length equal ton + length ba.
val >> : (array * word) -> array-
>> (ba, n)`returns a new array by trimming `nelements from the "right" ofba. The new array will havemax(0, length ba - n)elements. val setBit : (array * int) -> unit-
setBit (ba, ix)sets the element ofbaat indexixtotrue. This function raises theSubscriptexception ifixis out of bounds. val clrBit : (array * int) -> unit-
setBit (ba, ix)sets the element ofbaat indexixtofalse. This function raises theSubscriptexception ifixis out of bounds. val union : array -> array -> unit-
union ba1 ba2updatesba1by setting each elementba1[ix]to the logical OR ofba1[ix]andba2[ix], whereba2[ix]is extended withfalseelements as necessary to match the length ofba1. val intersection : array -> array -> unit-
intersection ba1 ba2updatesba1by setting each elementba1[ix]to the logical AND ofba1[ix]andba2[ix], whereba2[ix]is extended withfalseelements as necessary to match the length ofba1. val complement : array -> unit-
complement balogically negates all of the elements ofba.