BitVector
structure
signature BIT_VECTOR
structure BitVector
: BIT_VECTOR
The BitVector structure provides compacted vectors of booleans, with one bit for each boolean value. A 0 (1) bit corresponds to the boolean value false
(true
), respectively. These vectors can be used to implement sets of integers. Member testing takes constant time.
include MONO_VECTOR
where type elem = bool
val fromString : string -> vector
val bits : (int * int list) -> vector
val getBits : vector -> int list
val toString : vector -> string
val isZero : vector -> bool
val extend0 : (vector * int) -> vector
val extend1 : (vector * int) -> vector
val eqBits : (vector * vector) -> bool
val equal : (vector * vector) -> bool
val andb : (vector * vector * int) -> vector
val orb : (vector * vector * int) -> vector
val xorb : (vector * vector * int) -> vector
val notb : vector -> vector
val lshift : (vector * int) -> vector
val rshift : (vector * int) -> vector
fromString s
fromString "1af8" = 0001101011111000
. (By convention, 0 corresponds to false
and 1 corresponds to true
, bit 0 appears on the right, and indices increase to the left.) The length of the vector will be 4*(size s)
. Raises Fail if a non-hexadecimal character appears in the string.
bits (sz, l)
getBits vec
toString vec
isZero vec
extend0 (vec, len)
extend1 (vec, len)
eqBits (vec, vec2)
getBits vec = getBits vec2
equal (vec, vec2)
andb (vec, vec2, len)
orb (vec, vec2, len)
xorb (vec, vec2, len)
notb vec
lshift (vec, i)
length
vec. Raises Fail if n is negative.
rshift (vec, i)
length
vec - n) consisting of bits n,n+1,...,length
vec - 1 of vec. If n >= length
vec, the new vector has length 0.
BitArray, MONO_VECTOR
Last Modified June 9, 1998
Comments to John Reppy
Copyright © 1998 Bell Labs, Lucent Technologies