home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / bitstrin.h < prev    next >
C/C++ Source or Header  |  1993-07-23  |  18KB  |  757 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Doug Lea (dl@rocky.oswego.edu)
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23.  
  24. #ifndef _BitString_h
  25. #pragma once
  26.  
  27. #define _BitString_h 1
  28.  
  29. #include <stream.h>
  30. #include <values.h>
  31.  
  32. #define BITSTRBITS   BITS(short)
  33.  
  34. struct BitStrRep
  35. {
  36.   unsigned int    len;          // length in bits
  37.   unsigned short  sz;           // allocated slots
  38.   unsigned short  s[1];         // bits start here
  39.  
  40.   friend BitStrRep*  BStr_alloc(BitStrRep*, unsigned short*, int, int, int);
  41.   friend BitStrRep*  BStr_resize(BitStrRep*, int);
  42.   friend BitStrRep*  BStr_copy(BitStrRep*, BitStrRep*);
  43.   friend BitStrRep*  cmpl(BitStrRep*, BitStrRep*);
  44.   friend BitStrRep*  and(BitStrRep*, BitStrRep*, BitStrRep*);
  45.   friend BitStrRep*  or(BitStrRep*, BitStrRep*, BitStrRep*);
  46.   friend BitStrRep*  xor(BitStrRep*, BitStrRep*, BitStrRep*);
  47.   friend BitStrRep*  difference(BitStrRep*, BitStrRep*, BitStrRep*);
  48.   friend BitStrRep*  concat(BitStrRep*, BitStrRep*, BitStrRep*);
  49.   friend BitStrRep*  concat(BitStrRep*, int, BitStrRep*);
  50.   friend BitStrRep*  rshift(BitStrRep*, int, BitStrRep*);
  51.  
  52. };
  53.  
  54. extern BitStrRep    _nilBitStrRep;
  55.  
  56. class BitString;
  57. class BitPattern;
  58. class BitStrTmp;
  59.  
  60. class BitStrBit
  61. {
  62. protected:
  63.   BitString*        src;
  64.   unsigned int      pos;
  65.  
  66.  public:
  67.                     BitStrBit(BitString* v, int p);
  68.                     BitStrBit(BitStrBit& b);
  69.                     ~BitStrBit();
  70.   int               operator int();
  71.   int               operator =  (int b);
  72.   int               operator == (int b);
  73.   int               operator != (int b);
  74. };
  75.  
  76. class BitSubString
  77. {
  78.   friend class      BitString;
  79.   friend class      BitStrTmp;
  80.   friend class      BitPattern;
  81.  
  82. protected:
  83.  
  84.   BitString*        S;
  85.   int               pos;
  86.   int               len;
  87.  
  88.                     BitSubString(BitString* x, int p, int l);
  89.                     BitSubString(BitSubString& x);
  90. public:
  91.                     ~BitSubString();
  92.  
  93.   void              operator =  (BitString&  y);
  94.   void              operator =  (BitSubString&  y);
  95.   int               length();
  96.   int               empty();
  97.  
  98.   int               OK();
  99. };
  100.  
  101. class BitString
  102. {
  103.   friend class       BitStrTmp;
  104.   friend class       BitSubString;
  105.   friend class       BitPattern;
  106. protected:
  107.   BitStrRep*     rep;
  108.  
  109.   int               search(int, int, unsigned short*, int, int);
  110.   int               match(int, int, int, unsigned short*, int, int);
  111.  
  112. public:
  113.  
  114. // constructors
  115.                      BitString();
  116.                      BitString(BitString&);
  117.                      BitString(BitSubString& y);
  118.  
  119.                      ~BitString();
  120.  
  121.   void               operator =  (int bit);
  122.   void               operator =  (BitString& y);
  123.   void               operator =  (BitStrTmp& y);
  124.   void               operator =  (BitSubString& y);
  125.  
  126. // equality & subset tests
  127.  
  128.   friend int         operator == (BitString& x, BitString& y);
  129.   friend int         operator != (BitString& x, BitString& y);
  130.   friend int         operator <  (BitString& x, BitString& y);
  131.   friend int         operator <= (BitString& x, BitString& y);
  132.   friend int         operator >  (BitString& x, BitString& y);
  133.   friend int         operator >= (BitString& x, BitString& y);
  134.  
  135.   friend int         lcompare(BitString& x, BitString& y); // lexigraphic comp
  136.  
  137.  
  138.   BitStrTmp          operator |  (BitString& y);
  139.   BitStrTmp          operator |  (BitStrTmp& y);
  140.   void               operator |= (BitString& y);
  141.   BitStrTmp          operator &  (BitString& y);
  142.   BitStrTmp          operator &  (BitStrTmp& y);
  143.   void               operator &= (BitString& y);
  144.   BitStrTmp          operator -  (BitString& y);
  145.   BitStrTmp          operator -  (BitStrTmp& y);
  146.   void               operator -= (BitString& y);
  147.   BitStrTmp          operator ^  (BitString& y);
  148.   BitStrTmp          operator ^  (BitStrTmp& y);
  149.   void               operator ^= (BitString& y);
  150.   BitStrTmp          operator +  (BitString& y);
  151.   BitStrTmp          operator +  (BitStrTmp& y);
  152.   BitStrTmp          operator +  (int b);
  153.   void               operator += (BitString& y);
  154.   void               operator += (int b);
  155.   BitStrTmp          operator << (int s);
  156.   void               operator <<=(int s);
  157.   BitStrTmp          operator >> (int s);
  158.   void               operator >>=(int s);
  159.  
  160.   BitStrTmp          operator ~ ();
  161.   void               complement();
  162.  
  163. // individual bit manipulation
  164.  
  165.   void               set(int pos);
  166.   void               set(int from, int to);
  167.   void               set();
  168.  
  169.   void               clear(int pos);
  170.   void               clear(int from, int to);
  171.   void               clear(); 
  172.  
  173.   void               invert(int pos);
  174.   void               invert(int from, int to);
  175.  
  176.   int                test(int pos);
  177.   int                test(int from, int to);
  178.  
  179.   void               assign(int p, int bit);
  180.  
  181. // indexing
  182.  
  183.   BitStrBit          operator [] (int pos);
  184.  
  185. // iterators
  186.  
  187.   int                first(int b = 1);
  188.   int                last(int b = 1);
  189.  
  190.   int                next(int pos, int b = 1);
  191.   int                previous(int pos, int b = 1);
  192.  
  193. // searching & matching
  194.  
  195.   int                index(int          bit, int startpos = 0);      
  196.   int                index(BitString&     y, int startpos = 0);      
  197.   int                index(BitSubString&  y, int startpos = 0);      
  198.   int                index(BitPattern&    r, int startpos = 0);       
  199.  
  200.   int                contains(BitString&     y);
  201.   int                contains(BitSubString&  y);
  202.   int                contains(BitPattern&    r);
  203.  
  204.   int                contains(BitString&     y, int pos);
  205.   int                contains(BitSubString&  y, int pos);
  206.   int                contains(BitPattern&    r, int pos);
  207.  
  208.   int                matches(BitString&     y, int pos = 0);
  209.   int                matches(BitSubString&  y, int pos = 0);
  210.   int                matches(BitPattern& r, int pos = 0);
  211.  
  212. // BitSubString extraction
  213.  
  214.   BitSubString       at(int               pos, int len);
  215.   BitSubString       at(BitString&        x, int startpos = 0); 
  216.   BitSubString       at(BitSubString&     x, int startpos = 0); 
  217.   BitSubString       at(BitPattern&       r, int startpos = 0); 
  218.  
  219.   BitSubString       before(int           pos);
  220.   BitSubString       before(BitString&    x, int startpos = 0);
  221.   BitSubString       before(BitSubString& x, int startpos = 0);
  222.   BitSubString       before(BitPattern&   r, int startpos = 0);
  223.  
  224.   BitSubString       after(int            pos);
  225.   BitSubString       after(BitString&     x, int startpos = 0);
  226.   BitSubString       after(BitSubString&  x, int startpos = 0);
  227.   BitSubString       after(BitPattern&    r, int startpos = 0);
  228.  
  229. // other friends & utilities
  230.  
  231.   friend BitStrTmp   common_prefix(BitString& x, BitString& y, int pos = 0);
  232.   friend BitStrTmp   common_suffix(BitString& x, BitString& y, int pos = -1);
  233.   friend BitStrTmp   reverse(BitString& x);
  234.  
  235.   void               right_trim(int bit);
  236.   void               left_trim(int bit);
  237.  
  238. // status
  239.  
  240.   int                empty();
  241.   int                count(int bit = 1);
  242.   int                length();
  243.  
  244. // convertors & IO
  245.  
  246.   friend BitStrTmp   atoBitString(const char* s, char f='0', char t='1');
  247.   friend const char* BitStringtoa(BitString& x, char f='0', char t='1');
  248.  
  249.   friend BitStrTmp   shorttoBitString(unsigned short);
  250.   friend BitStrTmp   longtoBitString(unsigned long);
  251.  
  252.   friend ostream&    operator << (ostream& s, BitString& x);
  253.  
  254. // misc
  255.  
  256.   void               error(char* msg);
  257.  
  258. // indirect friends
  259.  
  260.   friend const char* BitPatterntoa(BitPattern& p, 
  261.                                   char f='0',char t='1',char x='X');
  262.   friend BitPattern  atoBitPattern(const char* s,
  263.                                   char f='0',char t='1',char x='X');
  264.  
  265.   int                OK();
  266. };
  267.  
  268. class BitStrTmp : public BitString
  269. {
  270.   friend class       BitSubString;
  271.   friend class       BitString;
  272. public:
  273.                      BitStrTmp(BitStrRep*);
  274.                      BitStrTmp(BitString& x);
  275.                      BitStrTmp(BitStrTmp& x);
  276.                      ~BitStrTmp();
  277.  
  278.   BitStrTmp          operator |  (BitString& y);
  279.   BitStrTmp          operator &  (BitString& y);
  280.   BitStrTmp          operator -  (BitString& y);
  281.   BitStrTmp          operator ^  (BitString& y);
  282.   BitStrTmp          operator +  (BitString& y);
  283.   BitStrTmp          operator +  (int b);
  284.   BitStrTmp          operator << (int s);
  285.   BitStrTmp          operator >> (int s);
  286.  
  287.   BitStrTmp          operator ~ ();
  288. };
  289.  
  290. class BitPattern
  291. {
  292. public:
  293.   BitString          pattern;
  294.   BitString          mask;
  295.  
  296.                      BitPattern();
  297.                      BitPattern(BitPattern&);
  298.                      BitPattern(BitString& p, BitString& m);
  299.                      ~BitPattern();
  300.  
  301.   friend const char* BitPatterntoa(BitPattern& p, 
  302.                                   char f='0',char t='1',char x='X');
  303.   friend BitPattern atoBitPattern(const char* s,
  304.                                   char f='0',char t='1',char x='X');
  305.   friend ostream&   operator << (ostream& s, BitPattern& x);
  306.  
  307.   int               search(unsigned short*, int, int);
  308.   int               match(unsigned short* xs, int, int, int);
  309.  
  310.   int               OK();
  311. };
  312.  
  313.  
  314. //#ifdef __OPTIMIZE__
  315.  
  316.  
  317. inline static int BitStr_index(int l)
  318. {
  319.   return (unsigned)(l) / BITSTRBITS;
  320. }
  321.  
  322. inline static int BitStr_pos(int l)
  323. {
  324.   return l & (BITSTRBITS - 1);
  325. }
  326.  
  327. inline BitString::BitString()
  328.   rep = &_nilBitStrRep;
  329. }
  330.  
  331. inline BitStrTmp shorttoBitString(unsigned short w)
  332.   return BStr_alloc(0, &w, 0, BITSTRBITS, BITSTRBITS);
  333. }
  334.  
  335. inline BitStrTmp longtoBitString(unsigned long w)
  336.   unsigned short u[2];
  337.   u[0] = w & ((unsigned short)(~(0)));
  338.   u[1] = w >> BITSTRBITS;
  339.   return BStr_alloc(0, &u[0], 0, 2*BITSTRBITS, 2*BITSTRBITS);
  340. }
  341.  
  342.  
  343. inline BitStrTmp::BitStrTmp(BitStrRep* r)
  344.   rep = r;
  345. }
  346.  
  347. inline BitStrTmp::BitStrTmp(BitStrTmp& x)
  348. {
  349.   rep = x.rep; x.rep = &_nilBitStrRep;
  350. }
  351.  
  352. inline BitStrTmp::BitStrTmp(BitString& x)
  353. {
  354.   rep = x.rep; x.rep = &_nilBitStrRep;
  355. }
  356.  
  357. inline BitString::BitString(BitString& x)
  358.   rep = BStr_copy(0, x.rep);
  359. }
  360.  
  361. inline BitString::BitString(BitSubString& y)
  362. {
  363.   rep = BStr_alloc(0, y.S->rep->s, y.pos, y.pos+y.len, y.len);
  364. }
  365.  
  366. inline BitString::~BitString()
  367.   if (rep != &_nilBitStrRep) delete rep;
  368. }
  369.  
  370. inline BitStrTmp::~BitStrTmp() {}
  371.  
  372. inline void BitString::operator =  (BitString& y)
  373.   rep = BStr_copy(rep, y.rep);
  374. }
  375.  
  376. inline void BitString::operator =  (BitStrTmp& y)
  377.   if (rep != &_nilBitStrRep) delete rep;
  378.   rep = y.rep; y.rep = &_nilBitStrRep; 
  379. }
  380.  
  381. inline void BitString::operator = (int b)
  382.   unsigned short bit = b;
  383.   rep = BStr_alloc(rep, &bit, 0, 1, 1);
  384. }
  385.  
  386. inline void BitString::operator=(BitSubString&  y)
  387. {
  388.   rep = BStr_alloc(rep, y.S->rep->s, y.pos, y.pos+y.len, y.len);
  389. }
  390.  
  391. inline BitSubString::BitSubString(BitSubString& x)
  392.   S = x.S; pos = x.pos;   len = x.len; 
  393. }
  394.  
  395. inline BitSubString::~BitSubString() {}
  396.  
  397. inline BitPattern::BitPattern(BitString& p, BitString& m)
  398.   pattern = p; mask = m;
  399. }
  400.  
  401. inline BitPattern::BitPattern(BitPattern& b)
  402.   pattern = b.pattern; mask = b.mask;
  403. }
  404.  
  405. inline BitPattern::BitPattern() {}
  406. inline BitPattern::~BitPattern() {}
  407.  
  408. inline BitStrTmp  BitString::operator & (BitString& y)
  409. {
  410.   return and(rep, y.rep, 0);
  411. }
  412.  
  413. inline BitStrTmp   BitString::operator & (BitStrTmp& y)
  414. {
  415.   y.rep =  and(rep, y.rep, y.rep); return y;
  416. }
  417.  
  418. inline BitStrTmp   BitStrTmp::operator & (BitString& y)
  419. {
  420.   rep =  and(rep, y.rep, rep); return *this;
  421. }
  422.  
  423. inline void        BitString::operator &= (BitString& y)
  424. {
  425.   rep =  and(rep, y.rep, rep);
  426. }
  427.  
  428.  
  429. inline BitStrTmp  BitString::operator | (BitString& y)
  430. {
  431.   return or(rep, y.rep, 0);
  432. }
  433.  
  434. inline BitStrTmp   BitString::operator | (BitStrTmp& y)
  435. {
  436.   y.rep =  or(rep, y.rep, y.rep); return y;
  437. }
  438.  
  439. inline BitStrTmp   BitStrTmp::operator | (BitString& y)
  440. {
  441.   rep =  or(rep, y.rep, rep); return *this;
  442. }
  443.  
  444. inline void        BitString::operator |= (BitString& y)
  445. {
  446.   rep =  or(rep, y.rep, rep);
  447. }
  448.  
  449. inline BitStrTmp  BitString::operator ^ (BitString& y)
  450. {
  451.   return xor(rep, y.rep, 0);
  452. }
  453.  
  454. inline BitStrTmp   BitString::operator ^ (BitStrTmp& y)
  455. {
  456.   y.rep =  xor(rep, y.rep, y.rep); return y;
  457. }
  458.  
  459. inline BitStrTmp   BitStrTmp::operator ^ (BitString& y)
  460. {
  461.   rep =  xor(rep, y.rep, rep); return *this;
  462. }
  463.  
  464. inline void        BitString::operator ^= (BitString& y)
  465. {
  466.   rep =  xor(rep, y.rep, rep);
  467. }
  468.  
  469.  
  470. inline BitStrTmp  BitString::operator - (BitString& y)
  471. {
  472.   return difference(rep, y.rep, 0);
  473. }
  474.  
  475. inline BitStrTmp   BitString::operator - (BitStrTmp& y)
  476. {
  477.   y.rep =  difference(rep, y.rep, y.rep); return y;
  478. }
  479.  
  480. inline BitStrTmp   BitStrTmp::operator - (BitString& y)
  481. {
  482.   rep =  difference(rep, y.rep, rep); return *this;
  483. }
  484.  
  485. inline void        BitString::operator -= (BitString& y)
  486. {
  487.   rep =  difference(rep, y.rep, rep);
  488. }
  489.  
  490. inline BitStrTmp  BitString::operator + (BitString& y)
  491. {
  492.   return concat(rep, y.rep, 0);
  493. }
  494.  
  495. inline BitStrTmp  BitString::operator + (int bit)
  496. {
  497.   return concat(rep, bit, 0);
  498. }
  499.  
  500. inline BitStrTmp   BitString::operator + (BitStrTmp& y)
  501. {
  502.   y.rep =  concat(rep, y.rep, y.rep); return y;
  503. }
  504.  
  505. inline BitStrTmp   BitStrTmp::operator + (BitString& y)
  506. {
  507.   rep =  concat(rep, y.rep, rep); return *this;
  508. }
  509.  
  510. inline BitStrTmp   BitStrTmp::operator + (int bit)
  511. {
  512.   rep =  concat(rep, bit, rep); return *this;
  513. }
  514.  
  515. inline void        BitString::operator += (BitString& y)
  516. {
  517.   rep =  concat(rep, y.rep, rep);
  518. }
  519.  
  520. inline void        BitString::operator += (int bit)
  521. {
  522.   rep =  concat(rep, bit, rep);
  523. }
  524.  
  525. inline BitStrTmp  BitString::operator << (int y)
  526. {
  527.   return rshift(rep, y, 0);
  528. }
  529.  
  530. inline BitStrTmp   BitStrTmp::operator << (int y)
  531. {
  532.   rep =  rshift(rep, y, rep); return *this;
  533. }
  534.  
  535. inline void        BitString::operator <<= (int y)
  536. {
  537.   rep =  rshift(rep, y, rep);
  538. }
  539.  
  540. inline BitStrTmp  BitString::operator >> (int y)
  541. {
  542.   return rshift(rep, -y, 0);
  543. }
  544.  
  545. inline BitStrTmp   BitStrTmp::operator >> (int y)
  546. {
  547.   rep =  rshift(rep, -y, rep); return *this;
  548. }
  549.  
  550. inline void        BitString::operator >>= (int y)
  551. {
  552.   rep =  rshift(rep, -y, rep);
  553. }
  554.  
  555. inline void        BitString::complement()
  556. {
  557.   rep =  cmpl(rep, rep);
  558. }
  559.  
  560. inline BitStrTmp   BitStrTmp::operator ~()
  561. {
  562.   rep =  cmpl(rep, rep); return *this;
  563. }
  564.  
  565. inline BitStrTmp  BitString::operator ~()
  566. {
  567.   return cmpl(rep, 0);
  568. }
  569.  
  570. inline int BitString::length()
  571.   return rep->len;
  572. }
  573.  
  574. inline int BitString::empty()
  575.   return rep->len == 0;
  576. }
  577.  
  578. inline int BitString::index(BitString& y, int startpos = 0)
  579. {   
  580.   return search(startpos, rep->len, y.rep->s, 0, y.rep->len);
  581. }
  582.  
  583. inline int BitString::index(BitSubString& y, int startpos = 0)
  584. {   
  585.   return search(startpos, rep->len, y.S->rep->s, y.pos, y.pos+y.len);
  586. }
  587.  
  588. inline int BitString::contains(BitString& y)
  589. {   
  590.   return search(0, rep->len, y.rep->s, 0, y.rep->len) >= 0;
  591. }
  592.  
  593. inline int BitString::contains(BitSubString& y)
  594. {   
  595.   return search(0, rep->len, y.S->rep->s, y.pos, y.pos+y.len) >= 0;
  596. }
  597.  
  598. inline int BitString::contains(BitString& y, int p)
  599. {
  600.   return match(p, rep->len, 0, y.rep->s, 0, y.rep->len);
  601. }
  602.  
  603. inline int BitString::matches(BitString& y, int p = 0)
  604. {
  605.   return match(p, rep->len, 1, y.rep->s, 0, y.rep->len);
  606. }
  607.  
  608. inline int BitString::contains(BitSubString& y, int p)
  609. {
  610.   return match(p, rep->len, 0, y.S->rep->s, y.pos, y.pos+y.len);
  611. }
  612.  
  613. inline int BitString::matches(BitSubString& y, int p = 0)
  614. {
  615.   return match(p, rep->len, 1, y.S->rep->s, y.pos, y.pos+y.len);
  616. }
  617.  
  618. inline int BitString::contains(BitPattern& r)
  619. {
  620.   return r.search(rep->s, 0, rep->len) >= 0;
  621. }
  622.  
  623. inline int BitString::contains(BitPattern& r, int p)
  624. {
  625.   return r.match(rep->s, p, rep->len, 0);
  626. }
  627.  
  628. inline int BitString::matches(BitPattern& r, int p = 0)
  629. {
  630.   return r.match(rep->s, p, rep->len, 1);
  631. }
  632.  
  633. inline int BitString::index(BitPattern& r, int startpos = 0)
  634. {
  635.   return r.search(rep->s, startpos, rep->len);
  636. }
  637.  
  638. inline  int BitSubString::length()
  639.   return len;
  640. }
  641.  
  642. inline  int BitSubString::empty()
  643.   return len == 0;
  644. }
  645.  
  646. inline int operator != (BitString& x, BitString& y)
  647. {
  648.   return !(x == y);
  649. }
  650.  
  651. inline int operator>(BitString& x, BitString& y)
  652. {
  653.   return y < x;
  654. }
  655.  
  656. inline int operator>=(BitString& x, BitString& y)
  657. {
  658.   return y <= x;
  659. }
  660.  
  661.  
  662. inline int BitString::first(int b = 1)
  663. {
  664.   return next(-1, b);
  665. }
  666.  
  667. inline int BitString::last(int b = 1)
  668. {
  669.   return previous(rep->len, b);
  670. }
  671.  
  672. inline int BitString::index(int bit, int startpos = 0)
  673. {
  674.   if (startpos >= 0)
  675.     return next(startpos - 1, bit);
  676.   else
  677.     return previous(rep->len + startpos + 1, bit);
  678. }
  679.  
  680. inline void BitString::right_trim(int b)
  681. {
  682.   int nb = (b == 0)? 1 : 0;
  683.   rep = BStr_resize(rep, previous(rep->len, nb) + 1);
  684. }
  685.  
  686. inline void BitString::left_trim(int b)
  687. {
  688.   int nb = (b == 0)? 1 : 0;
  689.   int p = next(-1, nb);
  690.   rep = BStr_alloc(rep, rep->s, p, rep->len, rep->len - p);
  691. }
  692.  
  693. inline int BitString::test(int i)
  694. {
  695.   return ((unsigned)(i) >= rep->len)? 0 : 
  696.          ((rep->s[BitStr_index(i)] & (1 << (BitStr_pos(i)))) != 0);
  697. }
  698.  
  699.  
  700. inline BitStrBit::BitStrBit(BitStrBit& b)
  701. {
  702.   src = b.src; pos = b.pos;
  703. }
  704.  
  705. inline BitStrBit::BitStrBit(BitString* v, int p)
  706. {
  707.   src = v; pos = p;
  708. }
  709.  
  710. inline BitStrBit::~BitStrBit() {}
  711.  
  712. inline int BitStrBit::operator int()
  713. {
  714.   return src->test(pos);
  715. }
  716.  
  717. inline int BitStrBit::operator = (int b)
  718. {
  719.   src->assign(pos, b); return b;
  720. }
  721.  
  722. inline int BitStrBit::operator == (int b)
  723. {
  724.   return src->test(pos) == b;
  725. }
  726.  
  727. inline int BitStrBit::operator != (int b)
  728. {
  729.   return src->test(pos) != b;
  730. }
  731.  
  732. inline BitStrBit BitString::operator [] (int i)
  733. {
  734.   if ((unsigned)(i) >= rep->len) error("illegal bit index");
  735.   return BitStrBit(this, i);
  736. }
  737.  
  738. //#endif
  739.  
  740. #endif
  741.