37#ifndef _CHOMP_CUBES_BINCUBE_H_
38#define _CHOMP_CUBES_BINCUBE_H_
61template <
int number,
int power>
104template <
int Dim,
int twoPower>
119template <
int Dim,
int twoPower>
153 friend class bincube<Dim,twoPower>;
169 operator int ()
const;
178 const int *
coord ()
const;
181 template <
class intType>
182 intType *
coord (intType *tab)
const;
208 int n = -1,
int inicur = -1);
218 operator int ()
const;
255 void add (
int number);
259 template <
class intType>
260 void add (
const intType *coord);
264 bool check (
int number)
const;
268 template <
class intType>
269 bool check (
const intType *coord)
const;
277 template <
class intType>
278 void remove (
const intType *coord);
284 operator const char * ()
const;
290 std::istream &
read (std::istream &in);
296 static void wrap (
int dir);
302 template <
class intType>
303 static intType
wrap (intType coord,
int dir);
307 template <
class intType>
308 static int coord2num (
const intType *coord);
311 template <
class intType>
312 static intType *
num2coord (
int number, intType *coord);
317 template <
class intType>
318 static const intType *
num2coord (
int number);
322 operator int ()
const;
357template <
int Dim,
int twoPower>
360template <
int Dim,
int twoPower>
363template <
int Dim,
int twoPower>
366template <
int Dim,
int twoPower>
369template <
int Dim,
int twoPower>
372template <
int Dim,
int twoPower>
375template <
int Dim,
int twoPower>
378template <
int Dim,
int twoPower>
384template <
int Dim,
int twoPower>
387 buf =
new char [bufsize];
389 memset (buf, 0, bufsize);
394template <
int Dim,
int twoPower>
403template <
int Dim,
int twoPower>
406 buf =
new char [bufsize];
408 memcpy (buf, b. buf, bufsize);
409 cardinality = b. cardinality;
413template <
int Dim,
int twoPower>
417 memcpy (buf, b. buf, bufsize);
418 cardinality = b. cardinality;
422template <
int Dim,
int twoPower>
432template <
int Dim,
int twoPower>
438template <
int Dim,
int twoPower>
444template <
int Dim,
int twoPower>
451template <
int Dim,
int twoPower>
458template <
int Dim,
int twoPower>
459template <
class intType>
468 while (coord >= width)
476template <
int Dim,
int twoPower>
477template <
class intType>
481 for (
int i = Dim - 1; i >= 0; -- i)
493 else if ((c < 0) || (c >= width))
501template <
int Dim,
int twoPower>
502template <
class intType>
505 for (
int i = 0; i < Dim; ++ i)
513template <
int Dim,
int twoPower>
514template <
class intType>
522template <
int Dim,
int twoPower>
526 int offset = start >> 3;
529 if (offset >= bufsize)
535 int bitnumber = start & 7;
536 while (bitnumber < 8)
538 if (buf [offset] & (1 << bitnumber))
539 return (offset << 3) + bitnumber;
548 if (offset >= bufsize)
558 if (buf [offset] & (1 << bitnumber))
559 return (offset << 3) + bitnumber;
566template <
int Dim,
int twoPower>
569 return buf [number >> 3] & (1 << (number & 7));
572template <
int Dim,
int twoPower>
573template <
class intType>
576 return check (coord2num (coord));
579template <
int Dim,
int twoPower>
582 if ((cardinality >= 0) && !check (number))
584 buf [number >> 3] |= (char) (1 << (number & 7));
588template <
int Dim,
int twoPower>
589template <
class intType>
592 return add (coord2num (coord));
595template <
int Dim,
int twoPower>
598 if ((cardinality > 0) && check (number))
600 buf [number >> 3] &= (char) (~(1 << (number & 7)));
604template <
int Dim,
int twoPower>
605template <
class intType>
608 return remove (coord2num (coord));
613template <
int Dim,
int twoPower>
620template <
int Dim,
int twoPower>
630template <
int Dim,
int twoPower>
639template <
int Dim,
int twoPower>
645template <
int Dim,
int twoPower>
651template <
int Dim,
int twoPower>
657template <
int Dim,
int twoPower>
658template <
class intType>
666template <
class coordinate>
671 for (
int i = Dim - 1; i >= 0; -- i)
676 dest [i] = src [i] - 1;
679 dest [i] = src [i] + 1;
685 throw "Erratic neighbor.";
693template <
class settype>
695 (
const typename settype::iterator &q,
int n)
697 const int Dim = settype::MaxDim;
703 return typename settype::iterator (q. b,
714template <
int Dim,
int twoPower>
717 b (bcub), curnum (-1), cur (inicur)
725 for (
int i = 0; i < Dim; ++ i)
730 for (
int i = 0; i < Dim; ++ i)
736template <
int Dim,
int twoPower>
747 for (
int i = 0; i < Dim; ++ i)
756 if (b ->
check (curnum))
766template <
int Dim,
int twoPower>
777template <
int Dim,
int twoPower>
783template <
int Dim,
int twoPower>
784inline bool operator ==
789 return ((x1. b == x2. b) && (x1. cur == x2. cur));
792template <
int Dim,
int twoPower>
793inline bool operator !=
803template <
int Dim,
int twoPower>
804inline typename bincube<Dim,twoPower>::neighborhood_iterator
812template <
int Dim,
int twoPower>
823template <
int Dim,
int twoPower>
830template <
int Dim,
int twoPower>
839template <
int Dim,
int twoPower>
845template <
int Dim,
int twoPower>
851template <
int Dim,
int twoPower>
857template <
int Dim,
int twoPower>
867template <
int Dim,
int twoPower>
884template <
int Dim,
int twoPower>
890template <
int Dim,
int twoPower>
896template <
int Dim,
int twoPower>
906template <
int Dim,
int twoPower>
913template <
int Dim,
int twoPower>
925template <
class cubetype,
class settype>
931 q (middle), s (cset) {};
938 cubetype neighbor = bit2neighborAlg<settype> (q, n);
941 return (s.
check (neighbor));
959 static bool check (
typename SetT::iterator q,
const SetT &s)
964 static bool check (
int n,
const SetT &s)
967 typename SetT::iterator q (
const_cast<SetT *
> (&s), n);
978 static bool check (
typename SetT::iterator q,
const SetT &s)
983 static bool check (
int n,
const SetT &s)
986 typename SetT::iterator q (
const_cast<SetT *
> (&s), n);
997 static bool check (
typename SetT::iterator q,
const SetT &s)
1002 static bool check (
int n,
const SetT &s)
1005 typename SetT::iterator q (
const_cast<SetT *
> (&s), n);
1006 return check (q, s);
1013template <
class Number>
1021 operator Number ()
const {
return number;}
1028template <
class Number>
1031 return static_cast<int_t> (
static_cast<Number
> (n));
1035template <
class Number>
1038 return static_cast<int_t> (
static_cast<Number
> (n) ^
1047template <
class SetT,
class QueueT>
1064template <
typename SetT,
typename Acyclic,
typename QueueT>
1072 bool exitloop =
false;
1073 bool lastrun =
false;
1080 int countremoved = 0, countleft = 0;
1081 typename SetT::iterator cur = X.
begin (),
end = X.
end ();
1084 if (Acyclic::check (cur, X))
1096 if (!quiet && !(
count % 5273))
1098 "\b\b\b\b\b\b\b\b\b\b";
1104 if (!lastrun && (countremoved - 10 < (countleft >> 2)))
1111 while (!Q.
empty ())
1113 typename QueueT::value_type elem = Q. front ();
1115 if (Acyclic::check (elem, X))
1122 if (!quiet && !(
count % 5273))
1124 "\b\b\b\b\b\b\b\b\b\b";
1166template <
class FullCubSet>
1181 throw "Binary cube reduction not implemented "
1182 "for dimension > 3.";
This file defines a very simple function for counting the number of bits in a byte or a multi-byte in...
This class defines a procedure for verifying if a full-cubical neighborhood in a given set of a full ...
static bool check(typename SetT::iterator q, const SetT &s)
static bool check(int n, const SetT &s)
This class defines a procedure for verifying if a full-cubical neighborhood in a given set of a full ...
static bool check(typename SetT::iterator q, const SetT &s)
static bool check(int n, const SetT &s)
This class defines a procedure for verifying if a full-cubical neighborhood in a given set of a full ...
static bool check(typename SetT::iterator q, const SetT &s)
static bool check(int n, const SetT &s)
A fixed-dimensional bitmap of the size 2^n in each direction.
This is a class used by the classes "Acyclic1d", "Acyclic2d", and "Acyclic3d" to use binary decision ...
NeighborsBdd(const cubetype &middle, const settype &cset)
This is a helper class which makes the compiler compute n^k during the compilation of the program.
This class defines an error type which is caused by using coordinates of a cube out of range with res...
This is an abstract class which defines a set of full cubes represented as a bitmap for the purpose o...
The iterator of the set of cubes within a bitmap.
int CoordType
The type of coordinates.
int n
The number of the current bit in the set.
iterator & operator++()
The preincrement operator.
static const int MaxDim
The maximal possible dimension of the cube.
const int * coord() const
The coordinates of the cube.
static int dim()
The dimension of the cube.
iterator(bincube< Dim, twoPower > *bcub=0, int num=-1)
The default constructor.
bincube< Dim, twoPower > * b
The binary cube in which the cube is contained.
The neighborhood of a cube.
neighborhood_iterator & operator++()
The preincrement operator.
int curnum
The number of the current neighbor in the binary cube.
int coord[Dim]
The coordinates of the middle cube in the neighborhood.
bincube< Dim, twoPower > * b
Conversion to a cube iterator.
int ncoord[Dim]
The coordinates of the current neighbor.
neighborhood_iterator(bincube< Dim, twoPower > *bcub=0, int n=-1, int inicur=-1)
The default constructor.
int cur
The neighbor counter (up to max_neighbors).
A binary n-dimensional hypercube for storing cubes as bits.
static intType * num2coord(int number, intType *coord)
Determines the coordinates of the cube with given number.
bool allocated
Was the memory for the buffer allocated?
static int coord2num(const intType *coord)
Determines the number of the cube with given coordinates.
static const int bufsize
The size of the buffer in bytes.
static const int max_neighbors
The maximal possible number of neighbors of a cube.
static int wrapping
Wrapping in each direction.
static void wrap(int dir)
Turns on wrapping in the given direction.
neighborhood_iterator neighborhood_begin(int number) const
Creates a neighborhood iterator for the specified cube and sets it at the first cube.
neighborhood_iterator neighborhood_end(int number) const
Creates a one-behind-the-end iterator for the given cube.
std::istream & read(std::istream &in)
Reads the binary buffer from an input stream.
void clear()
Makes the set empty.
void remove(int number)
Clears the bit corresponding to the given cube (by number).
static const int maxcount
The maximal number of cubes that can be stored in the set.
static const int MaxDim
The maximal possible dimension of a cube.
static bool wrapped(int dir)
Verifies whether the space is wrapped in the given direction.
static int dimension()
Retrieves the dimension of the cube.
int count() const
Get the number of cubes in the set.
iterator end()
Returns the iterator that points beyond the end of the set.
bool check(int number) const
Checks if the given cube belongs to the set or not.
bincube()
The default constructor.
static void dontwrap(int dir)
Turns off wrapping in the given direction.
char * buf
The memory for storing the hypercubes.
static const int twoMask
The mask for extracting one coordinate from the number.
bool empty() const
Verifies whether the set is empty or not.
int findcube(int start=0) const
Finds the first existing cube beginning at the given number.
int cardinality
The number of cubes in the set (or -1 if unknown)
static const int width
The width of the set in each direction (in cubes).
iterator begin()
Returns the iterator that points at the first cube in the set.
static int getbufsize()
Gets the buffer size.
~bincube()
The destructor.
void add(int number)
Sets the bit corresponding to the given cube (by number).
bincube< Dim, twoPower > & operator=(const bincube< Dim, twoPower > &b)
The assignment operator.
const char * getbuffer() const
Gets the binary buffer for reading only.
A class of numbers that can be used in a hashed set.
hashNumber(Number n=0)
The default constructor.
This is a template for a set of objects of the given type.
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
int int_t
Index type for indexing arrays, counting cubes, etc.
This file contains the definition of the container "hashedset" which can be used to represent a set o...
hashedset< hashNumber< int > > hashIntQueue
outputstream sout
A replacement for standard output stream, with optional logging and other features provided by the cl...
bool acyclic3d(NeighborCheck &n)
Verifies whether the neighborhood of a 3-dimensional cube is acyclic.
std::ostream & operator<<(std::ostream &out, const bincube< Dim, twoPower > &b)
int write(std::ostream &out, const coordtype *c, int dim, char parenthesis=40, char closing=0)
int_t hashkey2(const hashNumber< Number > &n)
The second hashing key.
void addneighbors(const int &c, const SetT &s, QueueT &q)
Adds the neighbors of the cube 'c' in the set 's' to the set 'q'.
bool acyclic1d(NeighborCheck &n)
Verifies whether the neighborhood of a 1-dimensional "cube" is acyclic.
void bit2neighborAlg(int number, const coordinate *src, coordinate *dest, int Dim)
short int coordinate
The default type of coordinates.
std::istream & operator>>(std::istream &in, bincube< Dim, twoPower > &b)
int_t hashkey1(const hashNumber< Number > &n)
The first hashing key.
outputstream scon
The console output stream to which one should put all the junk that spoils the log file,...
int reduceFullCubes(FullCubSet &X, bool quiet=false)
Reduces the set of full cubes.
int reduceFullCubesAlg(SetT &X, bool quiet)
Reduces the set of full cubes.
bool acyclic2d(NeighborCheck &n)
Verifies whether the neighborhood of a 2-dimensional "cube" is acyclic.
This namespace contains the entire CHomP library interface.