Skip to content

Commit

Permalink
import Bit-Vector 5.7 from CPAN
Browse files Browse the repository at this point in the history
git-cpan-module:   Bit-Vector
git-cpan-version:  5.7
git-cpan-authorid: STBEY
git-cpan-file:     authors/id/S/ST/STBEY/Bit-Vector-5.7.tar.gz
  • Loading branch information
Steffen Beyer authored and schwern committed Dec 10, 2009
1 parent 03d05ca commit 5a5e593
Show file tree
Hide file tree
Showing 89 changed files with 522 additions and 20,242 deletions.
417 changes: 233 additions & 184 deletions BitVector.c

Large diffs are not rendered by default.

65 changes: 35 additions & 30 deletions BitVector.h
Expand Up @@ -50,7 +50,7 @@ charptr BitVector_Version (void); /* returns version string */
N_int BitVector_Word_Bits (void); /* returns # of bits in machine word */
N_int BitVector_Long_Bits (void); /* returns # of bits in unsigned long */

wordptr BitVector_Create(N_int bits, booltype clear); /* malloc */
wordptr BitVector_Create(N_int bits, boolean clear); /* malloc */

/* ===> OBJECT METHODS: <=== */

Expand Down Expand Up @@ -85,9 +85,9 @@ void BitVector_Interval_Fill (wordptr addr, N_int lower, N_int upper);
void BitVector_Interval_Flip (wordptr addr, N_int lower, N_int upper);
void BitVector_Interval_Reverse (wordptr addr, N_int lower, N_int upper);

booltype BitVector_interval_scan_inc(wordptr addr, N_int start,
boolean BitVector_interval_scan_inc(wordptr addr, N_int start,
N_intptr min, N_intptr max);
booltype BitVector_interval_scan_dec(wordptr addr, N_int start,
boolean BitVector_interval_scan_dec(wordptr addr, N_int start,
N_intptr min, N_intptr max);

void BitVector_Interval_Copy (wordptr X, wordptr Y, N_int Xoffset,
Expand All @@ -99,10 +99,10 @@ wordptr BitVector_Interval_Substitute(wordptr X, wordptr Y,

/* ===> bit vector test functions: */

booltype BitVector_is_empty (wordptr addr); /* X == {} ? */
booltype BitVector_is_full (wordptr addr); /* X == ~{} ? */
boolean BitVector_is_empty (wordptr addr); /* X == {} ? */
boolean BitVector_is_full (wordptr addr); /* X == ~{} ? */

booltype BitVector_equal (wordptr X, wordptr Y); /* X == Y ? */
boolean BitVector_equal (wordptr X, wordptr Y); /* X == Y ? */
Z_int BitVector_Lexicompare (wordptr X, wordptr Y); /* X <,=,> Y ? */
Z_int BitVector_Compare (wordptr X, wordptr Y); /* X <,=,> Y ? */

Expand All @@ -126,39 +126,39 @@ void BitVector_Dispose (charptr string);

void BitVector_Bit_Off (wordptr addr, N_int index); /* X = X \ {x} */
void BitVector_Bit_On (wordptr addr, N_int index); /* X = X + {x} */
booltype BitVector_bit_flip(wordptr addr, N_int index); /* X=(X+{x})\(X*{x}) */
boolean BitVector_bit_flip(wordptr addr, N_int index); /* X=(X+{x})\(X*{x}) */

booltype BitVector_bit_test(wordptr addr, N_int index); /* {x} in X ? */
boolean BitVector_bit_test(wordptr addr, N_int index); /* {x} in X ? */

void BitVector_Bit_Copy(wordptr addr, N_int index, booltype bit);
void BitVector_Bit_Copy(wordptr addr, N_int index, boolean bit);

/* ===> bit vector bit shift & rotate functions: */

void BitVector_LSB (wordptr addr, booltype bit);
void BitVector_MSB (wordptr addr, booltype bit);
booltype BitVector_lsb (wordptr addr);
booltype BitVector_msb (wordptr addr);
booltype BitVector_rotate_left (wordptr addr);
booltype BitVector_rotate_right(wordptr addr);
booltype BitVector_shift_left (wordptr addr, booltype carry_in);
booltype BitVector_shift_right (wordptr addr, booltype carry_in);
void BitVector_LSB (wordptr addr, boolean bit);
void BitVector_MSB (wordptr addr, boolean bit);
boolean BitVector_lsb (wordptr addr);
boolean BitVector_msb (wordptr addr);
boolean BitVector_rotate_left (wordptr addr);
boolean BitVector_rotate_right(wordptr addr);
boolean BitVector_shift_left (wordptr addr, boolean carry_in);
boolean BitVector_shift_right (wordptr addr, boolean carry_in);
void BitVector_Move_Left (wordptr addr, N_int bits);
void BitVector_Move_Right (wordptr addr, N_int bits);

/* ===> bit vector insert/delete bits: */

void BitVector_Insert (wordptr addr, N_int offset, N_int count,
booltype clear);
boolean clear);
void BitVector_Delete (wordptr addr, N_int offset, N_int count,
booltype clear);
boolean clear);

/* ===> bit vector arithmetic: */

booltype BitVector_increment (wordptr addr); /* X++ */
booltype BitVector_decrement (wordptr addr); /* X-- */
boolean BitVector_increment (wordptr addr); /* X++ */
boolean BitVector_decrement (wordptr addr); /* X-- */

booltype BitVector_add (wordptr X, wordptr Y, wordptr Z, booltype carry);
booltype BitVector_subtract(wordptr X, wordptr Y, wordptr Z, booltype carry);
boolean BitVector_add (wordptr X, wordptr Y, wordptr Z, boolean carry);
boolean BitVector_subtract(wordptr X, wordptr Y, wordptr Z, boolean carry);
void BitVector_Negate (wordptr X, wordptr Y);
void BitVector_Absolute(wordptr X, wordptr Y);
Z_int BitVector_Sign (wordptr addr);
Expand All @@ -179,9 +179,9 @@ void BitVector_Word_Store (wordptr addr, N_int offset, N_int value);
N_int BitVector_Word_Read (wordptr addr, N_int offset);

void BitVector_Word_Insert (wordptr addr, N_int offset, N_int count,
booltype clear);
boolean clear);
void BitVector_Word_Delete (wordptr addr, N_int offset, N_int count,
booltype clear);
boolean clear);

