| Bit-Vector documentation | view source | Contained in the Bit-Vector distribution. |
Bit::Vector::Overload - Overloaded operators add-on for Bit::Vector
Note that you do not need to "use Bit::Vector;"
in addition to this module.
Simply "use Bit::Vector::Overload;" INSTEAD
of "use Bit::Vector;". You can still use all the
methods from the "Bit::Vector" module in addition
to the overloaded operators and methods provided
here after that.
Configuration
$config = Bit::Vector->Configuration();
Bit::Vector->Configuration($config);
$oldconfig = Bit::Vector->Configuration($newconfig);
String Conversion
$string = "$vector"; # depending on configuration
print "\$vector = '$vector'\n";
Emptyness
if ($vector) # if not empty (non-zero)
if (! $vector) # if empty (zero)
unless ($vector) # if empty (zero)
Complement (one's complement)
$vector2 = ~$vector1;
$vector = ~$vector;
Negation (two's complement)
$vector2 = -$vector1;
$vector = -$vector;
Norm
$norm = abs($vector); # depending on configuration
Absolute
$vector2 = abs($vector1); # depending on configuration
Concatenation
$vector3 = $vector1 . $vector2;
$vector1 .= $vector2;
$vector1 = $vector2 . $vector1;
$vector2 = $vector1 . $scalar; # depending on configuration
$vector2 = $scalar . $vector1;
$vector .= $scalar;
Duplication
$vector2 = $vector1 x $factor;
$vector x= $factor;
Shift Left
$vector2 = $vector1 << $bits;
$vector <<= $bits;
Shift Right
$vector2 = $vector1 >> $bits;
$vector >>= $bits;
Union
$vector3 = $vector1 | $vector2;
$vector1 |= $vector2;
$vector2 = $vector1 | $scalar;
$vector |= $scalar;
$vector3 = $vector1 + $vector2; # depending on configuration
$vector1 += $vector2;
$vector2 = $vector1 + $scalar;
$vector += $scalar;
Intersection
$vector3 = $vector1 & $vector2;
$vector1 &= $vector2;
$vector2 = $vector1 & $scalar;
$vector &= $scalar;
$vector3 = $vector1 * $vector2; # depending on configuration
$vector1 *= $vector2;
$vector2 = $vector1 * $scalar;
$vector *= $scalar;
ExclusiveOr
$vector3 = $vector1 ^ $vector2;
$vector1 ^= $vector2;
$vector2 = $vector1 ^ $scalar;
$vector ^= $scalar;
Set Difference
$vector3 = $vector1 - $vector2; # depending on configuration
$vector1 -= $vector2;
$vector1 = $vector2 - $vector1;
$vector2 = $vector1 - $scalar;
$vector2 = $scalar - $vector1;
$vector -= $scalar;
Addition
$vector3 = $vector1 + $vector2; # depending on configuration
$vector1 += $vector2;
$vector2 = $vector1 + $scalar;
$vector += $scalar;
Subtraction
$vector3 = $vector1 - $vector2; # depending on configuration
$vector1 -= $vector2;
$vector1 = $vector2 - $vector1;
$vector2 = $vector1 - $scalar;
$vector2 = $scalar - $vector1;
$vector -= $scalar;
Multiplication
$vector3 = $vector1 * $vector2; # depending on configuration
$vector1 *= $vector2;
$vector2 = $vector1 * $scalar;
$vector *= $scalar;
Division
$vector3 = $vector1 / $vector2;
$vector1 /= $vector2;
$vector1 = $vector2 / $vector1;
$vector2 = $vector1 / $scalar;
$vector2 = $scalar / $vector1;
$vector /= $scalar;
Modulo
$vector3 = $vector1 % $vector2;
$vector1 %= $vector2;
$vector1 = $vector2 % $vector1;
$vector2 = $vector1 % $scalar;
$vector2 = $scalar % $vector1;
$vector %= $scalar;
Exponentiation
$vector3 = $vector1 ** $vector2;
$vector1 **= $vector2;
$vector2 = $vector1 ** $scalar;
$vector2 = $scalar ** $vector1;
$vector **= $scalar;
Increment
++$vector;
$vector++;
Decrement
--$vector;
$vector--;
Lexical Comparison (unsigned)
$cmp = $vector1 cmp $vector2;
if ($vector1 lt $vector2)
if ($vector1 le $vector2)
if ($vector1 gt $vector2)
if ($vector1 ge $vector2)
$cmp = $vector cmp $scalar;
if ($vector lt $scalar)
if ($vector le $scalar)
if ($vector gt $scalar)
if ($vector ge $scalar)
Comparison (signed)
$cmp = $vector1 <=> $vector2;
if ($vector1 < $vector2) # depending on configuration
if ($vector1 <= $vector2)
if ($vector1 > $vector2)
if ($vector1 >= $vector2)
$cmp = $vector <=> $scalar;
if ($vector < $scalar) # depending on configuration
if ($vector <= $scalar)
if ($vector > $scalar)
if ($vector >= $scalar)
Equality
if ($vector1 eq $vector2)
if ($vector1 ne $vector2)
if ($vector eq $scalar)
if ($vector ne $scalar)
if ($vector1 == $vector2)
if ($vector1 != $vector2)
if ($vector == $scalar)
if ($vector != $scalar)
Subset Relationship
if ($vector1 <= $vector2) # depending on configuration
True Subset Relationship
if ($vector1 < $vector2) # depending on configuration
Superset Relationship
if ($vector1 >= $vector2) # depending on configuration
True Superset Relationship
if ($vector1 > $vector2) # depending on configuration
0") for
"false" and a numeric one ("1") for "true". <<", ">>"
and "x" operators) and bit numbers are always regarded as being
UNSIGNED.
Configuration()" method (for more
details, see the description of this method further below).
from_Dec()")
in numeric form (i.e., either as a numeric constant or expression or as a
Perl variable containing a numeric value).
$vector /= 10; # ok because number is small
$vector /= -10; # ok for same reason
$vector /= "10"; # always correct
$vector += "1152921504606846976"; # quotes probably required here
Bit::Vector->Configuration("input=decimal");
0..9 and an optional leading sign ("+" or "-").
"$vector"
if ($vector)
if (!$vector)
~$vector
-$vector
abs($vector)
++$vector
$vector++
--$vector
$vector--
.=
x=
<<=
>>=
|=
&=
^=
+=
-=
*=
/=
%=
**=
<<",
">>" and "x", as well as their related assignment
variants, "<<=", ">>=" and "x=", the
left operand is ALWAYS a bit vector and the right operand is
ALWAYS a number (which is the factor indicating how many times
the operator is to be applied).
.
|
&
^
+
-
*
/
%
**
<=> cmp
== eq
!= ne
< lt
<= le
> gt
>= ge
.=
|=
&=
^=
+=
-=
*=
/=
%=
**=
-w"
switch of Perl.
input = bit indices (default) : numeric
input = hexadecimal : string
input = binary : string
input = decimal : string (in general)
input = decimal : numeric (if small enough)
input = enumeration : string
.") and its assignment variant (".="):
.") is
not a bit vector object but a Perl scalar, the contents of the remaining
bit vector operand are converted into a string (the format of which
depends on the configuration set with the "Configuration()" method),
which is then concatenated in the proper order (i.e., as indicated by the
order of the two operands) with the Perl scalar (in other words, a string
is returned in such a case instead of a bit vector object!).
.=") of the concatenation operator is a Perl scalar, it is converted
internally to a bit vector of the same size as the left side operand provided
that the configuration states that scalars are to be regarded as indices,
decimal strings or enumerations.
<<", ">>"
or "x" are reversed, a fatal "reversed operands error" occurs.
Concat()", "Concat_List()",
"Copy()", "Interval_Copy()" and "Interval_Substitute()", where no
conditions at all are imposed on the size of their bit vector arguments.
Multiply()", all three bit vector arguments must in principle
obey the rule of matching sizes, but the bit vector in which the result of
the multiplication is to be stored may be larger than the two bit vector
arguments containing the factors for the multiplication.
Power()", the bit vector for the result must be the same
size or greater than the base of the exponentiation term. The exponent
can be any size.
0" and
"$vector->Size()-1", or a fatal "index out of range"
error will occur.$config = Bit::Vector->Configuration(); Bit::Vector->Configuration($config); $oldconfig = Bit::Vector->Configuration($newconfig);
+ the way scalar operands (replacing one of the two
bit vector object operands) are automatically
converted internally into a bit vector object of
their own,
+ the operation certain overloaded operators perform,
i.e., an operation with sets or an arithmetic
operation,
+ the format to which bit vectors are converted
automatically when they are enclosed in double
quotes.
<which>=<value>".
<which>" and "<value>" thereby consist of letters
([a-zA-Z]) and white space.
<which>" has to contain one or more keywords from one of
three groups, each group representing one of the three aspects that
the "Configuration()" method controls:
+ "^scalar", "^input", "^in$"
+ "^operator", "^semantic", "^ops$"
+ "^string", "^output", "^out$"
<value>":
<which>",
there are different groups of keywords that determine the value
the selected aspect will be set to:
+ "<which>" = "^scalar", "^input", "^in$":
"<value>" =
* "^bit$", "^index", "^indice"
* "^hex"
* "^bin"
* "^dec"
* "^enum"
+ "<which>" = "^operator", "^semantic", "^ops$":
"<value>" =
* "^set$"
* "^arithmetic"
+ "<which>" = "^string", "^output", "^out$":
"<value>" =
* "^hex"
* "^bin"
* "^dec"
* "^enum"
"Any scalar input I provide should be considered to be = a bit index"
"I want to have operator semantics suitable for = arithmetics"
"Any bit vector in double quotes is to be output as = an enumeration"
^bit$", "^index", or "^indice"
all cause scalar input to be considered to represent a bit index, i.e.,
"$vector ^= 5;" will flip bit #5 in the given bit vector (this is
essentially the same as "$vector->bit_flip(5);").
^hex" will cause scalar input to be considered as being in
hexadecimal, i.e., "$vector ^= 5;" will flip bit #0 and bit #2 (because
hexadecimal "5" is binary "0101").
0-9 and decimal 0-9 are the same.)
^bin" will cause scalar input to be considered as being in
binary format. All characters except "0" and "1" are forbidden in
this case (i.e., produce a syntax error).
$vector ^= '0101';", for instance, will flip bit #0 and bit #2.
^dec" causes scalar input to be considered as integers
in decimal format, i.e., "$vector ^= 5;" will flip bit #0 and bit #2
(because decimal "5" is binary "0101").
^enum" causes scalar input to be considered
as being a list ("enumeration") of indices and ranges of (contiguous)
indices, i.e., "$vector |= '2,3,5,7-13,17-23';" will cause bits #2,
#3, #5, #7 through #13 and #17 through #23 to be set.
+", "-", "*", "<", "<=",
">" and ">=".
+ set union ( set1 u set2 ) - set difference ( set1 \ set2 ) * set intersection ( set1 n set2 ) < true subset relationship ( set1 < set2 ) <= subset relationship ( set1 <= set2 ) > true superset relationship ( set1 > set2 ) >= superset relationship ( set1 >= set2 )
+ addition ( num1 + num2 ) - subtraction ( num1 - num2 ) * multiplication ( num1 * num2 ) < "less than" comparison ( num1 < num2 ) <= "less than or equal" comparison ( num1 <= num2 ) > "greater than" comparison ( num1 > num2 ) >= "greater than or equal" comparison ( num1 >= num2 )
<", "<=",
">" and ">=") regard their operands as being SIGNED.
lt", "le", "gt" and "ge" instead (in contrast to the
operators above, these operators are NOT affected by the
"operator semantics" setting).
to_Hex()", "to_Bin()", "to_Dec()" and "to_Enum()"
(not counting "Block_Read()", since this method does not return a
human-readable string).
Chunk_List_Read()".)
print "\$vector = '$vector'\n"; $string = "$vector";
Configuration()"
is:
Scalar Input = Bit Index
Operator Semantics = Set Operators
String Output = Hexadecimal
Bit::Vector->Configuration("in=bin,ops=arithmetic,out=bin");
print Bit::Vector->Configuration(), "\n";
Scalar Input = Binary
Operator Semantics = Arithmetic Operators
String Output = Binary
Configuration()"
method to restore that setting later.
Bit::Vector->Configuration("operators = arithmetic");
"$vector"
to_Hex()", "to_Bin()",
"to_Dec()" and "to_Enum()"), it is of course desirable to
be able to choose which of these methods should be applied in this
case.
Configure()" (see the previous chapter,
immediately above).
if ($vector)
if (!$vector)
is_full()",
which returns true if ALL bits of the corresponding bit vector are
SET. ~$vector
-$vector (unary minus)
abs($vector)
Configuration()" for more details), this term either returns
the number of set bits in the given bit vector (this is the same
as calculating the number of elements which are contained in the
given set) - which is the default behaviour, or it returns a new
bit vector object which contains the absolute value of the number
stored in the given bit vector. $vector1 . $vector2
Configuration()" method), which is then concatenated in the proper
order (i.e., as indicated by the order of the two operands) with the Perl
scalar.
$vector x $factor
$vector << $bits
$bits",
specifies.
$bits" most significant bits are lost, all other
bits move up by "$bits" positions, and the "$bits" least significant
bits that have been left unoccupied by this shift are all set to zero.
$bits" is greater than the number of bits of the given bit vector,
this term returns an empty bit vector (i.e., with all bits cleared) of
the same size as the given bit vector.
$vector >> $bits
$bits",
specifies.
$bits" least significant bits are lost, all other
bits move down by "$bits" positions, and the "$bits" most significant
bits that have been left unoccupied by this shift are all set to zero.
$bits" is greater than the number of bits of the given bit vector,
this term returns an empty bit vector (i.e., with all bits cleared) of
the same size as the given bit vector.
$vector1 | $vector2
$vector1 & $vector2
$vector1 ^ $vector2
$vector1 + $vector2
Configuration()" for more details), this term either returns
a new bit vector object which is the result of a bitwise OR operation
between the two bit vector operands (this is the same as calculating
the union of two sets) - which is the default behaviour, or it returns
a new bit vector object which contains the sum of the two numbers
stored in the two bit vector operands. $vector1 - $vector2
Configuration()" for more details), this term either returns
a new bit vector object which is the set difference of the two sets
represented in the two bit vector operands - which is the default
behaviour, or it returns a new bit vector object which contains
the difference of the two numbers stored in the two bit vector
operands. $vector1 * $vector2
Configuration()" for more details), this term either returns
a new bit vector object which is the result of a bitwise AND operation
between the two bit vector operands (this is the same as calculating
the intersection of two sets) - which is the default behaviour, or it
returns a new bit vector object which contains the product of the two
numbers stored in the two bit vector operands. $vector1 / $vector2
$vector1 % $vector2
$vector1 ** $vector2
$vector1 .= $vector2;
$vector x= $factor;
$vector <<= $bits;
$bits"
positions (towards the most significant bit).
$bits" most significant bits are lost, all other
bits move up by "$bits" positions, and the "$bits" least significant
bits that have been left unoccupied by this shift are all set to zero.
$bits" is greater than the number of bits of the given bit vector,
the given bit vector is erased completely (i.e., all bits are cleared). $vector >>= $bits;
$bits"
positions (towards the least significant bit).
$bits" least significant bits are lost, all other
bits move down by "$bits" positions, and the "$bits" most significant
bits that have been left unoccupied by this shift are all set to zero.
$bits" is greater than the number of bits of the given bit vector,
the given bit vector is erased completely (i.e., all bits are cleared). $vector1 |= $vector2;
$vector1 &= $vector2;
$vector1 ^= $vector2;
$vector1 += $vector2;
Configuration()" for more details), this statement either performs
a bitwise OR operation between the two bit vector operands (this is
the same as calculating the union of two sets) - which is the default
behaviour, or it calculates the sum of the two numbers stored in the
two bit vector operands.
$vector1 -= $vector2;
Configuration()" for more details), this statement either calculates
the set difference of the two sets represented in the two bit vector
operands - which is the default behaviour, or it calculates the
difference of the two numbers stored in the two bit vector operands.
$vector1 *= $vector2;
Configuration()" for more details), this statement either performs
a bitwise AND operation between the two bit vector operands (this is
the same as calculating the intersection of two sets) - which is the
default behaviour, or it calculates the product of the two numbers
stored in the two bit vector operands.
$vector1 /= $vector2;
$vector1 %= $vector2;
$vector1 **= $vector2;
++$vector, $vector++
--$vector, $vector--
($vector1 cmp $vector2)
-1" if "$vector1" is less than "$vector2",
"0" if "$vector1" and "$vector2" are the same, and "1"
if "$vector1" is greater than "$vector2".
($vector1 eq $vector2)
1") if the contents of the two bit vector
operands are the same and false ("0") otherwise. ($vector1 ne $vector2)
1") if the two bit vector operands differ
and false ("0") otherwise. ($vector1 lt $vector2)
1") if "$vector1" is less than "$vector2",
and false ("0") otherwise.
($vector1 le $vector2)
1") if "$vector1" is less than or equal to
"$vector2", and false ("0") otherwise.
($vector1 gt $vector2)
1") if "$vector1" is greater than "$vector2",
and false ("0") otherwise.
($vector1 ge $vector2)
1") if "$vector1" is greater than or equal to
"$vector2", and false ("0") otherwise.
($vector1 <=> $vector2)
-1" if "$vector1" is less than "$vector2",
"0" if "$vector1" and "$vector2" are the same, and "1"
if "$vector1" is greater than "$vector2".
($vector1 == $vector2)
1") if the contents of the two bit vector
operands are the same and false ("0") otherwise. ($vector1 != $vector2)
1") if the two bit vector operands differ
and false ("0") otherwise. ($vector1 < $vector2)
Configuration()" for more details), this term either returns
true ("1") if "$vector1" is a true subset of "$vector2"
(and false ("0") otherwise) - which is the default behaviour,
or it returns true ("1") if "$vector1" is less than
"$vector2" (and false ("0") otherwise).
($vector1 <= $vector2)
Configuration()" for more details), this term either returns
true ("1") if "$vector1" is a subset of "$vector2" (and
false ("0") otherwise) - which is the default behaviour, or it
returns true ("1") if "$vector1" is less than or equal to
"$vector2" (and false ("0") otherwise).
($vector1 > $vector2)
Configuration()" for more details), this term either returns
true ("1") if "$vector1" is a true superset of "$vector2"
(and false ("0") otherwise) - which is the default behaviour,
or it returns true ("1") if "$vector1" is greater than
"$vector2" (and false ("0") otherwise).
($vector1 >= $vector2)
Configuration()" for more details), this term either returns
true ("1") if "$vector1" is a superset of "$vector2" (and
false ("0") otherwise) - which is the default behaviour, or it
returns true ("1") if "$vector1" is greater than or equal to
"$vector2" (and false ("0") otherwise).
Bit::Vector(3), Bit::Vector::String(3).
This man page documents "Bit::Vector::Overload" version 7.1.
Steffen Beyer mailto:STBEY@cpan.org http://www.engelschall.com/u/sb/download/
Copyright (c) 2000 - 2009 by Steffen Beyer. All rights reserved.
This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".
The C library at the core of this Perl module can additionally be redistributed and/or modified under the terms of the "GNU Library General Public License".
Please refer to the files "Artistic.txt", "GNU_GPL.txt" and "GNU_LGPL.txt" in this distribution for details!
This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the "GNU General Public License" for more details.
| Bit-Vector documentation | view source | Contained in the Bit-Vector distribution. |