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_ARRAY
signature extends theMONO_ARRAY
signature from the Standard ML Basis Library. Note that while theMONO_ARRAY
signature includes a corresponding monomorphicvector
type, there is currently no implementation of a correspondingBitVector
structure. val fromString : string -> array option
-
fromString s
returnsSOME ba
when the strings
is a sequence of hexadecimal digits. The length ofba
will be4*(length s)
. ReturnsNONE
of a non-hexadecimal character is encountered. val bits : (int * int list) -> array
-
bits (n, ixs)
returns a new arrayba
of lengthn
, whereba[ix]
istrue
for eachix
in the list of indicesixs
. This function raises theSize
exception ifn < 0
and theSubscript
exception if any index is out of bounds. val getBits : array -> int list
-
getBits ba
returns a list of indicesix
for whichba[ix]
is true in increasing order. val toString : array -> string
-
toString ba
returns 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 ba
returns true if, and only if, no elements aretrue
inba
. val extend0 : (array * int) -> array
-
extend0 (ba, n)
returns a new arrayba'
that ismax(n, length ba)
elements long, where thelength ba
elements ofba'
are copied fromba
and the remaining elements arefalse
. This function raises theSize
exception ifn < 0
. val extend1 : (array * int) -> array
-
extend1 (ba, n)
returns a new arrayba'
that ismax(n, length ba)
elements long, where thelength ba
elements ofba'
are copied fromba
and the remaining elements aretrue
. This function raises theSize
exception ifn < 0
. val eqBits : (array * array) -> bool
-
eqBits (ba1, ba2)
returns true if the two arrays have the sametrue
entries. 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 arrayba
of lengthn
, where the elementba[ix]
is the logical AND ofba1[ix]
andba2[ix]
, where the inputs are extended withfalse
as necessary. This function raises theSize
exception ifn < 0
. val orb : (array * array * int) -> array
-
orb (ba1, ba2, n)
returns a new arrayba
of lengthn
, where the elementba[ix]
is the logical OR ofba1[ix]
andba2[ix]
, where the inputs are extended withfalse
as necessary. This function raises theSize
exception ifn < 0
. val xorb : (array * array * int) -> array
-
xorb (ba1, ba2, n)
returns a new arrayba
of lengthn
, where the elementba[ix]
is the logical XOR ofba1[ix]
andba2[ix]
, where the inputs are extended withfalse
as necessary. This function raises theSize
exception ifn < 0
. val notb : array -> array
-
notb ba
returns a new array of the same length asba
with the elements negated.
val << : (array * word) -> array
-
<< (ba, n)`returns a new array by appending `n
false
elements 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 `n
elements 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 ofba
at indexix
totrue
. This function raises theSubscript
exception ifix
is out of bounds. val clrBit : (array * int) -> unit
-
setBit (ba, ix)
sets the element ofba
at indexix
tofalse
. This function raises theSubscript
exception ifix
is out of bounds. val union : array -> array -> unit
-
union ba1 ba2
updatesba1
by setting each elementba1[ix]
to the logical OR ofba1[ix]
andba2[ix]
, whereba2[ix]
is extended withfalse
elements as necessary to match the length ofba1
. val intersection : array -> array -> unit
-
intersection ba1 ba2
updatesba1
by setting each elementba1[ix]
to the logical AND ofba1[ix]
andba2[ix]
, whereba2[ix]
is extended withfalse
elements as necessary to match the length ofba1
. val complement : array -> unit
-
complement ba
logically negates all of the elements ofba
.