1 // bitspace.h: declaration of class bitspace for handling F_2 spaces
2 //////////////////////////////////////////////////////////////////////////
3 //
4 // Copyright 1990-2012 John Cremona
5 //
6 // This file is part of the eclib package.
7 //
8 // eclib is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 2 of the License, or (at your
11 // option) any later version.
12 //
13 // eclib is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 // for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with eclib; if not, write to the Free Software Foundation,
20 // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #if     !defined(_ECLIB_BITSPACE_H)
25 #define _ECLIB_BITSPACE_H      1       //flags that this file has been included
26 
27 class bitspace {
28 private:
29   long maxdim;
30   long dim;
31   long * pivs; // holds the position of the ith pivot
32   unsigned long * gens; // holds the ith basis element
33   unsigned long bitmask;   // holds the bits of the pivs
34 public:
35   bitspace(long d);
36   ~bitspace();
getbitmask()37   unsigned long getbitmask() {return bitmask;}
38   long reduce(unsigned long& v, long start=0) const;
39   // reduces v mod this, returns minimal i such that the reduced v has
40   // ith bit set, or -1 if v reduces to 0.  Assumes already reduced for i<start
mask(unsigned long i)41   int mask(unsigned long i) {return (i&bitmask)!=0;}
42   void augment(unsigned long v, long piv);
43   // uses reduced v to augment this, given piv as suitable pivot position in v
augment(unsigned long v)44   int augment(unsigned long v)
45   // uses v to augment this unless it it dependent, returns 1 if new
46     {
47       long j = reduce(v);
48       if(j<0) return 0;
49       augment(v,j); return 1;
50     }
51 };
52 
testbit(long a,long i)53 inline int testbit(long a, long i) {return (a& (1<<i));}
setbit(long & a,long i)54 inline int setbit( long& a, long i) {return (a|=(1<<i));}
55 
56 #endif
57