PreviousUpNext

15.3.422  src/lib/src/rw-bit-vector.api

## rw-bit-vector.api

# Compiled by:
#     src/lib/std/standard.lib



# Api for mutable bit array.  The model here treats bit array as an
# array of bools.


api Rw_Bit_Vector = api {

    include Typelocked_Rw_Vector;               # Typelocked_Rw_Vector  is from   src/lib/std/src/typelocked-rw-vector.api

    from_string:  String -> Rw_Vector;
      # The string argument gives a hexadecimal
      # representation of the bits set in the
      # rw_vector. Characters 0-9, a-f and A-F are
      # allowed. For example,
      #  from_string "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 rw_vector will be 4*(size string).
      # Raises LibBase::BadArg if a non-hexadecimal character
      # appears in the string.

    bits:  ((Int, List( Int )) ) -> Rw_Vector;
      # Create rw_vector of the given length with the indices of its set bits 
      # given by the list argument.
      # Raises SUBSCRIPT if a list item is < 0 or >= length.

    get_bits:  Rw_Vector -> List( Int );
      # Returns list of bits set in bit rw_vector, in increasing
      # order of indices.

    to_string:  Rw_Vector -> String;
      # Inverse of stringToBits.
      # The bit rw_vector is zero-padded to the next
      # length that is a multiple of 4. 

    is_zero:   Rw_Vector -> Bool;
      #  Returns TRUE if and only if no bits are set. 

    extend0:  ((Rw_Vector, Int)) -> Rw_Vector;
    extend1:  ((Rw_Vector, Int)) -> Rw_Vector;
      # Extend bit rw_vector by 0's or 1's to given length.
      # If bit rw_vector is already >= argument length, return a copy
      # of the bit rw_vector.
      # Raises SIZE if length < 0.

    eq_bits:  ((Rw_Vector, Rw_Vector)) -> Bool;
      #  TRUE if set bits are identical 
    equal:  ((Rw_Vector, Rw_Vector)) -> Bool;
      #  TRUE if same length and same set bits 

    bitwise_and:  ((Rw_Vector, Rw_Vector, Int)) -> Rw_Vector;
    bitwise_or:   ((Rw_Vector, Rw_Vector, Int)) -> Rw_Vector;
    bitwise_xor:  ((Rw_Vector, Rw_Vector, Int)) -> Rw_Vector;
      # Create new rw_vector of the given length
      # by logically combining bits of original 
      # rw_vector using and, or and xor, respectively. 
      # If necessary, the rw_vector are
      # implicitly extended by 0 to be the same length 
      # as the new rw_vector.

    bitwise_not:   Rw_Vector -> Rw_Vector;
      # Create new rw_vector with all bits of original
      # rw_vector inverted.

    lshift:   ((Rw_Vector, Int)) -> Rw_Vector;
      # lshift (ba, n) creates a new rw_vector by
      # inserting n 0's on the right of ba.
      # The new rw_vector has length n + length ba.

    rshift:   ((Rw_Vector, Int)) -> Rw_Vector;
      # rshift (ba, n) creates a new rw_vector of
      # of length max (0, length ba - n) consisting
      # of bits n, n+1, ..., length ba - 1 of ba.
      # If n >= length ba, the new arraarray has length 0.

  #  mutable operations for rw_vector 

    set_bit:  ((Rw_Vector, Int)) -> Void;
    clr_bit:  ((Rw_Vector, Int)) -> Void;
      # Update value at given index to new value.
      # Raises SUBSCRIPT if index < 0 or >= length.
      # setBit (ba, i) = update (ba, i, TRUE)
      # clrBit (ba, i) = update (ba, i, FALSE)

    union:  Rw_Vector -> Rw_Vector -> Void;
    intersection:  Rw_Vector -> Rw_Vector -> Void;
      # Or (and) second bitarray into the first. Second is
      # implicitly truncated or extended by 0's to match 
      # the length of the first.

    complement:  Rw_Vector -> Void;
      #  Invert all bits. 

} #  RW_BIT_VECTOR 
    where  Element == Bool;


## COPYRIGHT (c) 1995 by AT&T Bell Laboratories.  See COPYRIGHT file for details.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2011,
## released under Gnu Public Licence version 3.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext