Bit Vectors in C

What's New

Some other bit vector resources

ANNOUNCE: "Bit::Vector" 5.1 (final release)

From: Steffen Beyer <sb@sdm.de>
Newsgroups: comp.lang.perl.announce,comp.lang.perl.modules
Subject: ANNOUNCE: "Bit::Vector" 5.1 (final release)
Followup-To: comp.lang.perl.modules
Date: 9 Mar 1998 19:00:48 GMT
Organization: sd&m GmbH & Co. KG Munich, Germany
Lines: 305
Message-ID: <6e1e90$494$1@news1.teleport.com>

I am glad to announce version 5.1 of the "Bit::Vector" module:

                    =====================================
                      Package "Bit::Vector" Version 5.1
                    =====================================

The package is available for download either from my web site at

                  http://www.engelschall.com/u/sb/download/

or from any CPAN (= "Comprehensive Perl Archive Network") mirror server:
(allow a few days for propagation if necessary)

                  http://www.perl.com/CPAN/authors/id/STBEY/

The package consists of a C library (designed for maximum efficiency)
which is the core of a Perl module (designed for maximum ease of use).

The C library is specifically designed so that it can be used stand-alone,
without Perl.


What does it do:
----------------

This module is useful for a large range of different tasks:

  -  For example for implementing sets and performing set operations
     (like union, difference, intersection, complement, check for subset
     relationship etc.),

  -  as a basis for many efficient algorithms, for instance the
     "Sieve of Erathostenes" (for calculating prime numbers),

     (The complexities of the methods in this module are usually either
      O(1) or O(n/b), where "b" is the number of bits in a machine word
      on your system.)

  -  for shift registers of arbitrary length (for example for cyclic
     redundancy checksums),

  -  to calculate "look-ahead", "first" and "follow" character sets
     for parsers and compiler-compilers,

  -  for graph algorithms,

  -  for efficient storage and retrieval of status information,

  -  for performing text synthesis ruled by boolean expressions,

  -  for "big integer" arithmetic with arbitrarily large integers,

  -  for manipulations of chunks of bits of arbitrary size,

  -  for bitwise processing of audio CD wave files,

  -  to convert formats of data files,

and more.

