home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Vector.pod < prev    next >
Encoding:
Text File  |  2002-09-28  |  98.5 KB  |  3,100 lines

  1.  
  2. =head1 NAME
  3.  
  4. Bit::Vector - Efficient bit vector, set of integers and "big int" math library
  5.  
  6. =head1 SYNOPSIS
  7.  
  8. =head2 OVERLOADED OPERATORS
  9.  
  10. See L<Bit::Vector::Overload(3)>.
  11.  
  12. =head2 CLASS METHODS
  13.  
  14.   Version
  15.       $version = Bit::Vector->Version();
  16.  
  17.   Word_Bits
  18.       $bits = Bit::Vector->Word_Bits();  #  bits in a machine word
  19.  
  20.   Long_Bits
  21.       $bits = Bit::Vector->Long_Bits();  #  bits in an unsigned long
  22.  
  23.   new
  24.       $vector = Bit::Vector->new($bits);  #  bit vector constructor
  25.  
  26.       @veclist = Bit::Vector->new($bits,$count);
  27.  
  28.   new_Hex
  29.       $vector = Bit::Vector->new_Hex($bits,$string);
  30.  
  31.   new_Bin
  32.       $vector = Bit::Vector->new_Bin($bits,$string);
  33.  
  34.   new_Dec
  35.       $vector = Bit::Vector->new_Dec($bits,$string);
  36.  
  37.   new_Enum
  38.       $vector = Bit::Vector->new_Enum($bits,$string);
  39.  
  40.   Concat_List
  41.       $vector = Bit::Vector->Concat_List(@vectors);
  42.  
  43. =head2 OBJECT METHODS
  44.  
  45.   new
  46.       $vec2 = $vec1->new($bits);  #  alternative call of constructor
  47.  
  48.       @veclist = $vec->new($bits,$count);
  49.  
  50.   Shadow
  51.       $vec2 = $vec1->Shadow();  #  new vector, same size but empty
  52.  
  53.   Clone
  54.       $vec2 = $vec1->Clone();  #  new vector, exact duplicate
  55.  
  56.   Concat
  57.       $vector = $vec1->Concat($vec2);
  58.  
  59.   Concat_List
  60.       $vector = $vec1->Concat_List($vec2,$vec3,...);
  61.  
  62.   Size
  63.       $bits = $vector->Size();
  64.  
  65.   Resize
  66.       $vector->Resize($bits);
  67.       $vector->Resize($vector->Size()+5);
  68.       $vector->Resize($vector->Size()-5);
  69.  
  70.   Copy
  71.       $vec2->Copy($vec1);
  72.  
  73.   Empty
  74.       $vector->Empty();
  75.  
  76.   Fill
  77.       $vector->Fill();
  78.  
  79.   Flip
  80.       $vector->Flip();
  81.  
  82.   Primes
  83.       $vector->Primes();  #  Sieve of Erathostenes
  84.  
  85.   Reverse
  86.       $vec2->Reverse($vec1);
  87.  
  88.   Interval_Empty
  89.       $vector->Interval_Empty($min,$max);
  90.  
  91.   Interval_Fill
  92.       $vector->Interval_Fill($min,$max);
  93.  
  94.   Interval_Flip
  95.       $vector->Interval_Flip($min,$max);
  96.  
  97.   Interval_Reverse
  98.       $vector->Interval_Reverse($min,$max);
  99.  
  100.   Interval_Scan_inc
  101.       if (($min,$max) = $vector->Interval_Scan_inc($start))
  102.  
  103.   Interval_Scan_dec
  104.       if (($min,$max) = $vector->Interval_Scan_dec($start))
  105.  
  106.   Interval_Copy
  107.       $vec2->Interval_Copy($vec1,$offset2,$offset1,$length);
  108.  
  109.   Interval_Substitute
  110.       $vec2->Interval_Substitute($vec1,$off2,$len2,$off1,$len1);
  111.  
  112.   is_empty
  113.       if ($vector->is_empty())
  114.  
  115.   is_full
  116.       if ($vector->is_full())
  117.  
  118.   equal
  119.       if ($vec1->equal($vec2))
  120.  
  121.   Lexicompare (unsigned)
  122.       if ($vec1->Lexicompare($vec2) == 0)
  123.       if ($vec1->Lexicompare($vec2) != 0)
  124.       if ($vec1->Lexicompare($vec2) <  0)
  125.       if ($vec1->Lexicompare($vec2) <= 0)
  126.       if ($vec1->Lexicompare($vec2) >  0)
  127.       if ($vec1->Lexicompare($vec2) >= 0)
  128.  
  129.   Compare (signed)
  130.       if ($vec1->Compare($vec2) == 0)
  131.       if ($vec1->Compare($vec2) != 0)
  132.       if ($vec1->Compare($vec2) <  0)
  133.       if ($vec1->Compare($vec2) <= 0)
  134.       if ($vec1->Compare($vec2) >  0)
  135.       if ($vec1->Compare($vec2) >= 0)
  136.  
  137.   to_Hex
  138.       $string = $vector->to_Hex();
  139.  
  140.   from_Hex
  141.       $vector->from_Hex($string);
  142.  
  143.   to_Bin
  144.       $string = $vector->to_Bin();
  145.  
  146.   from_Bin
  147.       $vector->from_Bin($string);
  148.  
  149.   to_Dec
  150.       $string = $vector->to_Dec();
  151.  
  152.   from_Dec
  153.       $vector->from_Dec($string);
  154.  
  155.   to_Enum
  156.       $string = $vector->to_Enum();  #  e.g. "2,3,5-7,11,13-19"
  157.  
  158.   from_Enum
  159.       $vector->from_Enum($string);
  160.  
  161.   Bit_Off
  162.       $vector->Bit_Off($index);
  163.  
  164.   Bit_On
  165.       $vector->Bit_On($index);
  166.  
  167.   bit_flip
  168.       $bit = $vector->bit_flip($index);
  169.  
  170.   bit_test
  171.   contains
  172.       $bit = $vector->bit_test($index);
  173.       $bit = $vector->contains($index);
  174.       if ($vector->bit_test($index))
  175.       if ($vector->contains($index))
  176.  
  177.   Bit_Copy
  178.       $vector->Bit_Copy($index,$bit);
  179.  
  180.   LSB (least significant bit)
  181.       $vector->LSB($bit);
  182.  
  183.   MSB (most significant bit)
  184.       $vector->MSB($bit);
  185.  
  186.   lsb (least significant bit)
  187.       $bit = $vector->lsb();
  188.  
  189.   msb (most significant bit)
  190.       $bit = $vector->msb();
  191.  
  192.   rotate_left
  193.       $carry = $vector->rotate_left();
  194.  
  195.   rotate_right
  196.       $carry = $vector->rotate_right();
  197.  
  198.   shift_left
  199.       $carry = $vector->shift_left($carry);
  200.  
  201.   shift_right
  202.       $carry = $vector->shift_right($carry);
  203.  
  204.   Move_Left
  205.       $vector->Move_Left($bits);  #  shift left "$bits" positions
  206.  
  207.   Move_Right
  208.       $vector->Move_Right($bits);  #  shift right "$bits" positions
  209.  
  210.   Insert
  211.       $vector->Insert($offset,$bits);
  212.  
  213.   Delete
  214.       $vector->Delete($offset,$bits);
  215.  
  216.   increment
  217.       $carry = $vector->increment();
  218.  
  219.   decrement
  220.       $carry = $vector->decrement();
  221.  
  222.   inc
  223.       $overflow = $vec2->inc($vec1);
  224.  
  225.   dec
  226.       $overflow = $vec2->dec($vec1);
  227.  
  228.   add
  229.       $carry = $vec3->add($vec1,$vec2,$carry);
  230.       ($carry,$overflow) = $vec3->add($vec1,$vec2,$carry);
  231.  
  232.   subtract
  233.       $carry = $vec3->subtract($vec1,$vec2,$carry);
  234.       ($carry,$overflow) = $vec3->subtract($vec1,$vec2,$carry);
  235.  
  236.   Neg
  237.   Negate
  238.       $vec2->Neg($vec1);
  239.       $vec2->Negate($vec1);
  240.  
  241.   Abs
  242.   Absolute
  243.       $vec2->Abs($vec1);
  244.       $vec2->Absolute($vec1);
  245.  
  246.   Sign
  247.       if ($vector->Sign() == 0)
  248.       if ($vector->Sign() != 0)
  249.       if ($vector->Sign() <  0)
  250.       if ($vector->Sign() <= 0)
  251.       if ($vector->Sign() >  0)
  252.       if ($vector->Sign() >= 0)
  253.  
  254.   Multiply
  255.       $vec3->Multiply($vec1,$vec2);
  256.  
  257.   Divide
  258.       $quot->Divide($vec1,$vec2,$rest);
  259.  
  260.   GCD (Greatest Common Divisor)
  261.       $vecgcd->GCD($veca,$vecb);
  262.       $vecgcd->GCD($vecx,$vecy,$veca,$vecb);
  263.  
  264.   Power
  265.       $vec3->Power($vec1,$vec2);
  266.  
  267.   Block_Store
  268.       $vector->Block_Store($buffer);
  269.  
  270.   Block_Read
  271.       $buffer = $vector->Block_Read();
  272.  
  273.   Word_Size
  274.       $size = $vector->Word_Size();  #  number of words in "$vector"
  275.  
  276.   Word_Store
  277.       $vector->Word_Store($offset,$word);
  278.  
  279.   Word_Read
  280.       $word = $vector->Word_Read($offset);
  281.  
  282.   Word_List_Store
  283.       $vector->Word_List_Store(@words);
  284.  
  285.   Word_List_Read
  286.       @words = $vector->Word_List_Read();
  287.  
  288.   Word_Insert
  289.       $vector->Word_Insert($offset,$count);
  290.  
  291.   Word_Delete
  292.       $vector->Word_Delete($offset,$count);
  293.  
  294.   Chunk_Store
  295.       $vector->Chunk_Store($chunksize,$offset,$chunk);
  296.  
  297.   Chunk_Read
  298.       $chunk = $vector->Chunk_Read($chunksize,$offset);
  299.  
  300.   Chunk_List_Store
  301.       $vector->Chunk_List_Store($chunksize,@chunks);
  302.  
  303.   Chunk_List_Read
  304.       @chunks = $vector->Chunk_List_Read($chunksize);
  305.  
  306.   Index_List_Remove
  307.       $vector->Index_List_Remove(@indices);
  308.  
  309.   Index_List_Store
  310.       $vector->Index_List_Store(@indices);
  311.  
  312.   Index_List_Read
  313.       @indices = $vector->Index_List_Read();
  314.  
  315.   Or
  316.   Union
  317.       $vec3->Or($vec1,$vec2);
  318.       $set3->Union($set1,$set2);
  319.  
  320.   And
  321.   Intersection
  322.       $vec3->And($vec1,$vec2);
  323.       $set3->Intersection($set1,$set2);
  324.  
  325.   AndNot
  326.   Difference
  327.       $vec3->AndNot($vec1,$vec2);
  328.       $set3->Difference($set1,$set2);
  329.  
  330.   Xor
  331.   ExclusiveOr
  332.       $vec3->Xor($vec1,$vec2);
  333.       $set3->ExclusiveOr($set1,$set2);
  334.  
  335.   Not
  336.   Complement
  337.       $vec2->Not($vec1);
  338.       $set2->Complement($set1);
  339.  
  340.   subset
  341.       if ($set1->subset($set2))  #  true if $set1 is subset of $set2
  342.  
  343.   Norm
  344.       $norm = $set->Norm();
  345.  
  346.   Min
  347.       $min = $set->Min();
  348.  
  349.   Max
  350.       $max = $set->Max();
  351.  
  352.   Multiplication
  353.       $matrix3->Multiplication($rows3,$cols3,
  354.                       $matrix1,$rows1,$cols1,
  355.                       $matrix2,$rows2,$cols2);
  356.  
  357.   Product
  358.       $matrix3->Product($rows3,$cols3,
  359.                $matrix1,$rows1,$cols1,
  360.                $matrix2,$rows2,$cols2);
  361.  
  362.   Closure
  363.       $matrix->Closure($rows,$cols);
  364.  
  365.   Transpose
  366.       $matrix2->Transpose($rows2,$cols2,$matrix1,$rows1,$cols1);
  367.  
  368. =head1 IMPORTANT NOTES
  369.  
  370. =over 2
  371.  
  372. =item *
  373.  
  374. Method naming conventions
  375.  
  376. Method names completely in lower case indicate a boolean return value.
  377.  
  378. (Except for the bit vector constructor method "C<new()>", of course.)
  379.  
  380. =item *
  381.  
  382. Boolean values
  383.  
  384. Boolean values in this module are always a numeric zero ("C<0>") for
  385. "false" and a numeric one ("C<1>") for "true".
  386.  
  387. =item *
  388.  
  389. Negative numbers
  390.  
  391. All numeric input parameters passed to any of the methods in this module
  392. are regarded as being B<UNSIGNED> (as opposed to the contents of the
  393. bit vectors themselves, which are usually considered to be B<SIGNED>).
  394.  
  395. As a consequence, whenever you pass a negative number as an argument to
  396. some method of this module, it will be treated as a (usually very large)
  397. positive number due to its internal two's complement binary representation,
  398. usually resulting in an "index out of range" error message and program
  399. abortion.
  400.  
  401. =item *
  402.  
  403. Bit order
  404.  
  405. Note that bit vectors are stored least order bit and least order word first
  406. internally.
  407.  
  408. I.e., bit #0 of any given bit vector corresponds to bit #0 of word #0 in the
  409. array of machine words representing the bit vector.
  410.  
  411. (Where word #0 comes first in memory, i.e., it is stored at the least memory
  412. address in the allocated block of memory holding the given bit vector.)
  413.  
  414. Note however that machine words can be stored least order byte first or last,
  415. depending on your system's implementation.
  416.  
  417. When you are exporting or importing a whole bit vector at once using the
  418. methods "C<Block_Read()>" and "C<Block_Store()>" (the only time in this
  419. module where this could make any difference), however, a conversion to and
  420. from "least order byte first" order is automatically supplied.
  421.  
  422. In other words, what "C<Block_Read()>" provides and what "C<Block_Store()>"
  423. expects is always in "least order byte first" order, regardless of the order
  424. in which words are stored internally on your machine.
  425.  
  426. This is to make sure that what you export on one machine using "C<Block_Read()>"
  427. can always be read in correctly with "C<Block_Store()>" on a different machine.
  428.  
  429. Note further that whenever bit vectors are converted to and from (binary or
  430. hexadecimal) strings, the B<RIGHTMOST> bit is always the B<LEAST SIGNIFICANT>
  431. one, and the B<LEFTMOST> bit is always the B<MOST SIGNIFICANT> bit.
  432.  
  433. This is because in our western culture, numbers are always represented in this
  434. way (least significant to most significant digits go from right to left).
  435.  
  436. Of course this requires an internal reversion of order, which the corresponding
  437. conversion methods perform automatically (without any additional overhead, it's
  438. just a matter of starting the internal loop at the bottom or the top end).
  439.  
  440. =item *
  441.  
  442. "Word" related methods
  443.  
  444. Note that all methods whose names begin with "C<Word_>" are
  445. B<MACHINE-DEPENDENT>!
  446.  
  447. They depend on the size (number of bits) of an "unsigned int" (C type) on
  448. your machine.
  449.  
  450. Therefore, you should only use these methods if you are B<ABSOLUTELY CERTAIN>
  451. that portability of your code is not an issue!
  452.  
  453. Note that you can use arbitrarily large chunks (i.e., fragments of bit vectors)
  454. of up to 32 bits B<IN A PORTABLE WAY> using the methods whose names begin with
  455. "C<Chunk_>".
  456.  
  457. =item *
  458.  
  459. Chunk sizes
  460.  
  461. Note that legal chunk sizes for all methods whose names begin with "C<Chunk_>"
  462. range from "C<1>" to "C<Bit::Vector-E<gt>Long_Bits();>" bits ("C<0>" is B<NOT>
  463. allowed!).
  464.  
  465. In order to make your programs portable, however, you shouldn't use chunk sizes
  466. larger than 32 bits, since this is the minimum size of an "unsigned long"
  467. (C type) on all systems, as prescribed by S<ANSI C>.
  468.  
  469. =item *
  470.  
  471. Matching sizes
  472.  
  473. In general, for methods involving several bit vectors at the same time, all
  474. bit vector arguments must have identical sizes (number of bits), or a fatal
  475. "size mismatch" error will occur.
  476.  
  477. Exceptions from this rule are the methods "C<Concat()>", "C<Concat_List()>",
  478. "C<Copy()>", "C<Interval_Copy()>" and "C<Interval_Substitute()>", where no
  479. conditions at all are imposed on the size of their bit vector arguments.
  480.  
  481. In method "C<Multiply()>", all three bit vector arguments must in principle
  482. obey the rule of matching sizes, but the bit vector in which the result of
  483. the multiplication is to be stored may be larger than the two bit vector
  484. arguments containing the factors for the multiplication.
  485.  
  486. In method "C<Power()>", the bit vector for the result must be the same
  487. size or greater than the base of the exponentiation term. The exponent
  488. can be any size.
  489.  
  490. =item *
  491.  
  492. Index ranges
  493.  
  494. All indices for any given bits must lie between "C<0>" and
  495. "C<$vector-E<gt>Size()-1>", or a fatal "index out of range"
  496. error will occur.
  497.  
  498. =back
  499.  
  500. =head1 DESCRIPTION
  501.  
  502. =head2 OVERLOADED OPERATORS
  503.  
  504. See L<Bit::Vector::Overload(3)>.
  505.  
  506. =head2 CLASS METHODS
  507.  
  508. =over 2
  509.  
  510. =item *
  511.  
  512. C<$version = Bit::Vector-E<gt>Version();>
  513.  
  514. Returns the current version number of this module.
  515.  
  516. =item *
  517.  
  518. C<$bits = Bit::Vector-E<gt>Word_Bits();>
  519.  
  520. Returns the number of bits of an "unsigned int" (C type)
  521. on your machine.
  522.  
  523. (An "unsigned int" is also called a "machine word",
  524. hence the name of this method.)
  525.  
  526. =item *
  527.  
  528. C<$bits = Bit::Vector-E<gt>Long_Bits();>
  529.  
  530. Returns the number of bits of an "unsigned long" (C type)
  531. on your machine.
  532.  
  533. =item *
  534.  
  535. C<$vector = Bit::Vector-E<gt>new($bits);>
  536.  
  537. This is the bit vector constructor method.
  538.  
  539. Call this method to create a new bit vector containing "C<$bits>"
  540. bits (with indices ranging from "C<0>" to "C<$bits-1>").
  541.  
  542. Note that - in contrast to previous versions - bit vectors
  543. of length zero (i.e., with C<$bits = 0>) are permitted now.
  544.  
  545. The method returns a reference to the newly created bit vector.
  546.  
  547. A new bit vector is always initialized so that all bits are cleared
  548. (turned off).
  549.  
  550. An exception will be raised if the method is unable to allocate the
  551. necessary memory.
  552.  
  553. Note that if you specify a negative number for "C<$bits>" it will be
  554. interpreted as a large positive number due to its internal two's
  555. complement binary representation.
  556.  
  557. In such a case, the bit vector constructor method will obediently attempt
  558. to create a bit vector of that size, probably resulting in an exception,
  559. as explained above.
  560.  
  561. =item *
  562.  
  563. C<@veclist = Bit::Vector-E<gt>new($bits,$count);>
  564.  
  565. You can also create more than one bit vector at a time if you specify the
  566. optional second parameter "C<$count>".
  567.  
  568. The method returns a list of "C<$count>" bit vectors which all have the
  569. same number of bits "C<$bits>" (and which are all initialized, i.e.,
  570. all bits are cleared).
  571.  
  572. If "C<$count>" is zero, an empty list is returned.
  573.  
  574. If "C<$bits>" is zero, a list of null-sized bit vectors is returned.
  575.  
  576. Note again that if you specify a negative number for "C<$count>" it will
  577. be interpreted as a large positive number due to its internal two's
  578. complement binary representation.
  579.  
  580. In such a case, the bit vector constructor method will obediently attempt
  581. to create that many bit vectors, probably resulting in an exception ("out
  582. of memory").
  583.  
  584. =item *
  585.  
  586. C<$vector = Bit::Vector-E<gt>new_Hex($bits,$string);>
  587.  
  588. This method is an alternative constructor which allows you to create
  589. a new bit vector object (with "C<$bits>" bits) and to initialize it
  590. all in one go.
  591.  
  592. The method is more efficient than performing these two steps separately
  593. first because in this method, the memory area occupied by the new bit
  594. vector is not initialized to zeros (which is pointless in this case),
  595. and second because it saves you from the associated overhead of one
  596. additional method invocation.
  597.  
  598. The method first calls the bit vector constructor method "C<new()>"
  599. internally, and then passes the given string to the method "C<from_Hex()>".
  600.  
  601. An exception will be raised if the necessary memory cannot be allocated
  602. (see the description of the method "C<new()>" immediately above for
  603. possible causes) or if the given string cannot be converted successfully
  604. (see the description of the method "C<from_Hex()>" further below for
  605. details).
  606.  
  607. In the latter case, the memory occupied by the new bit vector is
  608. released first (i.e., "free"d) before the exception is actually
  609. raised.
  610.  
  611. =item *
  612.  
  613. C<$vector = Bit::Vector-E<gt>new_Bin($bits,$string);>
  614.  
  615. This method is an alternative constructor which allows you to create
  616. a new bit vector object (with "C<$bits>" bits) and to initialize it
  617. all in one go.
  618.  
  619. The method is more efficient than performing these two steps separately
  620. first because in this method, the memory area occupied by the new bit
  621. vector is not initialized to zeros (which is pointless in this case),
  622. and second because it saves you from the associated overhead of one
  623. additional method invocation.
  624.  
  625. The method first calls the bit vector constructor method "C<new()>"
  626. internally, and then passes the given string to the method "C<from_Bin()>".
  627.  
  628. An exception will be raised if the necessary memory cannot be allocated
  629. (see the description of the method "C<new()>" above for possible causes)
  630. or if the given string cannot be converted successfully (see the
  631. description of the method "C<from_Bin()>" further below for details).
  632.  
  633. In the latter case, the memory occupied by the new bit vector is
  634. released first (i.e., "free"d) before the exception is actually
  635. raised.
  636.  
  637. =item *
  638.  
  639. C<$vector = Bit::Vector-E<gt>new_Dec($bits,$string);>
  640.  
  641. This method is an alternative constructor which allows you to create
  642. a new bit vector object (with "C<$bits>" bits) and to initialize it
  643. all in one go.
  644.  
  645. The method is more efficient than performing these two steps separately
  646. first because in this method, the memory area occupied by the new bit
  647. vector is not initialized to zeros (which is pointless in this case),
  648. and second because it saves you from the associated overhead of one
  649. additional method invocation.
  650.  
  651. The method first calls the bit vector constructor method "C<new()>"
  652. internally, and then passes the given string to the method "C<from_Dec()>".
  653.  
  654. An exception will be raised if the necessary memory cannot be allocated
  655. (see the description of the method "C<new()>" above for possible causes)
  656. or if the given string cannot be converted successfully (see the
  657. description of the method "C<from_Dec()>" further below for details).
  658.  
  659. In the latter case, the memory occupied by the new bit vector is
  660. released first (i.e., "free"d) before the exception is actually
  661. raised.
  662.  
  663. =item *
  664.  
  665. C<$vector = Bit::Vector-E<gt>new_Enum($bits,$string);>
  666.  
  667. This method is an alternative constructor which allows you to create
  668. a new bit vector object (with "C<$bits>" bits) and to initialize it
  669. all in one go.
  670.  
  671. The method is more efficient than performing these two steps separately
  672. first because in this method, the memory area occupied by the new bit
  673. vector is not initialized to zeros (which is pointless in this case),
  674. and second because it saves you from the associated overhead of one
  675. additional method invocation.
  676.  
  677. The method first calls the bit vector constructor method "C<new()>"
  678. internally, and then passes the given string to the method "C<from_Enum()>".
  679.  
  680. An exception will be raised if the necessary memory cannot be allocated
  681. (see the description of the method "C<new()>" above for possible causes)
  682. or if the given string cannot be converted successfully (see the
  683. description of the method "C<from_Enum()>" further below for details).
  684.  
  685. In the latter case, the memory occupied by the new bit vector is
  686. released first (i.e., "free"d) before the exception is actually
  687. raised.
  688.  
  689. =item *
  690.  
  691. C<$vector = Bit::Vector-E<gt>Concat_List(@vectors);>
  692.  
  693. This method creates a new vector containing all bit vectors from the
  694. argument list in concatenated form.
  695.  
  696. The argument list may contain any number of arguments (including
  697. zero); the only condition is that all arguments must be bit vectors.
  698.  
  699. There is no condition concerning the length (in number of bits) of
  700. these arguments.
  701.  
  702. The vectors from the argument list are not changed in any way.
  703.  
  704. If the argument list is empty or if all arguments have length zero,
  705. the resulting bit vector will also have length zero.
  706.  
  707. Note that the B<RIGHTMOST> bit vector from the argument list will
  708. become the B<LEAST> significant part of the resulting bit vector,
  709. and the B<LEFTMOST> bit vector from the argument list will
  710. become the B<MOST> significant part of the resulting bit vector.
  711.  
  712. =back
  713.  
  714. =head2 OBJECT METHODS
  715.  
  716. =over 2
  717.  
  718. =item *
  719.  
  720. C<$vec2 = $vec1-E<gt>new($bits);>
  721.  
  722. C<@veclist = $vec-E<gt>new($bits);>
  723.  
  724. This is an alternative way of calling the bit vector constructor method.
  725.  
  726. Vector "C<$vec1>" (or "C<$vec>") is not affected by this, it just serves
  727. as an anchor for the method invocation mechanism.
  728.  
  729. In fact B<ALL> class methods in this module can be called this way,
  730. even though this is probably considered to be "politically incorrect"
  731. by OO ("object-orientation") aficionados. ;-)
  732.  
  733. So even if you are too lazy to type "C<Bit::Vector-E<gt>>" instead of
  734. "C<$vec1-E<gt>>" (and even though laziness is - allegedly - a programmer's
  735. virtue C<:-)>), maybe it is better not to use this feature if you don't
  736. want to get booed at. ;-)
  737.  
  738. =item *
  739.  
  740. C<$vec2 = $vec1-E<gt>Shadow();>
  741.  
  742. Creates a B<NEW> bit vector "C<$vec2>" of the B<SAME SIZE> as "C<$vec1>"
  743. but which is B<EMPTY>.
  744.  
  745. Just like a shadow that has the same shape as the object it
  746. originates from, but is flat and has no volume, i.e., contains
  747. nothing.
  748.  
  749. =item *
  750.  
  751. C<$vec2 = $vec1-E<gt>Clone();>
  752.  
  753. Creates a B<NEW> bit vector "C<$vec2>" of the B<SAME SIZE> as "C<$vec1>"
  754. which is an B<EXACT COPY> of "C<$vec1>".
  755.  
  756. =item *
  757.  
  758. C<$vector = $vec1-E<gt>Concat($vec2);>
  759.  
  760. This method returns a new bit vector object which is the result of the
  761. concatenation of the contents of "C<$vec1>" and "C<$vec2>".
  762.  
  763. Note that the contents of "C<$vec1>" become the B<MOST> significant part
  764. of the resulting bit vector, and "C<$vec2>" the B<LEAST> significant part.
  765.  
  766. If both bit vector arguments have length zero, the resulting bit vector
  767. will also have length zero.
  768.  
  769. =item *
  770.  
  771. C<$vector = $vec1-E<gt>Concat_List($vec2,$vec3,...);>
  772.  
  773. This is an alternative way of calling this (class) method as an
  774. object method.
  775.  
  776. The method returns a new bit vector object which is the result of
  777. the concatenation of the contents of C<$vec1 . $vec2 . $vec3 . ...>
  778.  
  779. See the section "class methods" above for a detailed description of
  780. this method.
  781.  
  782. Note that the argument list may be empty and that all arguments
  783. must be bit vectors if it isn't.
  784.  
  785. =item *
  786.  
  787. C<$bits = $vector-E<gt>Size();>
  788.  
  789. Returns the size (number of bits) the given vector was created with
  790. (or "C<Resize()>"d to).
  791.  
  792. =item *
  793.  
  794. C<$vector-E<gt>Resize($bits);>
  795.  
  796. Changes the size of the given vector to the specified number of bits.
  797.  
  798. This method allows you to change the size of an existing bit vector,
  799. preserving as many bits from the old vector as will fit into the
  800. new one (i.e., all bits with indices smaller than the minimum of the
  801. sizes of both vectors, old and new).
  802.  
  803. If the number of machine words needed to store the new vector is smaller
  804. than or equal to the number of words needed to store the old vector, the
  805. memory allocated for the old vector is reused for the new one, and only
  806. the relevant book-keeping information is adjusted accordingly.
  807.  
  808. This means that even if the number of bits increases, new memory is not
  809. necessarily being allocated (i.e., if the old and the new number of bits
  810. fit into the same number of machine words).
  811.  
  812. If the number of machine words needed to store the new vector is greater
  813. than the number of words needed to store the old vector, new memory is
  814. allocated for the new vector, the old vector is copied to the new one,
  815. the remaining bits in the new vector are cleared (turned off) and the old
  816. vector is deleted, i.e., the memory that was allocated for it is released.
  817.  
  818. (An exception will be raised if the method is unable to allocate the
  819. necessary memory for the new vector.)
  820.  
  821. As a consequence, if you decrease the size of a given vector so that
  822. it will use fewer machine words, and increase it again later so that it
  823. will use more words than immediately before but still less than the
  824. original vector, new memory will be allocated anyway because the
  825. information about the size of the original vector is lost whenever
  826. you resize it.
  827.  
  828. Note also that if you specify a negative number for "C<$bits>" it will
  829. be interpreted as a large positive number due to its internal two's
  830. complement binary representation.
  831.  
  832. In such a case, "Resize()" will obediently attempt to create a bit
  833. vector of that size, probably resulting in an exception, as explained
  834. above.
  835.  
  836. Finally, note that - in contrast to previous versions - resizing a bit
  837. vector to a size of zero bits (length zero) is now permitted.
  838.  
  839. =item *
  840.  
  841. C<$vec2-E<gt>Copy($vec1);>
  842.  
  843. Copies the contents of bit vector "C<$vec1>" to bit vector "C<$vec2>".
  844.  
  845. The previous contents of bit vector "C<$vec2>" get overwritten, i.e.,
  846. are lost.
  847.  
  848. Both vectors must exist beforehand, i.e., this method does not B<CREATE>
  849. any new bit vector object.
  850.  
  851. The two vectors may be of any size.
  852.  
  853. If the source bit vector is larger than the target, this method will copy
  854. as much of the least significant bits of the source vector as will fit into
  855. the target vector, thereby discarding any extraneous most significant bits.
  856.  
  857. BEWARE that this causes a brutal cutoff in the middle of your data, and it
  858. will also leave you with an almost unpredictable sign if subsequently the
  859. number in the target vector is going to be interpreted as a number! (You
  860. have been warned!)
  861.  
  862. If the target bit vector is larger than the source, this method fills up
  863. the remaining most significant bits in the target bit vector with either
  864. 0's or 1's, depending on the sign (= the most significant bit) of the
  865. source bit vector. This is also known as "sign extension".
  866.  
  867. This makes it possible to copy numbers from a smaller bit vector into
  868. a larger one while preserving the number's absolute value as well as
  869. its sign (due to the two's complement binary representation of numbers).
  870.  
  871. =item *
  872.  
  873. C<$vector-E<gt>Empty();>
  874.  
  875. Clears all bits in the given vector.
  876.  
  877. =item *
  878.  
  879. C<$vector-E<gt>Fill();>
  880.  
  881. Sets all bits in the given vector.
  882.  
  883. =item *
  884.  
  885. C<$vector-E<gt>Flip();>
  886.  
  887. Flips (i.e., complements) all bits in the given vector.
  888.  
  889. =item *
  890.  
  891. C<$vector-E<gt>Primes();>
  892.  
  893. Clears the given bit vector and sets all bits whose
  894. indices are prime numbers.
  895.  
  896. This method uses the algorithm known as the "Sieve of
  897. Erathostenes" internally.
  898.  
  899. =item *
  900.  
  901. C<$vec2-E<gt>Reverse($vec1);>
  902.  
  903. This method copies the given vector "C<$vec1>" to
  904. the vector "C<$vec2>", thereby reversing the order
  905. of all bits.
  906.  
  907. I.e., the least significant bit of "C<$vec1>" becomes the
  908. most significant bit of "C<$vec2>", whereas the most
  909. significant bit of "C<$vec1>" becomes the least
  910. significant bit of "C<$vec2>", and so forth
  911. for all bits in between.
  912.  
  913. Note that in-place processing is also possible, i.e.,
  914. "C<$vec1>" and "C<$vec2>" may be identical.
  915.  
  916. (Internally, this is the same as
  917. C<$vec1-E<gt>Interval_Reverse(0,$vec1-E<gt>Size()-1);>.)
  918.  
  919. =item *
  920.  
  921. C<$vector-E<gt>Interval_Empty($min,$max);>
  922.  
  923. Clears all bits in the interval C<[$min..$max]> (including both limits)
  924. in the given vector.
  925.  
  926. "C<$min>" and "C<$max>" may have the same value; this is the same
  927. as clearing a single bit with "C<Bit_Off()>" (but less efficient).
  928.  
  929. Note that C<$vector-E<gt>Interval_Empty(0,$vector-E<gt>Size()-1);>
  930. is the same as C<$vector-E<gt>Empty();> (but less efficient).
  931.  
  932. =item *
  933.  
  934. C<$vector-E<gt>Interval_Fill($min,$max);>
  935.  
  936. Sets all bits in the interval C<[$min..$max]> (including both limits)
  937. in the given vector.
  938.  
  939. "C<$min>" and "C<$max>" may have the same value; this is the same
  940. as setting a single bit with "C<Bit_On()>" (but less efficient).
  941.  
  942. Note that C<$vector-E<gt>Interval_Fill(0,$vector-E<gt>Size()-1);>
  943. is the same as C<$vector-E<gt>Fill();> (but less efficient).
  944.  
  945. =item *
  946.  
  947. C<$vector-E<gt>Interval_Flip($min,$max);>
  948.  
  949. Flips (i.e., complements) all bits in the interval C<[$min..$max]>
  950. (including both limits) in the given vector.
  951.  
  952. "C<$min>" and "C<$max>" may have the same value; this is the same
  953. as flipping a single bit with "C<bit_flip()>" (but less efficient).
  954.  
  955. Note that C<$vector-E<gt>Interval_Flip(0,$vector-E<gt>Size()-1);>
  956. is the same as C<$vector-E<gt>Flip();> and
  957. C<$vector-E<gt>Complement($vector);>
  958. (but less efficient).
  959.  
  960. =item *
  961.  
  962. C<$vector-E<gt>Interval_Reverse($min,$max);>
  963.  
  964. Reverses the order of all bits in the interval C<[$min..$max]>
  965. (including both limits) in the given vector.
  966.  
  967. I.e., bits "C<$min>" and "C<$max>" swap places, and so forth
  968. for all bits in between.
  969.  
  970. "C<$min>" and "C<$max>" may have the same value; this has no
  971. effect whatsoever, though.
  972.  
  973. =item *
  974.  
  975. C<if (($min,$max) = $vector-E<gt>Interval_Scan_inc($start))>
  976.  
  977. Returns the minimum and maximum indices of the next contiguous block
  978. of set bits (i.e., bits in the "on" state).
  979.  
  980. The search starts at index "C<$start>" (i.e., C<"$min" E<gt>= "$start">)
  981. and proceeds upwards (i.e., C<"$max" E<gt>= "$min">), thus repeatedly
  982. increments the search pointer "C<$start>" (internally).
  983.  
  984. Note though that the contents of the variable (or scalar literal value)
  985. "C<$start>" is B<NOT> altered. I.e., you have to set it to the desired
  986. value yourself prior to each call to "C<Interval_Scan_inc()>" (see also
  987. the example given below).
  988.  
  989. Actually, the bit vector is not searched bit by bit, but one machine
  990. word at a time, in order to speed up execution (which means that this
  991. method is quite efficient).
  992.  
  993. An empty list is returned if no such block can be found.
  994.  
  995. Note that a single set bit (surrounded by cleared bits) is a valid
  996. block by this definition. In that case the return values for "C<$min>"
  997. and "C<$max>" are the same.
  998.  
  999. Typical use:
  1000.  
  1001.     $start = 0;
  1002.     while (($start < $vector->Size()) &&
  1003.         (($min,$max) = $vector->Interval_Scan_inc($start)))
  1004.     {
  1005.         $start = $max + 2;
  1006.  
  1007.         # do something with $min and $max
  1008.     }
  1009.  
  1010. =item *
  1011.  
  1012. C<if (($min,$max) = $vector-E<gt>Interval_Scan_dec($start))>
  1013.  
  1014. Returns the minimum and maximum indices of the next contiguous block
  1015. of set bits (i.e., bits in the "on" state).
  1016.  
  1017. The search starts at index "C<$start>" (i.e., C<"$max" E<lt>= "$start">)
  1018. and proceeds downwards (i.e., C<"$min" E<lt>= "$max">), thus repeatedly
  1019. decrements the search pointer "C<$start>" (internally).
  1020.  
  1021. Note though that the contents of the variable (or scalar literal value)
  1022. "C<$start>" is B<NOT> altered. I.e., you have to set it to the desired
  1023. value yourself prior to each call to "C<Interval_Scan_dec()>" (see also
  1024. the example given below).
  1025.  
  1026. Actually, the bit vector is not searched bit by bit, but one machine
  1027. word at a time, in order to speed up execution (which means that this
  1028. method is quite efficient).
  1029.  
  1030. An empty list is returned if no such block can be found.
  1031.  
  1032. Note that a single set bit (surrounded by cleared bits) is a valid
  1033. block by this definition. In that case the return values for "C<$min>"
  1034. and "C<$max>" are the same.
  1035.  
  1036. Typical use:
  1037.  
  1038.     $start = $vector->Size() - 1;
  1039.     while (($start >= 0) &&
  1040.         (($min,$max) = $vector->Interval_Scan_dec($start)))
  1041.     {
  1042.         $start = $min - 2;
  1043.  
  1044.         # do something with $min and $max
  1045.     }
  1046.  
  1047. =item *
  1048.  
  1049. C<$vec2-E<gt>Interval_Copy($vec1,$offset2,$offset1,$length);>
  1050.  
  1051. This method allows you to copy a stretch of contiguous bits (starting
  1052. at any position "C<$offset1>" you choose, with a length of "C<$length>"
  1053. bits) from a given "source" bit vector "C<$vec1>" to another position
  1054. "C<$offset2>" in a "target" bit vector "C<$vec2>".
  1055.  
  1056. Note that the two bit vectors "C<$vec1>" and "C<$vec2>" do B<NOT>
  1057. need to have the same (matching) size!
  1058.  
  1059. Consequently, any of the two terms "C<$offset1 + $length>" and
  1060. "C<$offset2 + $length>" (or both) may exceed the actual length
  1061. of its corresponding bit vector ("C<$vec1-E<gt>Size()>" and
  1062. "C<$vec2-E<gt>Size()>", respectively).
  1063.  
  1064. In such a case, the "C<$length>" parameter is automatically reduced
  1065. internally so that both terms above are bounded by the number of bits
  1066. of their corresponding bit vector.
  1067.  
  1068. This may even result in a length of zero, in which case nothing is
  1069. copied at all.
  1070.  
  1071. (Of course the value of the "C<$length>" parameter, supplied by you
  1072. in the initial method call, may also be zero right from the start!)
  1073.  
  1074. Note also that "C<$offset1>" and "C<$offset2>" must lie within the
  1075. range "C<0>" and, respectively, "C<$vec1-E<gt>Size()-1>" or
  1076. "C<$vec2-E<gt>Size()-1>", or a fatal "offset out of range" error
  1077. will occur.
  1078.  
  1079. Note further that "C<$vec1>" and "C<$vec2>" may be identical, i.e.,
  1080. you may copy a stretch of contiguous bits from one part of a given
  1081. bit vector to another part.
  1082.  
  1083. The source and the target interval may even overlap, in which case
  1084. the copying is automatically performed in ascending or descending
  1085. order (depending on the direction of the copy - downwards or upwards
  1086. in the bit vector, respectively) to handle this situation correctly,
  1087. i.e., so that no bits are being overwritten before they have been
  1088. copied themselves.
  1089.  
  1090. =item *
  1091.  
  1092. C<$vec2-E<gt>Interval_Substitute($vec1,$off2,$len2,$off1,$len1);>
  1093.  
  1094. This method is (roughly) the same for bit vectors (i.e., arrays
  1095. of booleans) as what the "splice" function in Perl is for lists
  1096. (i.e., arrays of scalars).
  1097.  
  1098. (See L<perlfunc/splice> for more details about this function.)
  1099.  
  1100. The method allows you to substitute a stretch of contiguous bits
  1101. (defined by a position (offset) "C<$off1>" and a length of "C<$len1>"
  1102. bits) from a given "source" bit vector "C<$vec1>" for a different
  1103. stretch of contiguous bits (defined by a position (offset) "C<$off2>"
  1104. and a length of "C<$len2>" bits) in another, "target" bit vector
  1105. "C<$vec2>".
  1106.  
  1107. Note that the two bit vectors "C<$vec1>" and "C<$vec2>" do B<NOT>
  1108. need to have the same (matching) size!
  1109.  
  1110. Note further that "C<$off1>" and "C<$off2>" must lie within the
  1111. range "C<0>" and, respectively, "C<$vec1-E<gt>Size()>" or
  1112. "C<$vec2-E<gt>Size()>", or a fatal "offset out of range" error
  1113. will occur.
  1114.  
  1115. Alert readers will have noticed that these upper limits are B<NOT>
  1116. "C<$vec1-E<gt>Size()-1>" and "C<$vec2-E<gt>Size()-1>", as they would
  1117. be for any other method in this module, but that these offsets may
  1118. actually point to one position B<PAST THE END> of the corresponding
  1119. bit vector.
  1120.  
  1121. This is necessary in order to make it possible to B<APPEND> a given
  1122. stretch of bits to the target bit vector instead of B<REPLACING>
  1123. something in it.
  1124.  
  1125. For reasons of symmetry and generality, the same applies to the offset
  1126. in the source bit vector, even though such an offset (one position past
  1127. the end of the bit vector) does not serve any practical purpose there
  1128. (but does not cause any harm either).
  1129.  
  1130. (Actually this saves you from the need of testing for this special case,
  1131. in certain circumstances.)
  1132.  
  1133. Note that whenever the term "C<$off1 + $len1>" exceeds the size
  1134. "C<$vec1-E<gt>Size()>" of bit vector "C<$vec1>" (or if "C<$off2 + $len2>"
  1135. exceeds "C<$vec2-E<gt>Size()>"), the corresponding length ("C<$len1>"
  1136. or "C<$len2>", respectively) is automatically reduced internally
  1137. so that "C<$off1 + $len1 E<lt>= $vec1-E<gt>Size()>" (and
  1138. "C<$off2 + $len2 E<lt>= $vec2-E<gt>Size()>") holds.
  1139.  
  1140. (Note that this does B<NOT> alter the intended result, even though
  1141. this may seem counter-intuitive at first!)
  1142.  
  1143. This may even result in a length ("C<$len1>" or "C<$len2>") of zero.
  1144.  
  1145. A length of zero for the interval in the B<SOURCE> bit vector
  1146. ("C<$len1 == 0>") means that the indicated stretch of bits in
  1147. the target bit vector (starting at position "C<$off2>") is to
  1148. be replaced by B<NOTHING>, i.e., is to be B<DELETED>.
  1149.  
  1150. A length of zero for the interval in the B<TARGET> bit vector
  1151. ("C<$len2> == 0") means that B<NOTHING> is replaced, and that the
  1152. stretch of bits from the source bit vector is simply B<INSERTED>
  1153. into the target bit vector at the indicated position ("C<$off2>").
  1154.  
  1155. If both length parameters are zero, nothing is done at all.
  1156.  
  1157. Note that in contrast to any other method in this module (especially
  1158. "C<Interval_Copy()>", "C<Insert()>" and "C<Delete()>"), this method
  1159. B<IMPLICITLY> and B<AUTOMATICALLY> adapts the length of the resulting
  1160. bit vector as needed, as given by
  1161.  
  1162.         $size = $vec2->Size();   #  before
  1163.         $size += $len1 - $len2;  #  after
  1164.  
  1165. (The only other method in this module that changes the size of a bit
  1166. vector is the method "C<Resize()>".)
  1167.  
  1168. In other words, replacing a given interval of bits in the target bit
  1169. vector with a longer or shorter stretch of bits from the source bit
  1170. vector, or simply inserting ("C<$len2 == 0>") a stretch of bits into
  1171. or deleting ("C<$len1 == 0>") an interval of bits from the target bit
  1172. vector will automatically increase or decrease, respectively, the size
  1173. of the target bit vector accordingly.
  1174.  
  1175. For the sake of generality, this may even result in a bit vector with
  1176. a size of zero (containing no bits at all).
  1177.  
  1178. This is also the reason why bit vectors of length zero are permitted
  1179. in this module in the first place, starting with version 5.0.
  1180.  
  1181. Finally, note that "C<$vec1>" and "C<$vec2>" may be identical, i.e.,
  1182. in-place processing is possible.
  1183.  
  1184. (If you think about that for a while or if you look at the code,
  1185. you will see that this is far from trivial!)
  1186.  
  1187. =item *
  1188.  
  1189. C<if ($vector-E<gt>is_empty())>
  1190.  
  1191. Tests whether the given bit vector is empty, i.e., whether B<ALL> of
  1192. its bits are cleared (in the "off" state).
  1193.  
  1194. In "big integer" arithmetic, this is equivalent to testing whether
  1195. the number stored in the bit vector is zero ("C<0>").
  1196.  
  1197. Returns "true" ("C<1>") if the bit vector is empty and "false" ("C<0>")
  1198. otherwise.
  1199.  
  1200. Note that this method also returns "true" ("C<1>") if the given bit
  1201. vector has a length of zero, i.e., if it contains no bits at all.
  1202.  
  1203. =item *
  1204.  
  1205. C<if ($vector-E<gt>is_full())>
  1206.  
  1207. Tests whether the given bit vector is full, i.e., whether B<ALL> of
  1208. its bits are set (in the "on" state).
  1209.  
  1210. In "big integer" arithmetic, this is equivalent to testing whether
  1211. the number stored in the bit vector is minus one ("-1").
  1212.  
  1213. Returns "true" ("C<1>") if the bit vector is full and "false" ("C<0>")
  1214. otherwise.
  1215.  
  1216. If the given bit vector has a length of zero (i.e., if it contains
  1217. no bits at all), this method returns "false" ("C<0>").
  1218.  
  1219. =item *
  1220.  
  1221. C<if ($vec1-E<gt>equal($vec2))>
  1222.  
  1223. Tests the two given bit vectors for equality.
  1224.  
  1225. Returns "true" ("C<1>") if the two bit vectors are exact
  1226. copies of one another and "false" ("C<0>") otherwise.
  1227.  
  1228. =item *
  1229.  
  1230. C<$cmp = $vec1-E<gt>Lexicompare($vec2);>
  1231.  
  1232. Compares the two given bit vectors, which are
  1233. regarded as B<UNSIGNED> numbers in binary representation.
  1234.  
  1235. The method returns "C<-1>" if the first bit vector is smaller
  1236. than the second bit vector, "C<0>" if the two bit vectors are
  1237. exact copies of one another and "C<1>" if the first bit vector
  1238. is greater than the second bit vector.
  1239.  
  1240. =item *
  1241.  
  1242. C<$cmp = $vec1-E<gt>Compare($vec2);>
  1243.  
  1244. Compares the two given bit vectors, which are
  1245. regarded as B<SIGNED> numbers in binary representation.
  1246.  
  1247. The method returns "C<-1>" if the first bit vector is smaller
  1248. than the second bit vector, "C<0>" if the two bit vectors are
  1249. exact copies of one another and "C<1>" if the first bit vector
  1250. is greater than the second bit vector.
  1251.  
  1252. =item *
  1253.  
  1254. C<$string = $vector-E<gt>to_Hex();>
  1255.  
  1256. Returns a hexadecimal string representing the given bit vector.
  1257.  
  1258. Note that this representation is quite compact, in that it only
  1259. needs at most twice the number of bytes needed to store the bit
  1260. vector itself, internally.
  1261.  
  1262. Note also that since a hexadecimal digit is always worth four bits,
  1263. the length of the resulting string is always a multiple of four bits,
  1264. regardless of the true length (in bits) of the given bit vector.
  1265.  
  1266. Finally, note that the B<LEAST> significant hexadecimal digit is
  1267. located at the B<RIGHT> end of the resulting string, and the B<MOST>
  1268. significant digit at the B<LEFT> end.
  1269.  
  1270. =item *
  1271.  
  1272. C<$vector-E<gt>from_Hex($string);>
  1273.  
  1274. Allows to read in the contents of a bit vector from a hexadecimal
  1275. string, such as returned by the method "C<to_Hex()>" (see above).
  1276.  
  1277. Remember that the least significant bits are always to the right of a
  1278. hexadecimal string, and the most significant bits to the left. Therefore,
  1279. the string is actually read in from right to left while the bit vector
  1280. is filled accordingly, 4 bits at a time, starting with the least significant
  1281. bits and going upward to the most significant bits.
  1282.  
  1283. If the given string contains less hexadecimal digits than are needed
  1284. to completely fill the given bit vector, the remaining (most significant)
  1285. bits are all cleared.
  1286.  
  1287. This also means that, even if the given string does not contain enough digits
  1288. to completely fill the given bit vector, the previous contents of the
  1289. bit vector are erased completely.
  1290.  
  1291. If the given string is longer than it needs to fill the given bit vector,
  1292. the superfluous characters are simply ignored.
  1293.  
  1294. (In fact they are ignored completely - they are not even checked for
  1295. proper syntax. See also below for more about that.)
  1296.  
  1297. This behaviour is intentional so that you may read in the string
  1298. representing one bit vector into another bit vector of different
  1299. size, i.e., as much of it as will fit.
  1300.  
  1301. If during the process of reading the given string any character is
  1302. encountered which is not a hexadecimal digit, a fatal syntax error
  1303. ensues ("input string syntax error").
  1304.  
  1305. =item *
  1306.  
  1307. C<$string = $vector-E<gt>to_Bin();>
  1308.  
  1309. Returns a binary string representing the given bit vector.
  1310.  
  1311. Example:
  1312.  
  1313.   $vector = Bit::Vector->new(8);
  1314.   $vector->Primes();
  1315.   $string = $vector->to_Bin();
  1316.   print "'$string'\n";
  1317.  
  1318. This prints:
  1319.  
  1320.   '10101100'
  1321.  
  1322. (Bits #7, #5, #3 and #2 are set.)
  1323.  
  1324. Note that the B<LEAST> significant bit is located at the B<RIGHT>
  1325. end of the resulting string, and the B<MOST> significant bit at
  1326. the B<LEFT> end.
  1327.  
  1328. =item *
  1329.  
  1330. C<$vector-E<gt>from_Bin($string);>
  1331.  
  1332. This method allows you to read in the contents of a bit vector from a
  1333. binary string, such as returned by the method "C<to_Bin()>" (see above).
  1334.  
  1335. Note that this method assumes that the B<LEAST> significant bit is located at
  1336. the B<RIGHT> end of the binary string, and the B<MOST> significant bit at the
  1337. B<LEFT> end. Therefore, the string is actually read in from right to left
  1338. while the bit vector is filled accordingly, one bit at a time, starting with
  1339. the least significant bit and going upward to the most significant bit.
  1340.  
  1341. If the given string contains less binary digits ("C<0>" and "C<1>") than are
  1342. needed to completely fill the given bit vector, the remaining (most significant)
  1343. bits are all cleared.
  1344.  
  1345. This also means that, even if the given string does not contain enough digits
  1346. to completely fill the given bit vector, the previous contents of the
  1347. bit vector are erased completely.
  1348.  
  1349. If the given string is longer than it needs to fill the given bit vector,
  1350. the superfluous characters are simply ignored.
  1351.  
  1352. (In fact they are ignored completely - they are not even checked for
  1353. proper syntax. See also below for more about that.)
  1354.  
  1355. This behaviour is intentional so that you may read in the string
  1356. representing one bit vector into another bit vector of different
  1357. size, i.e., as much of it as will fit.
  1358.  
  1359. If during the process of reading the given string any character is
  1360. encountered which is not either "C<0>" or "C<1>", a fatal syntax error
  1361. ensues ("input string syntax error").
  1362.  
  1363. =item *
  1364.  
  1365. C<$string = $vector-E<gt>to_Dec();>
  1366.  
  1367. This method returns a string representing the contents of the given bit
  1368. vector converted to decimal (base C<10>).
  1369.  
  1370. Note that this method assumes the given bit vector to be B<SIGNED> (and
  1371. to contain a number in two's complement binary representation).
  1372.  
  1373. Consequently, whenever the most significant bit of the given bit vector
  1374. is set, the number stored in it is regarded as being B<NEGATIVE>.
  1375.  
  1376. The resulting string can be fed into "C<from_Dec()>" (see below) in order
  1377. to copy the contents of this bit vector to another one (or to restore the
  1378. contents of this one). This is not advisable, though, since this would be
  1379. very inefficient (there are much more efficient methods for storing and
  1380. copying bit vectors in this module).
  1381.  
  1382. Note that such conversion from binary to decimal is inherently slow
  1383. since the bit vector has to be repeatedly divided by C<10> with remainder
  1384. until the quotient becomes C<0> (each remainder in turn represents a single
  1385. decimal digit of the resulting string).
  1386.  
  1387. This is also true for the implementation of this method in this module,
  1388. even though a considerable effort has been made to speed it up: instead of
  1389. repeatedly dividing by C<10>, the bit vector is repeatedly divided by the
  1390. largest power of C<10> that will fit into a machine word. The remainder is
  1391. then repeatedly divided by C<10> using only machine word arithmetics, which
  1392. is much faster than dividing the whole bit vector ("divide and rule" principle).
  1393.  
  1394. According to my own measurements, this resulted in an 8-fold speed increase
  1395. over the straightforward approach.
  1396.  
  1397. Still, conversion to decimal should be used only where absolutely necessary.
  1398.  
  1399. Keep the resulting string stored in some variable if you need it again,
  1400. instead of converting the bit vector all over again.
  1401.  
  1402. Beware that if you set the configuration for overloaded operators to
  1403. "output=decimal", this method will be called for every bit vector
  1404. enclosed in double quotes!
  1405.  
  1406. =item *
  1407.  
  1408. C<$vector-E<gt>from_Dec($string);>
  1409.  
  1410. This method allows you to convert a given decimal number, which may be
  1411. positive or negative, into two's complement binary representation, which
  1412. is then stored in the given bit vector.
  1413.  
  1414. The decimal number should always be provided as a string, to avoid possible
  1415. truncation (due to the limited precision of integers in Perl) or formatting
  1416. (due to Perl's use of scientific notation for large numbers), which would
  1417. lead to errors.
  1418.  
  1419. If the binary representation of the given decimal number is too big to fit
  1420. into the given bit vector (if the given bit vector does not contain enough
  1421. bits to hold it), a fatal "numeric overflow error" occurs.
  1422.  
  1423. If the input string contains other characters than decimal digits (C<0-9>)
  1424. and an optional leading sign ("C<+>" or "C<->"), a fatal "input string
  1425. syntax error" occurs.
  1426.  
  1427. Beware that large positive numbers which cause the most significant bit to
  1428. be set (e.g. "255" in a bit vector with 8 bits) will be printed as negative
  1429. numbers when converted back to decimal using the method "to_Dec()" (e.g.
  1430. "-1", in our example), because numbers with the most significant bit set
  1431. are considered to be negative in two's complement binary representation.
  1432.  
  1433. Note also that while it is possible to thusly enter negative numbers as
  1434. large positive numbers (e.g. "255" for "-1" in a bit vector with 8 bits),
  1435. the contrary isn't, i.e., you cannot enter "-255" for "+1", in our example.
  1436. A fatal "numeric overflow error" will occur if you try to do so.
  1437.  
  1438. If possible program abortion is unwanted or intolerable, use
  1439. "C<eval>", like this:
  1440.  
  1441.   eval { $vector->from_Dec("1152921504606846976"); };
  1442.   if ($@)
  1443.   {
  1444.       # an error occurred
  1445.   }
  1446.  
  1447. There are four possible error messages:
  1448.  
  1449.   if ($@ =~ /item is not a string/)
  1450.  
  1451.   if ($@ =~ /input string syntax error/)
  1452.  
  1453.   if ($@ =~ /numeric overflow error/)
  1454.  
  1455.   if ($@ =~ /unable to allocate memory/)
  1456.  
  1457. Note that the conversion from decimal to binary is costly in terms of
  1458. processing time, since a lot of multiplications have to be carried out
  1459. (in principle, each decimal digit must be multiplied with the binary
  1460. representation of the power of C<10> corresponding to its position in
  1461. the decimal number, i.e., 1, 10, 100, 1000, 10000 and so on).
  1462.  
  1463. This is not as time consuming as the opposite conversion, from binary
  1464. to decimal (where successive divisions have to be carried out, which
  1465. are even more expensive than multiplications), but still noticeable.
  1466.  
  1467. Again (as in the case of "C<to_Dec()>"), the implementation of this
  1468. method in this module uses the principle of "divide and rule" in order
  1469. to speed up the conversion, i.e., as many decimal digits as possible
  1470. are first accumulated (converted) in a machine word and only then
  1471. stored in the given bit vector.
  1472.  
  1473. Even so, use this method only where absolutely necessary if speed is
  1474. an important consideration in your application.
  1475.  
  1476. Beware that if you set the configuration for overloaded operators to
  1477. "input=decimal", this method will be called for every scalar operand
  1478. you use!
  1479.  
  1480. =item *
  1481.  
  1482. C<$string = $vector-E<gt>to_Enum();>
  1483.  
  1484. Converts the given bit vector or set into an enumeration of single
  1485. indices and ranges of indices (".newsrc" style), representing the
  1486. bits that are set ("C<1>") in the bit vector.
  1487.  
  1488. Example:
  1489.  
  1490.   $vector = Bit::Vector->new(20);
  1491.   $vector->Bit_On(2);
  1492.   $vector->Bit_On(3);
  1493.   $vector->Bit_On(11);
  1494.   $vector->Interval_Fill(5,7);
  1495.   $vector->Interval_Fill(13,19);
  1496.   print "'", $vector->to_Enum(), "'\n";
  1497.  
  1498. which prints
  1499.  
  1500.   '2,3,5-7,11,13-19'
  1501.  
  1502. If the given bit vector is empty, the resulting string will
  1503. also be empty.
  1504.  
  1505. Note, by the way, that the above example can also be written
  1506. a little handier, perhaps, as follows:
  1507.  
  1508.   Bit::Vector->Configuration("out=enum");
  1509.   $vector = Bit::Vector->new(20);
  1510.   $vector->Index_List_Store(2,3,5,6,7,11,13,14,15,16,17,18,19);
  1511.   print "'$vector'\n";
  1512.  
  1513. =item *
  1514.  
  1515. C<$vector-E<gt>from_Enum($string);>
  1516.  
  1517. This method first empties the given bit vector and then tries to
  1518. set the bits and ranges of bits specified in the given string.
  1519.  
  1520. The string "C<$string>" must only contain unsigned integers
  1521. or ranges of integers (two unsigned integers separated by a
  1522. dash "-"), separated by commas (",").
  1523.  
  1524. All other characters are disallowed (including white space!)
  1525. and will lead to a fatal "input string syntax error".
  1526.  
  1527. In each range, the first integer (the lower limit of the range)
  1528. must always be less than or equal to the second integer (the
  1529. upper limit), or a fatal "minimum > maximum index" error occurs.
  1530.  
  1531. All integers must lie in the permitted range for the given
  1532. bit vector, i.e., they must lie between "C<0>" and
  1533. "C<$vector-E<gt>Size()-1>".
  1534.  
  1535. If this condition is not met, a fatal "index out of range"
  1536. error occurs.
  1537.  
  1538. If possible program abortion is unwanted or intolerable, use
  1539. "C<eval>", like this:
  1540.  
  1541.   eval { $vector->from_Enum("2,3,5-7,11,13-19"); };
  1542.   if ($@)
  1543.   {
  1544.       # an error occurred
  1545.   }
  1546.  
  1547. There are four possible error messages:
  1548.  
  1549.   if ($@ =~ /item is not a string/)
  1550.  
  1551.   if ($@ =~ /input string syntax error/)
  1552.  
  1553.   if ($@ =~ /index out of range/)
  1554.  
  1555.   if ($@ =~ /minimum > maximum index/)
  1556.  
  1557. Note that the order of the indices and ranges is irrelevant,
  1558. i.e.,
  1559.  
  1560.   eval { $vector->from_Enum("11,5-7,3,13-19,2"); };
  1561.  
  1562. results in the same vector as in the example above.
  1563.  
  1564. Ranges and indices may also overlap.
  1565.  
  1566. This is because each (single) index in the string is passed
  1567. to the method "C<Bit_On()>", internally, and each range to
  1568. the method "C<Interval_Fill()>".
  1569.  
  1570. This means that the resulting bit vector is just the union
  1571. of all the indices and ranges specified in the given string.
  1572.  
  1573. =item *
  1574.  
  1575. C<$vector-E<gt>Bit_Off($index);>
  1576.  
  1577. Clears the bit with index "C<$index>" in the given vector.
  1578.  
  1579. =item *
  1580.  
  1581. C<$vector-E<gt>Bit_On($index);>
  1582.  
  1583. Sets the bit with index "C<$index>" in the given vector.
  1584.  
  1585. =item *
  1586.  
  1587. C<$vector-E<gt>bit_flip($index)>
  1588.  
  1589. Flips (i.e., complements) the bit with index "C<$index>"
  1590. in the given vector.
  1591.  
  1592. Moreover, this method returns the B<NEW> state of the
  1593. bit in question, i.e., it returns "C<0>" if the bit is
  1594. cleared or "C<1>" if the bit is set (B<AFTER> flipping it).
  1595.  
  1596. =item *
  1597.  
  1598. C<if ($vector-E<gt>bit_test($index))>
  1599.  
  1600. C<if ($vector-E<gt>contains($index))>
  1601.  
  1602. Returns the current state of the bit with index "C<$index>"
  1603. in the given vector, i.e., returns "C<0>" if it is cleared
  1604. (in the "off" state) or "C<1>" if it is set (in the "on" state).
  1605.  
  1606. =item *
  1607.  
  1608. C<$vector-E<gt>Bit_Copy($index,$bit);>
  1609.  
  1610. Sets the bit with index "C<$index>" in the given vector either
  1611. to "C<0>" or "C<1>" depending on the boolean value "C<$bit>".
  1612.  
  1613. =item *
  1614.  
  1615. C<$vector-E<gt>LSB($bit);>
  1616.  
  1617. Allows you to set the least significant bit in the given bit
  1618. vector to the value given by the boolean parameter "C<$bit>".
  1619.  
  1620. This is a (faster) shortcut for "C<$vector-E<gt>Bit_Copy(0,$bit);>".
  1621.  
  1622. =item *
  1623.  
  1624. C<$vector-E<gt>MSB($bit);>
  1625.  
  1626. Allows you to set the most significant bit in the given bit
  1627. vector to the value given by the boolean parameter "C<$bit>".
  1628.  
  1629. This is a (faster) shortcut for
  1630. "C<$vector-E<gt>Bit_Copy($vector-E<gt>Size()-1,$bit);>".
  1631.  
  1632. =item *
  1633.  
  1634. C<$bit = $vector-E<gt>lsb();>
  1635.  
  1636. Returns the least significant bit of the given bit vector.
  1637.  
  1638. This is a (faster) shortcut for "C<$bit = $vector-E<gt>bit_test(0);>".
  1639.  
  1640. =item *
  1641.  
  1642. C<$bit = $vector-E<gt>msb();>
  1643.  
  1644. Returns the most significant bit of the given bit vector.
  1645.  
  1646. This is a (faster) shortcut for
  1647. "C<$bit = $vector-E<gt>bit_test($vector-E<gt>Size()-1);>".
  1648.  
  1649. =item *
  1650.  
  1651. C<$carry_out = $vector-E<gt>rotate_left();>
  1652.  
  1653.   carry             MSB           vector:           LSB
  1654.    out:
  1655.   +---+            +---+---+---+---     ---+---+---+---+
  1656.   |   |  <---+---  |   |   |   |    ...    |   |   |   |  <---+
  1657.   +---+      |     +---+---+---+---     ---+---+---+---+      |
  1658.              |                                                |
  1659.              +------------------------------------------------+
  1660.  
  1661. The least significant bit (LSB) is the bit with index "C<0>", the most
  1662. significant bit (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1663.  
  1664. =item *
  1665.  
  1666. C<$carry_out = $vector-E<gt>rotate_right();>
  1667.  
  1668.           MSB           vector:           LSB            carry
  1669.                                                           out:
  1670.          +---+---+---+---     ---+---+---+---+           +---+
  1671.   +--->  |   |   |   |    ...    |   |   |   |  ---+---> |   |
  1672.   |      +---+---+---+---     ---+---+---+---+     |     +---+
  1673.   |                                                |
  1674.   +------------------------------------------------+
  1675.  
  1676. The least significant bit (LSB) is the bit with index "C<0>", the most
  1677. significant bit (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1678.  
  1679. =item *
  1680.  
  1681. C<$carry_out = $vector-E<gt>shift_left($carry_in);>
  1682.  
  1683.   carry         MSB           vector:           LSB         carry
  1684.    out:                                                      in:
  1685.   +---+        +---+---+---+---     ---+---+---+---+        +---+
  1686.   |   |  <---  |   |   |   |    ...    |   |   |   |  <---  |   |
  1687.   +---+        +---+---+---+---     ---+---+---+---+        +---+
  1688.  
  1689. The least significant bit (LSB) is the bit with index "C<0>", the most
  1690. significant bit (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1691.  
  1692. =item *
  1693.  
  1694. C<$carry_out = $vector-E<gt>shift_right($carry_in);>
  1695.  
  1696.   carry         MSB           vector:           LSB         carry
  1697.    in:                                                       out:
  1698.   +---+        +---+---+---+---     ---+---+---+---+        +---+
  1699.   |   |  --->  |   |   |   |    ...    |   |   |   |  --->  |   |
  1700.   +---+        +---+---+---+---     ---+---+---+---+        +---+
  1701.  
  1702. The least significant bit (LSB) is the bit with index "C<0>", the most
  1703. significant bit (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1704.  
  1705. =item *
  1706.  
  1707. C<$vector-E<gt>Move_Left($bits);>
  1708.  
  1709. Shifts the given bit vector left by "C<$bits>" bits, i.e., inserts "C<$bits>"
  1710. new bits at the lower end (least significant bit) of the bit vector, moving
  1711. all other bits up by "C<$bits>" places, thereby losing the "C<$bits>" most
  1712. significant bits.
  1713.  
  1714. The inserted new bits are all cleared (set to the "off" state).
  1715.  
  1716. This method does nothing if "C<$bits>" is equal to zero.
  1717.  
  1718. Beware that the whole bit vector is cleared B<WITHOUT WARNING> if
  1719. "C<$bits>" is greater than or equal to the size of the given bit vector!
  1720.  
  1721. In fact this method is equivalent to
  1722.  
  1723.   for ( $i = 0; $i < $bits; $i++ ) { $vector->shift_left(0); }
  1724.  
  1725. except that it is much more efficient (for "C<$bits>" greater than or
  1726. equal to the number of bits in a machine word on your system) than
  1727. this straightforward approach.
  1728.  
  1729. =item *
  1730.  
  1731. C<$vector-E<gt>Move_Right($bits);>
  1732.  
  1733. Shifts the given bit vector right by "C<$bits>" bits, i.e., deletes the
  1734. "C<$bits>" least significant bits of the bit vector, moving all other bits
  1735. down by "C<$bits>" places, thereby creating "C<$bits>" new bits at the upper
  1736. end (most significant bit) of the bit vector.
  1737.  
  1738. These new bits are all cleared (set to the "off" state).
  1739.  
  1740. This method does nothing if "C<$bits>" is equal to zero.
  1741.  
  1742. Beware that the whole bit vector is cleared B<WITHOUT WARNING> if
  1743. "C<$bits>" is greater than or equal to the size of the given bit vector!
  1744.  
  1745. In fact this method is equivalent to
  1746.  
  1747.   for ( $i = 0; $i < $bits; $i++ ) { $vector->shift_right(0); }
  1748.  
  1749. except that it is much more efficient (for "C<$bits>" greater than or
  1750. equal to the number of bits in a machine word on your system) than
  1751. this straightforward approach.
  1752.  
  1753. =item *
  1754.  
  1755. C<$vector-E<gt>Insert($offset,$bits);>
  1756.  
  1757. This method inserts "C<$bits>" fresh new bits at position "C<$offset>"
  1758. in the given bit vector.
  1759.  
  1760. The "C<$bits>" most significant bits are lost, and all bits starting
  1761. with bit number "C<$offset>" up to and including bit number
  1762. "C<$vector-E<gt>Size()-$bits-1>" are moved up by "C<$bits>" places.
  1763.  
  1764. The now vacant "C<$bits>" bits starting at bit number "C<$offset>"
  1765. (up to and including bit number "C<$offset+$bits-1>") are then set
  1766. to zero (cleared).
  1767.  
  1768. Note that this method does B<NOT> increase the size of the given bit
  1769. vector, i.e., the bit vector is B<NOT> extended at its upper end to
  1770. "rescue" the "C<$bits>" uppermost (most significant) bits - instead,
  1771. these bits are lost forever.
  1772.  
  1773. If you don't want this to happen, you have to increase the size of the
  1774. given bit vector B<EXPLICITLY> and B<BEFORE> you perform the "Insert"
  1775. operation, with a statement such as the following:
  1776.  
  1777.   $vector->Resize($vector->Size() + $bits);
  1778.  
  1779. Or use the method "C<Interval_Substitute()>" instead of "C<Insert()>",
  1780. which performs automatic growing and shrinking of its target bit vector.
  1781.  
  1782. Note also that "C<$offset>" must lie in the permitted range between
  1783. "C<0>" and "C<$vector-E<gt>Size()-1>", or a fatal "offset out of range"
  1784. error will occur.
  1785.  
  1786. If the term "C<$offset + $bits>" exceeds "C<$vector-E<gt>Size()-1>",
  1787. all the bits starting with bit number "C<$offset>" up to bit number
  1788. "C<$vector-E<gt>Size()-1>" are simply cleared.
  1789.  
  1790. =item *
  1791.  
  1792. C<$vector-E<gt>Delete($offset,$bits);>
  1793.  
  1794. This method deletes, i.e., removes the bits starting at position
  1795. "C<$offset>" up to and including bit number "C<$offset+$bits-1>"
  1796. from the given bit vector.
  1797.  
  1798. The remaining uppermost bits (starting at position "C<$offset+$bits>"
  1799. up to and including bit number "C<$vector-E<gt>Size()-1>") are moved
  1800. down by "C<$bits>" places.
  1801.  
  1802. The now vacant uppermost (most significant) "C<$bits>" bits are then
  1803. set to zero (cleared).
  1804.  
  1805. Note that this method does B<NOT> decrease the size of the given bit
  1806. vector, i.e., the bit vector is B<NOT> clipped at its upper end to
  1807. "get rid of" the vacant "C<$bits>" uppermost bits.
  1808.  
  1809. If you don't want this, i.e., if you want the bit vector to shrink
  1810. accordingly, you have to do so B<EXPLICITLY> and B<AFTER> the "Delete"
  1811. operation, with a couple of statements such as these:
  1812.  
  1813.   $size = $vector->Size();
  1814.   if ($bits > $size) { $bits = $size; }
  1815.   $vector->Resize($size - $bits);
  1816.  
  1817. Or use the method "C<Interval_Substitute()>" instead of "C<Delete()>",
  1818. which performs automatic growing and shrinking of its target bit vector.
  1819.  
  1820. Note also that "C<$offset>" must lie in the permitted range between
  1821. "C<0>" and "C<$vector-E<gt>Size()-1>", or a fatal "offset out of range"
  1822. error will occur.
  1823.  
  1824. If the term "C<$offset + $bits>" exceeds "C<$vector-E<gt>Size()-1>",
  1825. all the bits starting with bit number "C<$offset>" up to bit number
  1826. "C<$vector-E<gt>Size()-1>" are simply cleared.
  1827.  
  1828. =item *
  1829.  
  1830. C<$carry = $vector-E<gt>increment();>
  1831.  
  1832. This method increments the given bit vector.
  1833.  
  1834. Note that this method regards bit vectors as being unsigned,
  1835. i.e., the largest possible positive number is directly
  1836. followed by the smallest possible (or greatest possible,
  1837. speaking in absolute terms) negative number:
  1838.  
  1839.   before:  2 ^ (b-1) - 1    (= "0111...1111")
  1840.   after:   2 ^ (b-1)        (= "1000...0000")
  1841.  
  1842. where "C<b>" is the number of bits of the given bit vector.
  1843.  
  1844. The method returns "false" ("C<0>") in all cases except when a
  1845. carry over occurs (in which case it returns "true", i.e., "C<1>"),
  1846. which happens when the number "1111...1111" is incremented,
  1847. which gives "0000...0000" plus a carry over to the next higher
  1848. (binary) digit.
  1849.  
  1850. This can be used for the terminating condition of a "while" loop,
  1851. for instance, in order to cycle through all possible values the
  1852. bit vector can assume.
  1853.  
  1854. =item *
  1855.  
  1856. C<$carry = $vector-E<gt>decrement();>
  1857.  
  1858. This method decrements the given bit vector.
  1859.  
  1860. Note that this method regards bit vectors as being unsigned,
  1861. i.e., the smallest possible (or greatest possible, speaking
  1862. in absolute terms) negative number is directly followed by
  1863. the largest possible positive number:
  1864.  
  1865.   before:  2 ^ (b-1)        (= "1000...0000")
  1866.   after:   2 ^ (b-1) - 1    (= "0111...1111")
  1867.  
  1868. where "C<b>" is the number of bits of the given bit vector.
  1869.  
  1870. The method returns "false" ("C<0>") in all cases except when a
  1871. carry over occurs (in which case it returns "true", i.e., "C<1>"),
  1872. which happens when the number "0000...0000" is decremented,
  1873. which gives "1111...1111" minus a carry over to the next higher
  1874. (binary) digit.
  1875.  
  1876. This can be used for the terminating condition of a "while" loop,
  1877. for instance, in order to cycle through all possible values the
  1878. bit vector can assume.
  1879.  
  1880. =item *
  1881.  
  1882. C<$overflow = $vec2-E<gt>inc($vec1);>
  1883.  
  1884. This method copies the contents of bit vector "C<$vec1>" to bit
  1885. vector "C<$vec2>" and increments the copy (not the original).
  1886.  
  1887. If by incrementing the number its sign becomes invalid, the return
  1888. value ("overflow" flag) will be true ("C<1>"), or false ("C<0>")
  1889. if not. (See the description of the method "add()" below for
  1890. a more in-depth explanation of what "overflow" means).
  1891.  
  1892. Note that in-place operation is also possible, i.e., "C<$vec1>"
  1893. and "C<$vec2>" may be identical.
  1894.  
  1895. =item *
  1896.  
  1897. C<$overflow = $vec2-E<gt>dec($vec1);>
  1898.  
  1899. This method copies the contents of bit vector "C<$vec1>" to bit
  1900. vector "C<$vec2>" and decrements the copy (not the original).
  1901.  
  1902. If by decrementing the number its sign becomes invalid, the return
  1903. value ("overflow" flag) will be true ("C<1>"), or false ("C<0>")
  1904. if not. (See the description of the method "subtract()" below
  1905. for a more in-depth explanation of what "overflow" means).
  1906.  
  1907. Note that in-place operation is also possible, i.e., "C<$vec1>"
  1908. and "C<$vec2>" may be identical.
  1909.  
  1910. =item *
  1911.  
  1912. C<$carry = $vec3-E<gt>add($vec1,$vec2,$carry);>
  1913.  
  1914. C<($carry,$overflow) = $vec3-E<gt>add($vec1,$vec2,$carry);>
  1915.  
  1916. This method adds the two numbers contained in bit vector "C<$vec1>"
  1917. and "C<$vec2>" with carry "C<$carry>" and stores the result in
  1918. bit vector "C<$vec3>".
  1919.  
  1920. I.e.,
  1921.             $vec3 = $vec1 + $vec2 + $carry
  1922.  
  1923. Note that the "C<$carry>" parameter is a boolean value, i.e.,
  1924. only its least significant bit is taken into account. (Think of
  1925. it as though "C<$carry &= 1;>" was always executed internally.)
  1926.  
  1927. In scalar context, the method returns a boolean value which
  1928. indicates if a carry over (to the next higher bit position)
  1929. has occured. In list context, the method returns the carry
  1930. and the overflow flag (in this order).
  1931.  
  1932. The overflow flag is true ("C<1>") if the sign (i.e., the most
  1933. significant bit) of the result is wrong. This can happen when
  1934. adding two very large positive numbers or when adding two (by
  1935. their absolute value) very large negative numbers. See also
  1936. further below.
  1937.  
  1938. The carry in- and output is needed mainly for cascading, i.e.,
  1939. to add numbers that are fragmented into several pieces.
  1940.  
  1941. Example:
  1942.  
  1943.   # initialize
  1944.  
  1945.   for ( $i = 0; $i < $n; $i++ )
  1946.   {
  1947.       $a[$i] = Bit::Vector->new($bits);
  1948.       $b[$i] = Bit::Vector->new($bits);
  1949.       $c[$i] = Bit::Vector->new($bits);
  1950.   }
  1951.  
  1952.   # fill @a and @b
  1953.  
  1954.   # $a[  0 ] is low order part,
  1955.   # $a[$n-1] is high order part,
  1956.   # and same for @b
  1957.  
  1958.   # add
  1959.  
  1960.   $carry = 0;
  1961.   for ( $i = 0; $i < $n; $i++ )
  1962.   {
  1963.       $carry = $c[$i]->add($a[$i],$b[$i],$carry);
  1964.   }
  1965.  
  1966. Note that it makes no difference to this method whether the numbers
  1967. in "C<$vec1>" and "C<$vec2>" are unsigned or signed (i.e., in two's
  1968. complement binary representation).
  1969.  
  1970. Note however that the return value (carry flag) is not meaningful
  1971. when the numbers are B<SIGNED>.
  1972.  
  1973. Moreover, when the numbers are signed, a special type of error can
  1974. occur which is commonly called an "overflow error".
  1975.  
  1976. An overflow error occurs when the sign of the result (its most
  1977. significant bit) is flipped (i.e., falsified) by a carry over
  1978. from the next-lower bit position ("MSB-1").
  1979.  
  1980. In fact matters are a bit more complicated than that: the overflow
  1981. flag is set to "true" whenever there is a carry over from bit
  1982. position MSB-1 to the most significant bit (MSB) but no carry
  1983. over from the MSB to the output carry flag, or vice-versa, i.e.,
  1984. when there is no carry over from bit position MSB-1 to the most
  1985. significant bit (MSB) but a carry over to the output carry flag.
  1986.  
  1987. Thus the overflow flag is the result of an exclusive-or operation
  1988. between incoming and outgoing carry over at the most significant
  1989. bit position.
  1990.  
  1991. =item *
  1992.  
  1993. C<$carry = $vec3-E<gt>subtract($vec1,$vec2,$carry);>
  1994.  
  1995. C<($carry,$overflow) = $vec3-E<gt>subtract($vec1,$vec2,$carry);>
  1996.  
  1997. This method subtracts the two numbers contained in bit vector
  1998. "C<$vec1>" and "C<$vec2>" with carry "C<$carry>" and stores the
  1999. result in bit vector "C<$vec3>".
  2000.  
  2001. I.e.,
  2002.             $vec3 = $vec1 - $vec2 - $carry
  2003.  
  2004. Note that the "C<$carry>" parameter is a boolean value, i.e.,
  2005. only its least significant bit is taken into account. (Think of
  2006. it as though "C<$carry &= 1;>" was always executed internally.)
  2007.  
  2008. In scalar context, the method returns a boolean value which
  2009. indicates if a carry over (to the next higher bit position)
  2010. has occured. In list context, the method returns the carry
  2011. and the overflow flag (in this order).
  2012.  
  2013. The overflow flag is true ("C<1>") if the sign (i.e., the most
  2014. significant bit) of the result is wrong. This can happen when
  2015. subtracting a very large negative number from a very large
  2016. positive number or vice-versa. See also further below.
  2017.  
  2018. The carry in- and output is needed mainly for cascading, i.e.,
  2019. to subtract numbers that are fragmented into several pieces.
  2020.  
  2021. Example:
  2022.  
  2023.   # initialize
  2024.  
  2025.   for ( $i = 0; $i < $n; $i++ )
  2026.   {
  2027.       $a[$i] = Bit::Vector->new($bits);
  2028.       $b[$i] = Bit::Vector->new($bits);
  2029.       $c[$i] = Bit::Vector->new($bits);
  2030.   }
  2031.  
  2032.   # fill @a and @b
  2033.  
  2034.   # $a[  0 ] is low order part,
  2035.   # $a[$n-1] is high order part,
  2036.   # and same for @b
  2037.  
  2038.   # subtract
  2039.  
  2040.   $carry = 0;
  2041.   for ( $i = 0; $i < $n; $i++ )
  2042.   {
  2043.       $carry = $c[$i]->subtract($a[$i],$b[$i],$carry);
  2044.   }
  2045.  
  2046. Note that it makes no difference to this method whether the numbers
  2047. in "C<$vec1>" and "C<$vec2>" are unsigned or signed (i.e., in two's
  2048. complement binary representation).
  2049.  
  2050. Note however that the return value (carry flag) is not meaningful
  2051. when the numbers are B<SIGNED>.
  2052.  
  2053. Moreover, when the numbers are signed, a special type of error can
  2054. occur which is commonly called an "overflow error".
  2055.  
  2056. An overflow error occurs when the sign of the result (its most
  2057. significant bit) is flipped (i.e., falsified) by a carry over
  2058. from the next-lower bit position ("MSB-1").
  2059.  
  2060. In fact matters are a bit more complicated than that: the overflow
  2061. flag is set to "true" whenever there is a carry over from bit
  2062. position MSB-1 to the most significant bit (MSB) but no carry
  2063. over from the MSB to the output carry flag, or vice-versa, i.e.,
  2064. when there is no carry over from bit position MSB-1 to the most
  2065. significant bit (MSB) but a carry over to the output carry flag.
  2066.  
  2067. Thus the overflow flag is the result of an exclusive-or operation
  2068. between incoming and outgoing carry over at the most significant
  2069. bit position.
  2070.  
  2071. =item *
  2072.  
  2073. C<$vec2-E<gt>Neg($vec1);>
  2074.  
  2075. C<$vec2-E<gt>Negate($vec1);>
  2076.  
  2077. This method calculates the two's complement of the number in bit
  2078. vector "C<$vec1>" and stores the result in bit vector "C<$vec2>".
  2079.  
  2080. Calculating the two's complement of a given number in binary representation
  2081. consists of inverting all bits and incrementing the result by one.
  2082.  
  2083. This is the same as changing the sign of the given number from "C<+>" to
  2084. "C<->" or vice-versa. In other words, applying this method twice on a given
  2085. number yields the original number again.
  2086.  
  2087. Note that in-place processing is also possible, i.e., "C<$vec1>" and
  2088. "C<$vec2>" may be identical.
  2089.  
  2090. Most importantly, beware that this method produces a counter-intuitive
  2091. result if the number contained in bit vector "C<$vec1>" is C<2 ^ (n-1)>
  2092. (i.e., "1000...0000"), where "C<n>" is the number of bits the given bit
  2093. vector contains: The negated value of this number is the number itself!
  2094.  
  2095. =item *
  2096.  
  2097. C<$vec2-E<gt>Abs($vec1);>
  2098.  
  2099. C<$vec2-E<gt>Absolute($vec1);>
  2100.  
  2101. Depending on the sign (i.e., the most significant bit) of the number in
  2102. bit vector "C<$vec1>", the contents of bit vector "C<$vec1>" are copied
  2103. to bit vector "C<$vec2>" either with the method "C<Copy()>" (if the number
  2104. in bit vector "C<$vec1>" is positive), or with "C<Negate()>" (if the number
  2105. in bit vector "C<$vec1>" is negative).
  2106.  
  2107. In other words, this method calculates the absolute value of the number
  2108. in bit vector "C<$vec1>" and stores the result in bit vector "C<$vec2>".
  2109.  
  2110. Note that in-place processing is also possible, i.e., "C<$vec1>" and
  2111. "C<$vec2>" may be identical.
  2112.  
  2113. Most importantly, beware that this method produces a counter-intuitive
  2114. result if the number contained in bit vector "C<$vec1>" is C<2 ^ (n-1)>
  2115. (i.e., "1000...0000"), where "C<n>" is the number of bits the given bit
  2116. vector contains: The absolute value of this number is the number itself,
  2117. even though this number is still negative by definition (the most
  2118. significant bit is still set)!
  2119.  
  2120. =item *
  2121.  
  2122. C<$sign = $vector-E<gt>Sign();>
  2123.  
  2124. This method returns "C<0>" if all bits in the given bit vector are cleared,
  2125. i.e., if the given bit vector contains the number "C<0>", or if the given
  2126. bit vector has a length of zero (contains no bits at all).
  2127.  
  2128. If not all bits are cleared, this method returns "C<-1>" if the most
  2129. significant bit is set (i.e., if the bit vector contains a negative
  2130. number), or "C<1>" otherwise (i.e., if the bit vector contains a
  2131. positive number).
  2132.  
  2133. =item *
  2134.  
  2135. C<$vec3-E<gt>Multiply($vec1,$vec2);>
  2136.  
  2137. This method multiplies the two numbers contained in bit vector "C<$vec1>"
  2138. and "C<$vec2>" and stores the result in bit vector "C<$vec3>".
  2139.  
  2140. Note that this method regards its arguments as B<SIGNED>.
  2141.  
  2142. If you want to make sure that a large number can never be treated as being
  2143. negative by mistake, make your bit vectors at least one bit longer than the
  2144. largest number you wish to represent, right from the start, or proceed as
  2145. follows:
  2146.  
  2147.     $msb1 = $vec1->msb();
  2148.     $msb2 = $vec2->msb();
  2149.     $vec1->Resize($vec1->Size()+1);
  2150.     $vec2->Resize($vec2->Size()+1);
  2151.     $vec3->Resize($vec3->Size()+1);
  2152.     $vec1->MSB($msb1);
  2153.     $vec2->MSB($msb2);
  2154.     $vec3->Multiply($vec1,$vec2);
  2155.  
  2156. Note also that all three bit vector arguments must in principle obey the
  2157. rule of matching sizes, but that the bit vector "C<$vec3>" may be larger
  2158. than the two factors "C<$vec1>" and "C<$vec2>".
  2159.  
  2160. In fact multiplying two binary numbers with "C<n>" bits may yield a result
  2161. which is at most "C<2n>" bits long.
  2162.  
  2163. Therefore, it is usually a good idea to let bit vector "C<$vec3>" have
  2164. twice the size of bit vector "C<$vec1>" and "C<$vec2>", unless you are
  2165. absolutely sure that the result will fit into a bit vector of the same
  2166. size as the two factors.
  2167.  
  2168. If you are wrong, a fatal "numeric overflow error" will occur.
  2169.  
  2170. Finally, note that in-place processing is possible, i.e., "C<$vec3>"
  2171. may be identical with "C<$vec1>" or "C<$vec2>", or both.
  2172.  
  2173. =item *
  2174.  
  2175. C<$quot-E<gt>Divide($vec1,$vec2,$rest);>
  2176.  
  2177. This method divides the two numbers contained in bit vector "C<$vec1>"
  2178. and "C<$vec2>" and stores the quotient in bit vector "C<$quot>" and
  2179. the remainder in bit vector "C<$rest>".
  2180.  
  2181. I.e.,
  2182.             $quot = $vec1 / $vec2;  #  div
  2183.             $rest = $vec1 % $vec2;  #  mod
  2184.  
  2185. Therefore, "C<$quot>" and "C<$rest>" must be two B<DISTINCT> bit vectors,
  2186. or a fatal "result vector(s) must be distinct" error will occur.
  2187.  
  2188. Note also that a fatal "division by zero error" will occur if "C<$vec2>"
  2189. is equal to zero.
  2190.  
  2191. Note further that this method regards its arguments as B<SIGNED>.
  2192.  
  2193. If you want to make sure that a large number can never be treated as being
  2194. negative by mistake, make your bit vectors at least one bit longer than the
  2195. largest number you wish to represent, right from the start, or proceed as
  2196. follows:
  2197.  
  2198.     $msb1 = $vec1->msb();
  2199.     $msb2 = $vec2->msb();
  2200.     $vec1->Resize($vec1->Size()+1);
  2201.     $vec2->Resize($vec2->Size()+1);
  2202.     $quot->Resize($quot->Size()+1);
  2203.     $rest->Resize($rest->Size()+1);
  2204.     $vec1->MSB($msb1);
  2205.     $vec2->MSB($msb2);
  2206.     $quot->Divide($vec1,$vec2,$rest);
  2207.  
  2208. Finally, note that in-place processing is possible, i.e., "C<$quot>"
  2209. may be identical with "C<$vec1>" or "C<$vec2>" or both, and "C<$rest>"
  2210. may also be identical with "C<$vec1>" or "C<$vec2>" or both, as long
  2211. as "C<$quot>" and "C<$rest>" are distinct. (!)
  2212.  
  2213. =item *
  2214.  
  2215. C<$vecgcd-E<gt>GCD($veca,$vecb);>
  2216.  
  2217. This method calculates the "Greatest Common Divisor" of the two numbers
  2218. contained in bit vector "C<$veca>" and "C<$vecb>" and stores the result
  2219. in bit vector "C<$vecgcd>".
  2220.  
  2221. The method uses Euklid's algorithm internally:
  2222.  
  2223.     int GCD(int a, int b)
  2224.     {
  2225.         int t;
  2226.  
  2227.         while (b != 0)
  2228.         {
  2229.             t = a % b; /* = remainder of (a div b) */
  2230.             a = b;
  2231.             b = t;
  2232.         }
  2233.         return(a);
  2234.     }
  2235.  
  2236. Note that C<GCD(z,0) == GCD(0,z) == z>.
  2237.  
  2238. =item *
  2239.  
  2240. C<$vecgcd-E<gt>GCD($vecx,$vecy,$veca,$vecb);>
  2241.  
  2242. This variant of the "GCD" method calculates the "Greatest Common Divisor"
  2243. of the two numbers contained in bit vector "C<$veca>" and "C<$vecb>" and
  2244. stores the result in bit vector "C<$vecgcd>".
  2245.  
  2246. Moreover, it determines the two factors which are necessary in order to
  2247. represent the greatest common divisor as a linear combination of its two
  2248. arguments, i.e., the two factors C<"x"> and C<"y"> so that
  2249. C<GCD(a,b) == x * a + y * b>, and stores them in bit vector "C<$vecx>"
  2250. and "C<$vecy>", respectively.
  2251.  
  2252. For example:
  2253.  
  2254.   a = 2322
  2255.   b =  654
  2256.  
  2257.   GCD( 2322, 654 ) == 6
  2258.  
  2259.   x =  20
  2260.   y = -71
  2261.  
  2262.   20 * 2322 - 71 * 654 == 6
  2263.  
  2264. Please see http://www.cut-the-knot.org/blue/extension.shtml
  2265. for an explanation of how this extension of Euklid's algorithm works.
  2266.  
  2267. =item *
  2268.  
  2269. C<$vec3-E<gt>Power($vec1,$vec2);>
  2270.  
  2271. This method calculates the exponentiation of base "C<$vec1>" elevated to
  2272. the "C<$vec2>" power, i.e., "C<$vec1 ** $vec2>", and stores the result
  2273. in bit vector "C<$vec3>".
  2274.  
  2275. The method uses an efficient divide-and-conquer algorithm:
  2276.  
  2277. Suppose the exponent is (decimal) 13, for example. The binary
  2278. representation of this exponent is "1101".
  2279.  
  2280. This means we want to calculate
  2281.  
  2282.   $vec1 * $vec1 * $vec1 * $vec1 * $vec1 * $vec1 * $vec1 * $vec1 *
  2283.   $vec1 * $vec1 * $vec1 * $vec1 *
  2284.   $vec1
  2285.  
  2286. That is, "C<$vec1>" multiplied with itself 13 times. The grouping
  2287. into lines above is no coincidence. The first line comprises 8
  2288. factors, the second contains 4, and the last line just one. This
  2289. just happens to be the binary representation of 13. C<;-)>
  2290.  
  2291. We then calculate a series of squares (of squares of squares...) of
  2292. the base, i.e.,
  2293.  
  2294.   $power[0] = $vec1;
  2295.   $power[1] = $vec1 * $vec1;
  2296.   $power[2] = $power[1] * $power[1];
  2297.   $power[3] = $power[2] * $power[2];
  2298.   etc.
  2299.  
  2300. To calculate the power of our example, we simply initialize our result
  2301. with 1 and consecutively multiply it with the items of the series of
  2302. powers we just calculated, if the corresponding bit of the binary
  2303. representation of the exponent is set:
  2304.  
  2305.   $result = 1;
  2306.   $result *= $power[0] if ($vec2 & 1);
  2307.   $result *= $power[1] if ($vec2 & 2);
  2308.   $result *= $power[2] if ($vec2 & 4);
  2309.   $result *= $power[3] if ($vec2 & 8);
  2310.   etc.
  2311.  
  2312. The bit vector "C<$vec3>" must be of the same size as the base
  2313. "C<$vec1>" or greater. "C<$vec3>" and "C<$vec1>" may be the same
  2314. vector (i.e., in-place calculation as in "C<$vec1 **= $vec2;>" is
  2315. possible), but "C<$vec3>" and "C<$vec2>" must be distinct. Finally,
  2316. the exponent "C<$vec2>" must be positive. A fatal error occurs if
  2317. any of these conditions is not met.
  2318.  
  2319. =item *
  2320.  
  2321. C<$vector-E<gt>Block_Store($buffer);>
  2322.  
  2323. This method allows you to load the contents of a given bit vector in
  2324. one go.
  2325.  
  2326. This is useful when you store the contents of a bit vector in a file,
  2327. for instance (using method "C<Block_Read()>"), and when you want to
  2328. restore the previously saved bit vector.
  2329.  
  2330. For this, "C<$buffer>" B<MUST> be a string (B<NO> automatic conversion
  2331. from numeric to string is provided here as would normally in Perl!)
  2332. containing the bit vector in "low order byte first" order.
  2333.  
  2334. If the given string is shorter than what is needed to completely fill
  2335. the given bit vector, the remaining (most significant) bytes of the
  2336. bit vector are filled with zeros, i.e., the previous contents of the
  2337. bit vector are always erased completely.
  2338.  
  2339. If the given string is longer than what is needed to completely fill
  2340. the given bit vector, the superfluous bytes are simply ignored.
  2341.  
  2342. See L<perlfunc/sysread> for how to read in the contents of "C<$buffer>"
  2343. from a file prior to passing it to this method.
  2344.  
  2345. =item *
  2346.  
  2347. C<$buffer = $vector-E<gt>Block_Read();>
  2348.  
  2349. This method allows you to export the contents of a given bit vector in
  2350. one block.
  2351.  
  2352. This is useful when you want to save the contents of a bit vector for
  2353. later, for instance in a file.
  2354.  
  2355. The advantage of this method is that it allows you to do so in the
  2356. compactest possible format, in binary.
  2357.  
  2358. The method returns a Perl string which contains an exact copy of the
  2359. contents of the given bit vector in "low order byte first" order.
  2360.  
  2361. See L<perlfunc/syswrite> for how to write the data from this string
  2362. to a file.
  2363.  
  2364. =item *
  2365.  
  2366. C<$size = $vector-E<gt>Word_Size();>
  2367.  
  2368. Each bit vector is internally organized as an array of machine words.
  2369.  
  2370. The methods whose names begin with "Word_" allow you to access this
  2371. internal array of machine words.
  2372.  
  2373. Note that because the size of a machine word may vary from system to
  2374. system, these methods are inherently B<MACHINE-DEPENDENT>!
  2375.  
  2376. Therefore, B<DO NOT USE> these methods unless you are absolutely certain
  2377. that portability of your code is not an issue!
  2378.  
  2379. You have been warned!
  2380.  
  2381. To be machine-independent, use the methods whose names begin with "C<Chunk_>"
  2382. instead, with chunk sizes no greater than 32 bits.
  2383.  
  2384. The method "C<Word_Size()>" returns the number of machine words that the
  2385. internal array of words of the given bit vector contains.
  2386.  
  2387. This is similar in function to the term "C<scalar(@array)>" for a Perl array.
  2388.  
  2389. =item *
  2390.  
  2391. C<$vector-E<gt>Word_Store($offset,$word);>
  2392.  
  2393. This method allows you to store a given value "C<$word>" at a given
  2394. position "C<$offset>" in the internal array of words of the given
  2395. bit vector.
  2396.  
  2397. Note that "C<$offset>" must lie in the permitted range between "C<0>"
  2398. and "C<$vector-E<gt>Word_Size()-1>", or a fatal "offset out of range"
  2399. error will occur.
  2400.  
  2401. This method is similar in function to the expression
  2402. "C<$array[$offset] = $word;>" for a Perl array.
  2403.  
  2404. =item *
  2405.  
  2406. C<$word = $vector-E<gt>Word_Read($offset);>
  2407.  
  2408. This method allows you to access the value of a given machine word
  2409. at position "C<$offset>" in the internal array of words of the given
  2410. bit vector.
  2411.  
  2412. Note that "C<$offset>" must lie in the permitted range between "C<0>"
  2413. and "C<$vector-E<gt>Word_Size()-1>", or a fatal "offset out of range"
  2414. error will occur.
  2415.  
  2416. This method is similar in function to the expression
  2417. "C<$word = $array[$offset];>" for a Perl array.
  2418.  
  2419. =item *
  2420.  
  2421. C<$vector-E<gt>Word_List_Store(@words);>
  2422.  
  2423. This method allows you to store a list of values "C<@words>" in the
  2424. internal array of machine words of the given bit vector.
  2425.  
  2426. Thereby the B<LEFTMOST> value in the list ("C<$words[0]>") is stored
  2427. in the B<LEAST> significant word of the internal array of words (the
  2428. one with offset "C<0>"), the next value from the list ("C<$words[1]>")
  2429. is stored in the word with offset "C<1>", and so on, as intuitively
  2430. expected.
  2431.  
  2432. If the list "C<@words>" contains fewer elements than the internal
  2433. array of words of the given bit vector contains machine words,
  2434. the remaining (most significant) words are filled with zeros.
  2435.  
  2436. If the list "C<@words>" contains more elements than the internal
  2437. array of words of the given bit vector contains machine words,
  2438. the superfluous values are simply ignored.
  2439.  
  2440. This method is comparable in function to the expression
  2441. "C<@array = @words;>" for a Perl array.
  2442.  
  2443. =item *
  2444.  
  2445. C<@words = $vector-E<gt>Word_List_Read();>
  2446.  
  2447. This method allows you to retrieve the internal array of machine
  2448. words of the given bit vector all at once.
  2449.  
  2450. Thereby the B<LEFTMOST> value in the returned list ("C<$words[0]>")
  2451. is the B<LEAST> significant word from the given bit vector, and the
  2452. B<RIGHTMOST> value in the returned list ("C<$words[$#words]>") is
  2453. the B<MOST> significant word of the given bit vector.
  2454.  
  2455. This method is similar in function to the expression
  2456. "C<@words = @array;>" for a Perl array.
  2457.  
  2458. =item *
  2459.  
  2460. C<$vector-E<gt>Word_Insert($offset,$count);>
  2461.  
  2462. This method inserts "C<$count>" empty new machine words at position
  2463. "C<$offset>" in the internal array of words of the given bit vector.
  2464.  
  2465. The "C<$count>" most significant words are lost, and all words starting
  2466. with word number "C<$offset>" up to and including word number
  2467. "C<$vector-E<gt>Word_Size()-$count-1>" are moved up by "C<$count>" places.
  2468.  
  2469. The now vacant "C<$count>" words starting at word number "C<$offset>"
  2470. (up to and including word number "C<$offset+$count-1>") are then set
  2471. to zero (cleared).
  2472.  
  2473. Note that this method does B<NOT> increase the size of the given bit
  2474. vector, i.e., the bit vector is B<NOT> extended at its upper end to
  2475. "rescue" the "C<$count>" uppermost (most significant) words - instead,
  2476. these words are lost forever.
  2477.  
  2478. If you don't want this to happen, you have to increase the size of the
  2479. given bit vector B<EXPLICITLY> and B<BEFORE> you perform the "Insert"
  2480. operation, with a statement such as the following:
  2481.  
  2482.   $vector->Resize($vector->Size() + $count * Bit::Vector->Word_Bits());
  2483.  
  2484. Note also that "C<$offset>" must lie in the permitted range between
  2485. "C<0>" and "C<$vector-E<gt>Word_Size()-1>", or a fatal "offset out
  2486. of range" error will occur.
  2487.  
  2488. If the term "C<$offset + $count>" exceeds "C<$vector-E<gt>Word_Size()-1>",
  2489. all the words starting with word number "C<$offset>" up to word number
  2490. "C<$vector-E<gt>Word_Size()-1>" are simply cleared.
  2491.  
  2492. =item *
  2493.  
  2494. C<$vector-E<gt>Word_Delete($offset,$count);>
  2495.  
  2496. This method deletes, i.e., removes the words starting at position
  2497. "C<$offset>" up to and including word number "C<$offset+$count-1>"
  2498. from the internal array of machine words of the given bit vector.
  2499.  
  2500. The remaining uppermost words (starting at position "C<$offset+$count>"
  2501. up to and including word number "C<$vector-E<gt>Word_Size()-1>") are
  2502. moved down by "C<$count>" places.
  2503.  
  2504. The now vacant uppermost (most significant) "C<$count>" words are then
  2505. set to zero (cleared).
  2506.  
  2507. Note that this method does B<NOT> decrease the size of the given bit
  2508. vector, i.e., the bit vector is B<NOT> clipped at its upper end to
  2509. "get rid of" the vacant "C<$count>" uppermost words.
  2510.  
  2511. If you don't want this, i.e., if you want the bit vector to shrink
  2512. accordingly, you have to do so B<EXPLICITLY> and B<AFTER> the "Delete"
  2513. operation, with a couple of statements such as these:
  2514.  
  2515.   $bits = $vector->Size();
  2516.   $count *= Bit::Vector->Word_Bits();
  2517.   if ($count > $bits) { $count = $bits; }
  2518.   $vector->Resize($bits - $count);
  2519.  
  2520. Note also that "C<$offset>" must lie in the permitted range between
  2521. "C<0>" and "C<$vector-E<gt>Word_Size()-1>", or a fatal "offset out
  2522. of range" error will occur.
  2523.  
  2524. If the term "C<$offset + $count>" exceeds "C<$vector-E<gt>Word_Size()-1>",
  2525. all the words starting with word number "C<$offset>" up to word number
  2526. "C<$vector-E<gt>Word_Size()-1>" are simply cleared.
  2527.  
  2528. =item *
  2529.  
  2530. C<$vector-E<gt>Chunk_Store($chunksize,$offset,$chunk);>
  2531.  
  2532. This method allows you to set more than one bit at a time with
  2533. different values.
  2534.  
  2535. You can access chunks (i.e., ranges of contiguous bits) between
  2536. one and at most "C<Bit::Vector-E<gt>Long_Bits()>" bits wide.
  2537.  
  2538. In order to be portable, though, you should never use chunk sizes
  2539. larger than 32 bits.
  2540.  
  2541. If the given "C<$chunksize>" does not lie between "C<1>" and
  2542. "C<Bit::Vector-E<gt>Long_Bits()>", a fatal "chunk size out of range"
  2543. error will occur.
  2544.  
  2545. The method copies the "C<$chunksize>" least significant bits
  2546. from the value "C<$chunk>" to the given bit vector, starting at
  2547. bit position "C<$offset>" and proceeding upwards until bit number
  2548. "C<$offset+$chunksize-1>".
  2549.  
  2550. (I.e., bit number "C<0>" of "C<$chunk>" becomes bit number "C<$offset>"
  2551. in the given bit vector, and bit number "C<$chunksize-1>" becomes
  2552. bit number "C<$offset+$chunksize-1>".)
  2553.  
  2554. If the term "C<$offset+$chunksize-1>" exceeds "C<$vector-E<gt>Size()-1>",
  2555. the corresponding superfluous (most significant) bits from "C<$chunk>"
  2556. are simply ignored.
  2557.  
  2558. Note that "C<$offset>" itself must lie in the permitted range between
  2559. "C<0>" and "C<$vector-E<gt>Size()-1>", or a fatal "offset out of range"
  2560. error will occur.
  2561.  
  2562. This method (as well as the other "C<Chunk_>" methods) is useful, for
  2563. example, when you are reading in data in chunks of, say, 8 bits, which
  2564. you need to access later, say, using 16 bits at a time (like audio CD
  2565. wave files, for instance).
  2566.  
  2567. =item *
  2568.  
  2569. C<$chunk = $vector-E<gt>Chunk_Read($chunksize,$offset);>
  2570.  
  2571. This method allows you to read the values of more than one bit at
  2572. a time.
  2573.  
  2574. You can read chunks (i.e., ranges of contiguous bits) between
  2575. one and at most "C<Bit::Vector-E<gt>Long_Bits()>" bits wide.
  2576.  
  2577. In order to be portable, though, you should never use chunk sizes
  2578. larger than 32 bits.
  2579.  
  2580. If the given "C<$chunksize>" does not lie between "C<1>" and
  2581. "C<Bit::Vector-E<gt>Long_Bits()>", a fatal "chunk size out of range"
  2582. error will occur.
  2583.  
  2584. The method returns the "C<$chunksize>" bits from the given bit vector
  2585. starting at bit position "C<$offset>" and proceeding upwards until
  2586. bit number "C<$offset+$chunksize-1>".
  2587.  
  2588. (I.e., bit number "C<$offset>" of the given bit vector becomes bit number
  2589. "C<0>" of the returned value, and bit number "C<$offset+$chunksize-1>"
  2590. becomes bit number "C<$chunksize-1>".)
  2591.  
  2592. If the term "C<$offset+$chunksize-1>" exceeds "C<$vector-E<gt>Size()-1>",
  2593. the non-existent bits are simply not returned.
  2594.  
  2595. Note that "C<$offset>" itself must lie in the permitted range between
  2596. "C<0>" and "C<$vector-E<gt>Size()-1>", or a fatal "offset out of range"
  2597. error will occur.
  2598.  
  2599. =item *
  2600.  
  2601. C<$vector-E<gt>Chunk_List_Store($chunksize,@chunks);>
  2602.  
  2603. This method allows you to fill the given bit vector with a list of
  2604. data packets ("chunks") of any size ("C<$chunksize>") you like
  2605. (within certain limits).
  2606.  
  2607. In fact the given "C<$chunksize>" must lie in the range between "C<1>"
  2608. and "C<Bit::Vector-E<gt>Long_Bits()>", or a fatal "chunk size out of
  2609. range" error will occur.
  2610.  
  2611. In order to be portable, though, you should never use chunk sizes
  2612. larger than 32 bits.
  2613.  
  2614. The given bit vector is thereby filled in ascending order: The first
  2615. chunk from the list (i.e., "C<$chunks[0]>") fills the "C<$chunksize>"
  2616. least significant bits, the next chunk from the list ("C<$chunks[1]>")
  2617. fills the bits number "C<$chunksize>" to number "C<2*$chunksize-1>",
  2618. the third chunk ("C<$chunks[2]>") fills the bits number "C<2*$chunksize>",
  2619. to number "C<3*$chunksize-1>", and so on.
  2620.  
  2621. If there a less chunks in the list than are needed to fill the entire
  2622. bit vector, the remaining (most significant) bits are cleared, i.e.,
  2623. the previous contents of the given bit vector are always erased completely.
  2624.  
  2625. If there are more chunks in the list than are needed to fill the entire
  2626. bit vector, and/or if a chunk extends beyond "C<$vector-E<gt>Size()-1>"
  2627. (which happens whenever "C<$vector-E<gt>Size()>" is not a multiple of
  2628. "C<$chunksize>"), the superfluous chunks and/or bits are simply ignored.
  2629.  
  2630. The method is useful, for example (and among many other applications),
  2631. for the conversion of packet sizes in a data stream.
  2632.  
  2633. This method can also be used to store an octal string in a given
  2634. bit vector:
  2635.  
  2636.   $vector->Chunk_List_Store(3, split(//, reverse $string));
  2637.  
  2638. Note however that unlike the conversion methods "C<from_Hex()>",
  2639. "C<from_Bin()>", "C<from_Dec()>" and "C<from_Enum()>",
  2640. this statement does not include any syntax checking, i.e.,
  2641. it may fail silently, without warning.
  2642.  
  2643. To perform syntax checking, add the following statements:
  2644.  
  2645.   if ($string =~ /^[0-7]+$/)
  2646.   {
  2647.       # okay, go ahead with conversion as shown above
  2648.   }
  2649.   else
  2650.   {
  2651.       # error, string contains other than octal characters
  2652.   }
  2653.  
  2654. Another application is to store a repetitive pattern in a given
  2655. bit vector:
  2656.  
  2657.   $pattern = 0xDEADBEEF;
  2658.   $length = 32;            # = length of $pattern in bits
  2659.   $size = $vector->Size();
  2660.   $factor = int($size / $length);
  2661.   if ($size % $length) { $factor++; }
  2662.   $vector->Chunk_List_Store($length, ($pattern) x $factor);
  2663.  
  2664. =item *
  2665.  
  2666. C<@chunks = $vector-E<gt>Chunk_List_Read($chunksize);>
  2667.  
  2668. This method allows you to access the contents of the given bit vector in
  2669. form of a list of data packets ("chunks") of a size ("C<$chunksize>")
  2670. of your choosing (within certain limits).
  2671.  
  2672. In fact the given "C<$chunksize>" must lie in the range between "C<1>"
  2673. and "C<Bit::Vector-E<gt>Long_Bits()>", or a fatal "chunk size out of
  2674. range" error will occur.
  2675.  
  2676. In order to be portable, though, you should never use chunk sizes
  2677. larger than 32 bits.
  2678.  
  2679. The given bit vector is thereby read in ascending order: The
  2680. "C<$chunksize>" least significant bits (bits number "C<0>" to
  2681. "C<$chunksize-1>") become the first chunk in the returned list
  2682. (i.e., "C<$chunks[0]>"). The bits number "C<$chunksize>" to
  2683. "C<2*$chunksize-1>" become the next chunk in the list
  2684. ("C<$chunks[1]>"), and so on.
  2685.  
  2686. If "C<$vector-E<gt>Size()>" is not a multiple of "C<$chunksize>",
  2687. the last chunk in the list will contain fewer bits than "C<$chunksize>".
  2688.  
  2689. B<BEWARE> that for large bit vectors and/or small values of "C<$chunksize>",
  2690. the number of returned list elements can be extremely large! B<BE CAREFUL!>
  2691.  
  2692. You could blow up your application with lack of memory (each list element
  2693. is a full-grown Perl scalar, internally, with an associated memory overhead
  2694. for its administration!) or at least cause a noticeable, more or less
  2695. long-lasting "freeze" of your application!
  2696.  
  2697. Possible applications:
  2698.  
  2699. The method is especially useful in the conversion of packet sizes in
  2700. a data stream.
  2701.  
  2702. This method can also be used to convert a given bit vector to a string
  2703. of octal numbers:
  2704.  
  2705.   $string = reverse join('', $vector->Chunk_List_Read(3));
  2706.  
  2707. =item *
  2708.  
  2709. C<$vector-E<gt>Index_List_Remove(@indices);>
  2710.  
  2711. This method allows you to specify a list of indices of bits which
  2712. should be turned off in the given bit vector.
  2713.  
  2714. In fact this method is a shortcut for
  2715.  
  2716.     foreach $index (@indices)
  2717.     {
  2718.         $vector->Bit_Off($index);
  2719.     }
  2720.  
  2721. In contrast to all other import methods in this module, this method
  2722. does B<NOT> clear the given bit vector before processing its list
  2723. of arguments.
  2724.  
  2725. Instead, this method allows you to accumulate the results of various
  2726. consecutive calls.
  2727.  
  2728. (The same holds for the method "C<Index_List_Store()>". As a
  2729. consequence, you can "wipe out" what you did using the method
  2730. "C<Index_List_Remove()>" by passing the identical argument list
  2731. to the method "C<Index_List_Store()>".)
  2732.  
  2733. =item *
  2734.  
  2735. C<$vector-E<gt>Index_List_Store(@indices);>
  2736.  
  2737. This method allows you to specify a list of indices of bits which
  2738. should be turned on in the given bit vector.
  2739.  
  2740. In fact this method is a shortcut for
  2741.  
  2742.     foreach $index (@indices)
  2743.     {
  2744.         $vector->Bit_On($index);
  2745.     }
  2746.  
  2747. In contrast to all other import methods in this module, this method
  2748. does B<NOT> clear the given bit vector before processing its list
  2749. of arguments.
  2750.  
  2751. Instead, this method allows you to accumulate the results of various
  2752. consecutive calls.
  2753.  
  2754. (The same holds for the method "C<Index_List_Remove()>". As a
  2755. consequence, you can "wipe out" what you did using the method
  2756. "C<Index_List_Store()>" by passing the identical argument list
  2757. to the method "C<Index_List_Remove()>".)
  2758.  
  2759. =item *
  2760.  
  2761. C<@indices = $vector-E<gt>Index_List_Read();>
  2762.  
  2763. This method returns a list of Perl scalars.
  2764.  
  2765. The list contains one scalar for each set bit in the given
  2766. bit vector.
  2767.  
  2768. B<BEWARE> that for large bit vectors, this can result in a literally
  2769. overwhelming number of list elements! B<BE CAREFUL!> You could run
  2770. out of memory or slow down your application considerably!
  2771.  
  2772. Each scalar contains the number of the index corresponding to
  2773. the bit in question.
  2774.  
  2775. These indices are always returned in ascending order.
  2776.  
  2777. If the given bit vector is empty (contains only cleared bits)
  2778. or if it has a length of zero (if it contains no bits at all),
  2779. the method returns an empty list.
  2780.  
  2781. This method can be useful, for instance, to obtain a list of
  2782. prime numbers:
  2783.  
  2784.     $limit = 1000; # or whatever
  2785.     $vector = Bit::Vector->new($limit+1);
  2786.     $vector->Primes();
  2787.     @primes = $vector->Index_List_Read();
  2788.  
  2789. =item *
  2790.  
  2791. C<$vec3-E<gt>Or($vec1,$vec2);>
  2792.  
  2793. C<$set3-E<gt>Union($set1,$set2);>
  2794.  
  2795. This method calculates the union of "C<$set1>" and "C<$set2>" and stores
  2796. the result in "C<$set3>".
  2797.  
  2798. This is usually written as "C<$set3 = $set1 u $set2>" in set theory
  2799. (where "u" is the "cup" operator).
  2800.  
  2801. (On systems where the "cup" character is unavailable this operator
  2802. is often denoted by a plus sign "+".)
  2803.  
  2804. In-place calculation is also possible, i.e., "C<$set3>" may be identical
  2805. with "C<$set1>" or "C<$set2>" or both.
  2806.  
  2807. =item *
  2808.  
  2809. C<$vec3-E<gt>And($vec1,$vec2);>
  2810.  
  2811. C<$set3-E<gt>Intersection($set1,$set2);>
  2812.  
  2813. This method calculates the intersection of "C<$set1>" and "C<$set2>" and
  2814. stores the result in "C<$set3>".
  2815.  
  2816. This is usually written as "C<$set3 = $set1 n $set2>" in set theory
  2817. (where "n" is the "cap" operator).
  2818.  
  2819. (On systems where the "cap" character is unavailable this operator
  2820. is often denoted by an asterisk "*".)
  2821.  
  2822. In-place calculation is also possible, i.e., "C<$set3>" may be identical
  2823. with "C<$set1>" or "C<$set2>" or both.
  2824.  
  2825. =item *
  2826.  
  2827. C<$vec3-E<gt>AndNot($vec1,$vec2);>
  2828.  
  2829. C<$set3-E<gt>Difference($set1,$set2);>
  2830.  
  2831. This method calculates the difference of "C<$set1>" less "C<$set2>" and
  2832. stores the result in "C<$set3>".
  2833.  
  2834. This is usually written as "C<$set3 = $set1 \ $set2>" in set theory
  2835. (where "\" is the "less" operator).
  2836.  
  2837. In-place calculation is also possible, i.e., "C<$set3>" may be identical
  2838. with "C<$set1>" or "C<$set2>" or both.
  2839.  
  2840. =item *
  2841.  
  2842. C<$vec3-E<gt>Xor($vec1,$vec2);>
  2843.  
  2844. C<$set3-E<gt>ExclusiveOr($set1,$set2);>
  2845.  
  2846. This method calculates the symmetric difference of "C<$set1>" and "C<$set2>"
  2847. and stores the result in "C<$set3>".
  2848.  
  2849. This can be written as "C<$set3 = ($set1 u $set2) \ ($set1 n $set2)>" in set
  2850. theory (the union of the two sets less their intersection).
  2851.  
  2852. When sets are implemented as bit vectors then the above formula is
  2853. equivalent to the exclusive-or between corresponding bits of the two
  2854. bit vectors (hence the name of this method).
  2855.  
  2856. Note that this method is also much more efficient than evaluating the
  2857. above formula explicitly since it uses a built-in machine language
  2858. instruction internally.
  2859.  
  2860. In-place calculation is also possible, i.e., "C<$set3>" may be identical
  2861. with "C<$set1>" or "C<$set2>" or both.
  2862.  
  2863. =item *
  2864.  
  2865. C<$vec2-E<gt>Not($vec1);>
  2866.  
  2867. C<$set2-E<gt>Complement($set1);>
  2868.  
  2869. This method calculates the complement of "C<$set1>" and stores the result
  2870. in "C<$set2>".
  2871.  
  2872. In "big integer" arithmetic, this is equivalent to calculating the one's
  2873. complement of the number stored in the bit vector "C<$set1>" in binary
  2874. representation.
  2875.  
  2876. In-place calculation is also possible, i.e., "C<$set2>" may be identical
  2877. with "C<$set1>".
  2878.  
  2879. =item *
  2880.  
  2881. C<if ($set1-E<gt>subset($set2))>
  2882.  
  2883. Returns "true" ("C<1>") if "C<$set1>" is a subset of "C<$set2>"
  2884. (i.e., completely contained in "C<$set2>") and "false" ("C<0>")
  2885. otherwise.
  2886.  
  2887. This means that any bit which is set ("C<1>") in "C<$set1>" must
  2888. also be set in "C<$set2>", but "C<$set2>" may contain set bits
  2889. which are not set in "C<$set1>", in order for the condition
  2890. of subset relationship to be true between these two sets.
  2891.  
  2892. Note that by definition, if two sets are identical, they are
  2893. also subsets (and also supersets) of each other.
  2894.  
  2895. =item *
  2896.  
  2897. C<$norm = $set-E<gt>Norm();>
  2898.  
  2899. Returns the norm (number of bits which are set) of the given vector.
  2900.  
  2901. This is equivalent to the number of elements contained in the given
  2902. set.
  2903.  
  2904. =item *
  2905.  
  2906. C<$min = $set-E<gt>Min();>
  2907.  
  2908. Returns the minimum of the given set, i.e., the minimum of all
  2909. indices of all set bits in the given bit vector "C<$set>".
  2910.  
  2911. If the set is empty (no set bits), plus infinity (represented
  2912. by the constant "MAX_LONG" on your system) is returned.
  2913.  
  2914. (This constant is usually S<2 ^ (n-1) - 1>, where "C<n>" is the
  2915. number of bits of an unsigned long on your machine.)
  2916.  
  2917. =item *
  2918.  
  2919. C<$max = $set-E<gt>Max();>
  2920.  
  2921. Returns the maximum of the given set, i.e., the maximum of all
  2922. indices of all set bits in the given bit vector "C<$set>".
  2923.  
  2924. If the set is empty (no set bits), minus infinity (represented
  2925. by the constant "MIN_LONG" on your system) is returned.
  2926.  
  2927. (This constant is usually S<-(2 ^ (n-1) - 1)> or S<-(2 ^ (n-1))>,
  2928. where "C<n>" is the number of bits of an unsigned long on your machine.)
  2929.  
  2930. =item *
  2931.  
  2932. C<$m3-E<gt>Multiplication($r3,$c3,$m1,$r1,$c1,$m2,$r2,$c2);>
  2933.  
  2934. This method multiplies two boolean matrices (stored as bit vectors)
  2935. "C<$m1>" and "C<$m2>" and stores the result in matrix "C<$m3>".
  2936.  
  2937. The method uses the binary "xor" operation ("C<^>") as the boolean
  2938. addition operator ("C<+>").
  2939.  
  2940. An exception is raised if the product of the number of rows and
  2941. columns of any of the three matrices differs from the actual size
  2942. of their underlying bit vector.
  2943.  
  2944. An exception is also raised if the numbers of rows and columns
  2945. of the three matrices do not harmonize in the required manner:
  2946.  
  2947.   rows3 == rows1
  2948.   cols3 == cols2
  2949.   cols1 == rows2
  2950.  
  2951. This method is used by the module "Math::MatrixBool".
  2952.  
  2953. See L<Math::MatrixBool(3)> for details.
  2954.  
  2955. =item *
  2956.  
  2957. C<$m3-E<gt>Product($r3,$c3,$m1,$r1,$c1,$m2,$r2,$c2);>
  2958.  
  2959. This method multiplies two boolean matrices (stored as bit vectors)
  2960. "C<$m1>" and "C<$m2>" and stores the result in matrix "C<$m3>".
  2961.  
  2962. This special method uses the binary "or" operation ("C<|>") as the
  2963. boolean addition operator ("C<+>").
  2964.  
  2965. An exception is raised if the product of the number of rows and
  2966. columns of any of the three matrices differs from the actual size
  2967. of their underlying bit vector.
  2968.  
  2969. An exception is also raised if the numbers of rows and columns
  2970. of the three matrices do not harmonize in the required manner:
  2971.  
  2972.   rows3 == rows1
  2973.   cols3 == cols2
  2974.   cols1 == rows2
  2975.  
  2976. This method is used by the module "Math::MatrixBool".
  2977.  
  2978. See L<Math::MatrixBool(3)> for details.
  2979.  
  2980. =item *
  2981.  
  2982. C<$matrix-E<gt>Closure($rows,$cols);>
  2983.  
  2984. This method calculates the reflexive transitive closure of the
  2985. given boolean matrix (stored as a bit vector) using Kleene's
  2986. algoritm.
  2987.  
  2988. (See L<Math::Kleene(3)> for a brief introduction into the
  2989. theory behind Kleene's algorithm.)
  2990.  
  2991. The reflexive transitive closure answers the question whether
  2992. a path exists between any two vertices of a graph whose edges
  2993. are given as a matrix:
  2994.  
  2995. If a (directed) edge exists going from vertex "i" to vertex "j",
  2996. then the element in the matrix with coordinates (i,j) is set to
  2997. "C<1>" (otherwise it remains set to "C<0>").
  2998.  
  2999. If the edges are undirected, the resulting matrix is symmetric,
  3000. i.e., elements (i,j) and (j,i) always contain the same value.
  3001.  
  3002. The matrix representing the edges of the graph only answers the
  3003. question whether an B<EDGE> exists between any two vertices of
  3004. the graph or not, whereas the reflexive transitive closure
  3005. answers the question whether a B<PATH> (a series of adjacent
  3006. edges) exists between any two vertices of the graph!
  3007.  
  3008. Note that the contents of the given matrix are modified by
  3009. this method, so make a copy of the initial matrix in time
  3010. if you are going to need it again later.
  3011.  
  3012. An exception is raised if the given matrix is not quadratic,
  3013. i.e., if the number of rows and columns of the given matrix
  3014. is not identical.
  3015.  
  3016. An exception is also raised if the product of the number of
  3017. rows and columns of the given matrix differs from the actual
  3018. size of its underlying bit vector.
  3019.  
  3020. This method is used by the module "Math::MatrixBool".
  3021.  
  3022. See L<Math::MatrixBool(3)> for details.
  3023.  
  3024. =item *
  3025.  
  3026. C<$matrix2-E<gt>Transpose($rows2,$cols2,$matrix1,$rows1,$cols1);>
  3027.  
  3028. This method calculates the transpose of a boolean matrix "C<$matrix1>"
  3029. (stored as a bit vector) and stores the result in matrix "C<$matrix2>".
  3030.  
  3031. The transpose of a boolean matrix, representing the edges of a graph,
  3032. can be used for finding the strongly connected components of that graph.
  3033.  
  3034. An exception is raised if the product of the number of rows and
  3035. columns of any of the two matrices differs from the actual size
  3036. of its underlying bit vector.
  3037.  
  3038. An exception is also raised if the following conditions are not
  3039. met:
  3040.  
  3041.   rows2 == cols1
  3042.   cols2 == rows1
  3043.  
  3044. Note that in-place processing ("C<$matrix1>" and "C<$matrix2>" are
  3045. identical) is only possible if the matrix is quadratic. Otherwise,
  3046. a fatal "matrix is not quadratic" error will occur.
  3047.  
  3048. This method is used by the module "Math::MatrixBool".
  3049.  
  3050. See L<Math::MatrixBool(3)> for details.
  3051.  
  3052. =back
  3053.  
  3054. =head1 SEE ALSO
  3055.  
  3056. Bit::Vector::Overload(3), Set::IntRange(3),
  3057. Math::MatrixBool(3), Math::MatrixReal(3),
  3058. DFA::Kleene(3), Math::Kleene(3),
  3059. Graph::Kruskal(3).
  3060.  
  3061. perl(1), perlsub(1), perlmod(1), perlref(1),
  3062. perlobj(1), perlbot(1), perltoot(1), perlxs(1),
  3063. perlxstut(1), perlguts(1), overload(3).
  3064.  
  3065. =head1 VERSION
  3066.  
  3067. This man page documents "Bit::Vector" version 6.3.
  3068.  
  3069. =head1 AUTHOR
  3070.  
  3071.   Steffen Beyer
  3072.   mailto:sb@engelschall.com
  3073.   http://www.engelschall.com/u/sb/download/
  3074.  
  3075. =head1 COPYRIGHT
  3076.  
  3077. Copyright (c) 1995 - 2002 by Steffen Beyer. All rights reserved.
  3078.  
  3079. =head1 LICENSE
  3080.  
  3081. This package is free software; you can redistribute it and/or
  3082. modify it under the same terms as Perl itself, i.e., under the
  3083. terms of the "Artistic License" or the "GNU General Public License".
  3084.  
  3085. The C library at the core of this Perl module can additionally
  3086. be redistributed and/or modified under the terms of the "GNU
  3087. Library General Public License".
  3088.  
  3089. Please refer to the files "Artistic.txt", "GNU_GPL.txt" and
  3090. "GNU_LGPL.txt" in this distribution for details!
  3091.  
  3092. =head1 DISCLAIMER
  3093.  
  3094. This package is distributed in the hope that it will be useful,
  3095. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3096. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  3097.  
  3098. See the "GNU General Public License" for more details.
  3099.  
  3100.