/* ===> arbitrary size chunk functions: */

Expand All @@ -200,18 +200,22 @@ void Set_Complement (wordptr X, wordptr Y); /* X = ~Y */

/* ===> set functions: */

booltype Set_subset (wordptr X, wordptr Y); /* X subset Y ? */
boolean Set_subset (wordptr X, wordptr Y); /* X subset Y ? */

N_int Set_Norm (wordptr addr); /* = | X | */
Z_long Set_Min (wordptr addr); /* = min(X) */
Z_long Set_Max (wordptr addr); /* = max(X) */

/* ===> matrix-of-booltypes operations: */
/* ===> matrix-of-booleans operations: */

void Matrix_Multiplication(wordptr X, N_int rowsX, N_int colsX,
wordptr Y, N_int rowsY, N_int colsY,
wordptr Z, N_int rowsZ, N_int colsZ);

void Matrix_Product (wordptr X, N_int rowsX, N_int colsX,
wordptr Y, N_int rowsY, N_int colsY,
wordptr Z, N_int rowsZ, N_int colsZ);

void Matrix_Closure (wordptr addr, N_int rows, N_int cols);

void Matrix_Transpose (wordptr X, N_int rowsX, N_int colsX,
Expand All @@ -230,11 +234,12 @@ void Matrix_Transpose (wordptr X, N_int rowsX, N_int colsX,
/*****************************************************************************/

/*****************************************************************************/
/* VERSION: 5.6 */
/* VERSION: 5.7 */
/*****************************************************************************/
/* VERSION HISTORY: */
/*****************************************************************************/
/* */
/* Version 5.7 19.05.99 Quickened "Div_Pos()". Added "Product()". */
/* Version 5.6 02.11.98 Leading zeros eliminated in "to_Hex()". */
/* Version 5.5 21.09.98 Fixed bug of uninitialized "error" in Multiply. */
/* Version 5.4 07.09.98 Fixed bug of uninitialized "error" in Divide. */
Expand All @@ -244,7 +249,7 @@ void Matrix_Transpose (wordptr X, N_int rowsX, N_int colsX,
/* Version 5.0 01.03.98 Major additions and rewrite. */
/* Version 4.2 16.07.97 Added is_empty, is_full. */
/* Version 4.1 30.06.97 Added word-ins/del, move-left/right, inc/dec. */
/* Version 4.0 23.04.97 Rewrite. Added bit shift and booltype. matrix ops. */
/* Version 4.0 23.04.97 Rewrite. Added bit shift and bool. matrix ops. */
/* Version 3.2 04.02.97 Added interval methods. */
/* Version 3.1 21.01.97 Fixed bug on 64 bit machines. */
/* Version 3.0 12.01.97 Added flip. */
Expand All @@ -270,7 +275,7 @@ void Matrix_Transpose (wordptr X, N_int rowsX, N_int colsX,
/* COPYRIGHT: */
/*****************************************************************************/
/* */
/* Copyright (c) 1995, 1996, 1997, 1998 by Steffen Beyer. */
/* Copyright (c) 1995, 1996, 1997, 1998, 1999 by Steffen Beyer. */
/* All rights reserved. */
/* */
/*****************************************************************************/
Expand Down
189 changes: 16 additions & 173 deletions CHANGES.txt
@@ -1,186 +1,29 @@
=====================================
Package "Bit::Vector" Version 5.6
Package "Bit::Vector" Version 5.7
=====================================


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


What's new in version 5.6:
--------------------------

The leading zeros in the output of "to_Hex()" have been suppressed.

A warning produced by some compilers on line 2067 of "BitVector.c" has been fixed.


Migration strategy to version 5.6:
----------------------------------

Step 1:
-------

If your application(s) still use(s) "Set::IntegerFast" version 3.x,
or if your application(s) still use(s) method names that are considered
deprecated since "Bit::Vector" version 4.0, you will have to upgrade to
"Bit::Vector" version 4.2 first by using the tool "upgrade_BV42.pl" from
the "tools" subdirectory in this distribution.

To do so, simply invoke this utility as follows:

> perl ./tools/upgrade_BV42.pl app1.pl app2.pl app3.pl ...
or
> perl .\tools\upgrade_BV42.pl app1.pl app2.pl app3.pl ...

Note that this utility renames the original file "app<i>.pl" to
"app<i>.pl.bak" before creating a fresh copy of this file (again
named "app<i>.pl"), and before applying any changes to that copy.

Be cautious to keep this backup copy (or better still, another copy
of the original file) in a safe place!

Beware that (at least under UNIX) this backup file will get overwritten
WITHOUT WARNING if you don't save it to a different place and if you run
the upgrade utility MORE THAN ONCE on the same application!

(Note though that running the upgrade utility more than once on the same
application is harmless as far as the RESULTING file is concerned.)

Beware also that this utility is not fool-proof:

It is theoretically impossible for a patch program such as this one,
which uses regular expressions to analyze your application(s), to handle
all possible cases correctly.

It would not only need to know about Perl syntax and how to parse it,
but it would also need to actually perform some of the Perl statements
(like "use") in order to know about methods that have been imported.

This is of course unfeasible, which is the reason why this utility can
only handle the most common cases.

Actually it might convert MORE than you might want; you will have to
either correct these cases manually after the conversion, or to adapt
the corresponding regular expressions to your special case beforehand.

The substitutions performed by this upgrade utility are the following:

Set::IntegerFast ==> Bit::Vector
use Bit::Vector 3.x ==> use Bit::Vector 4.2
= new Bit::Vector ==> = Bit::Vector->new
Empty_Interval ==> Interval_Empty
Fill_Interval ==> Interval_Fill
Flip_Interval ==> Interval_Flip
Delete ==> Bit_Off
Insert ==> Bit_On
flip ==> bit_flip
->in ==> ->contains
inclusion ==> subset

Step 2:
-------

To upgrade your application(s) from "Bit::Vector" version 4.x
to "Bit::Vector" version 5.6, simply issue the following command:

> perl ./tools/upgrade_BV56.pl app1.pl app2.pl app3.pl ...
or
> perl .\tools\upgrade_BV56.pl app1.pl app2.pl app3.pl ...

Note that this utility renames the original file "app<i>.pl" to
"app<i>.pl.bak" before creating a fresh copy of this file (again
named "app<i>.pl"), and before applying any changes to that copy.

Be cautious to keep this backup copy (or better still, another copy
of the original file) in a safe place!

Beware that (at least under UNIX) this backup file will get overwritten
WITHOUT WARNING if you don't save it to a different place and if you run
the upgrade utility MORE THAN ONCE on the same application!

(Note though that running the upgrade utility more than once on the same
application is harmless as far as the RESULTING file is concerned.)

Beware also that this utility is far from fool-proof:

For instance, method calls may not span over multiple lines, or
the upgrade utility will not work!

Moreover, the upgrade utility assumes that method calls use the
arrow ("->") -- other forms of method calls that are legal in Perl
are not supported.

Some examples of things this upgrade utility can't handle properly:

('10110110' + $vector1)->lexorder($vector2)

(The bit vector object for which the method is invoked (you could call
it the "lvalue" of the method call) must start with a dollar sign. This
means that "($vec1 + $vec2)->" instead of "('10110110' + $vector1)->"
would actually work, but this is not recommended, either. You always
risk parentheses at the wrong places after the upgrade. See below for
how to circumvent this problem!)

$vector[$index]->lexorder($vector[int($index/2)+1])

(Nested parentheses cannot be parsed with regular expressions.
Therefore, parentheses in the method's arguments cannot be
resolved properly, leading to parentheses in the wrong places
after the upgrade.)

You will need to fix these cases manually.

The best method for doing so is to simplify this kind of statement
BEFORE upgrading your application. A sure way to go is to store such
intermediate results in a temporary variable which is then used in
the method call.

For example:

$temp = '10110110' + $vector1;
$temp->lexorder($vector2)

$temp = int($index/2)+1;
$vector[$index]->lexorder($vector[$temp])

Note also that in most cases, the upgrade utility assumes that all
method calls have parentheses, even though this is not absolutely
required by Perl syntax.

Spaces before and after the method invocation arrow ("->") and between
the method name and the opening parenthesis are optional, though.

The substitutions performed by this upgrade utility are the following:

use Bit::Vector 4.x ==> use Bit::Vector 5.6
to_ASCII ==> to_Enum
from_ASCII ==> from_Enum
to_String ==> to_Hex
... ->from_string( ... ) ==> ( eval { ... ->from_Hex( ... ); !$@; } )
from_string ==> from_Hex
... ->lexorder( ... ) ==> ( ... ->Lexicompare( ... ) <= 0)
lexorder ==> Lexicompare
... = Bit::Vector->new_from_String( ... )
==>
... = Bit::Vector->new_Hex(length( ... ) << 2, ... )
new_from_String ==> new_Hex

Step 3:
-------

BEWARE that the semantics of the method "Compare()" have changed:

While previously it assumed its two bit vector arguments to be UNSIGNED,
it now assumes them to be SIGNED.

If you want to perform a comparison assuming UNSIGNED bit vectors, use
the new method "Lexicompare()" instead!


Version history:
----------------

Version 5.7 19.05.99

+ Improved method "Div_Pos()": It now uses only one instead of the
former two (very costly) "shift" operations in its main loop, and
it now depends on the (variable) length of the numbers involved rather
than the (constant) length of their respective bit vectors, making
this method tremendously faster now. The methods "to_Dec()", "Divide()"
and "GCD()" also profit from this change in the same way since they
rely crucially on the "Div_Pos()" method, internally.
+ Added a matrix multiplication method (for "Math::MatrixBool") named
"Product()" which determines paths in matrices representing graphs.
+ Fixed the problems with anchored error messages in the regression
test suite under MacPerl.

Version 5.6 02.11.98

+ Removed the leading zeros from the output of "to_Hex()".
Expand Down
4 changes: 2 additions & 2 deletions CREDITS.txt
@@ -1,9 +1,9 @@
=====================================
Package "Bit::Vector" Version 5.6
Package "Bit::Vector" Version 5.7
=====================================


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


Expand Down

0 comments on commit 5a5e593

Please sign in to comment.