(A number of example applications is available from my web site at
http://www.engelschall.com/u/sb/download/.)

A large number of import/export methods allow you to access individual
bits, contiguous ranges of bits, machine words, arbitrary chunks of
bits, lists (arrays) of chunks of bits or machine words and a whole
bit vector at once (for instance for blockwrite/-read to and from
a file).

You can also import and export the contents of a bit vector in binary,
hexadecimal and decimal representation as well as ".newsrc" style
enumerations.

Note that this module is specifically designed for efficiency, which is
also the reason why its methods are implemented in C.

To further increase execution speed, the module doesn't use bytes as its
basic storage unit, but rather uses machine words, assuming that a machine
word is the most efficiently handled size of all scalar types on all
machines (that's what the ANSI C standard proposes and assumes anyway).

In order to achieve this, it automatically determines the number of bits
in a machine word on your system and then adjusts its internal configuration
constants accordingly.

The greater the size of this basic storage unit, the better the complexity
(= execution speed) of the methods in this module, but also the greater the
average waste of unused bits in the last word.

The range of available methods is exceptionally large for this kind of library;
in detail:

Version()                to_Bin()                 Divide()
Word_Bits()              from_Bin()               GCD()
Long_Bits()              to_Dec()                 Block_Store()
new()                    from_Dec()               Block_Read()
Shadow()                 to_Enum()                Word_Size()
Clone()                  from_Enum()              Word_Store()
Concat()                 Bit_Off()                Word_Read()
Concat_List()            Bit_On()                 Word_List_Store()
Size()                   bit_flip()               Word_List_Read()
Resize()                 bit_test()               Word_Insert()
Copy()                   Bit_Copy()               Word_Delete()
Empty()                  LSB()                    Chunk_Store()
Fill()                   MSB()                    Chunk_Read()
Flip()                   lsb()                    Chunk_List_Store()
Primes()                 msb()                    Chunk_List_Read()
Reverse()                rotate_left()            Index_List_Remove()
Interval_Empty()         rotate_right()           Index_List_Store()
Interval_Fill()          shift_left()             Index_List_Read()
Interval_Flip()          shift_right()            Union()
Interval_Reverse()       Move_Left()              Intersection()
Interval_Scan_inc()      Move_Right()             Difference()
Interval_Scan_dec()      Insert()                 ExclusiveOr()
Interval_Copy()          Delete()                 Complement()
Interval_Substitute()    increment()              subset()
is_empty()               decrement()              Norm()
is_full()                add()                    Min()
equal()                  subtract()               Max()
Lexicompare()            Negate()                 Multiplication()
Compare()                Absolute()               Closure()
to_Hex()                 Sign()                   Transpose()
from_Hex()               Multiply()


Important note:
---------------

Note again that the C library at the core of this module ("BitVector.c")
can also be used stand-alone (i.e., without Perl).

To do so, simply link the output file "BitVector.o" (which is produced
when you build this module or when you just compile "BitVector.c") with
your application.


Example applications:
---------------------

See the module "Set::IntegerRange" for an easy-to-use module for sets
of integers.

See the module "Math::MatrixBool" for an implementation of boolean
matrices.

(Both modules are also available from my web site or any CPAN server.)

A tool relying crucially on this "Bit::Vector" module is "Slice",
a tool for generating different document versions out of a single
master file, ruled by boolean expressions ("include english version
of text plus examples but not ...").

(See also http://www.engelschall.com/sw/slice/.)

This tool is itself part of another tool, "WML" ("Website Meta Language"),
which allows you to generate and maintain large web sites.

Among many other features, it allows you to define your own HTML tags which
will be expanded either at generation or at run time, depending on your
choice.

(See also http://www.engelschall.com/sw/wml/.)

Both tools are written by Ralf S. Engelschall.


Changes in version 5.1:
-----------------------

In version 5.1, systematic exception handling was added to "Vector.pm" so that
error conditions arising from method calls in overloaded operators do not show
error messages anymore pointing to the location in "Vector.pm" where the method
was called, but rather to the location in your application program where the
overloaded operator was used.


New features in version 5.0:
----------------------------

In version 5.0, the following new methods have been added:

  -  Word_Bits()
  -  Long_Bits()
  -  Concat()
  -  Concat_List()
  -  Primes()
  -  Reverse()
  -  Interval_Reverse()
  -  Interval_Copy()
  -  Interval_Substitute()
  -  Lexicompare()
  -  to_Bin()
  -  from_bin()
  -  to_Dec()
  -  from_dec()
  -  Bit_Copy()
  -  LSB()
  -  MSB()
  -  lsb()
  -  msb()
  -  Insert()
  -  Delete()
  -  add()
  -  subtract()
  -  Negate()
  -  Absolute()
  -  Sign()
  -  Multiply()
  -  Divide()
  -  GCD()
  -  Block_Store()
  -  Block_Read()
  -  Word_Size()
  -  Word_Store()
  -  Word_Read()
  -  Word_List_Store()
  -  Word_List_Read()
  -  Word_Insert()
  -  Word_Delete()
  -  Chunk_Store()
  -  Chunk_Read()
  -  Chunk_List_Store()
  -  Chunk_List_Read()
  -  Index_List_Remove()
  -  Index_List_Store()
  -  Index_List_Read()
  -  Transpose()

Please see the "Bit::Vector" man page (after installing this module)
for more details about these new methods.

The following methods have been re-implemented in C (instead of Perl):

  -  Version()
  -  Shadow()
  -  Clone()
  -  to_Enum()       (previously named "to_ASCII")
  -  from_enum()     (previously named "from_ASCII")

The following method has changed its behaviour:

  -  Compare()       (now assumes that bit vectors are SIGNED)

The following methods have been renamed:

  -  to_String()      -->    to_Hex()
  -  from_string()    -->    from_hex()
  -  to_ASCII()       -->    to_Enum()
  -  from_ASCII()     -->    from_enum()

(Aliases for the old names are still available but deprecated!)

And finally, the following methods are gone:

  -  lexorder()
  -  new_from_String()

A tool is available in the module's distribution to upgrade your existing
applications and to provide substitutes for the two methods that are gone.


Legal issues:
-------------

This package with all its parts is

Copyright (c) 1995, 1996, 1997, 1998 by Steffen Beyer.
All rights reserved.

This package is "Non-Profit-Ware" ("NP-ware").

You may use, copy, modify and redistribute it under
the terms of the "Non-Profit-License" (NPL).

Please refer to the file "NONPROFIT" in the package's
distribution for details!


Prerequisites:
--------------

Perl version 5.000 or higher, and an ANSI C compiler (!)
                                     ======


Author's note:
--------------

If you have any questions, suggestions or need any assistance, please
let me know!

Also, if there is anything you would like to do with this module which
the module doesn't allow yet, please let me know! If it fits the module's
overall concept, I'll implement it as soon as possible. Frequently this is
only a matter of a few days.

I hope you will find this module beneficial!

Yours,
--
    Steffen Beyer <sb@sdm.de> http://www.engelschall.com/u/sb/
     "There is enough for the need of everyone in this world,
      but not for the greed of everyone." - Mahatma Gandhi

Jump back to top of document | Some other bit vector resources