Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes

chomp::homology::tPointset< coordtype > Class Template Reference

This class represents a set of points in R^n with integer coordinates. More...

#include <pointset.h>

List of all members.

Public Member Functions

 tPointset (int_t initialsize=0, int bequiet=1)
 Default constructor for a set of points with the initial size of the set defined here if an upper bound for the size of the set is known and thus it is smart to allocate less memory.
 tPointset (const tPointset< coordtype > &p)
 The copy constructor.
tPointsetoperator= (const tPointset< coordtype > &p)
 The assignment operator.
 ~tPointset ()
 The destructor.
int dimension (int d)
 Sets the dimension of points.
int dimension () const
 Returns the dimension of points.
double * gridsize (double *g=0)
 Gets or sets the size of the grid in R^n.
double * gridsize (double g)
 Sets the grid size (if the same in all the directions).
double * gridsize (int direction, double g)
 Sets the grid size in one particular direction.
const coordtype * wrapspace (const coordtype *w=NULL)
const coordtype * wrapspace (coordtype w)
const coordtype * wrapspace (int direction, coordtype w)
int check (int_t n) const
int check (const coordtype *c) const
int check (const double *c) const
int_t getnumber (const coordtype *c) const
int_t getnumber (const double *c) const
coordtype * operator[] (int_t n) const
coordtype * getpoint (int_t n) const
coordtype * getpoint (coordtype *c) const
coordtype * getpoint (double *c) const
coordtype * getpoint (int_t n, double *c) const
int_t add (const coordtype *c)
int_t add (double *c)
tPointsetadd (const tPointset< coordtype > &p)
int remove (int_t n)
int remove (const coordtype *c)
int remove (const double *c)
int remove (const tPointset< coordtype > &p)
int_t size () const
 Returns the number of points in the set.
bool empty () const
 Returns true if and only if the set of points is empty.
int_t gethashsize () const

Static Public Member Functions

static int defaultdimension (int d=0)
 Sets or gets the default dimension of points.

Public Attributes

int quiet
 Returns the number of points by simply projecting the set onto an integer number.
psethashstatstat
coordtype * minimal
coordtype * maximal
int wereremoved

Protected Member Functions

void initialize (int_t initialsize, int bequiet)
void deallocate ()
int_t hashfindpoint (const coordtype *c, int_t *addposition=NULL, int wrapped=0) const
void rehash (int_t newsize=0)

Protected Attributes

int dim
int_t npoints
int_t ntables
int tablepoints
coordtype ** tables
double * grid
coordtype * wrap
coordtype * temp
int_t hashsize
int_t hashcleared
int_thashtable
unsigned initsize

Static Protected Attributes

static int defaultdim = 0
static double * defaultgrid = NULL
static coordtype * defaultwrap = NULL

Detailed Description

template<class coordtype>
class chomp::homology::tPointset< coordtype >

This class represents a set of points in R^n with integer coordinates.

Definition at line 467 of file pointset.h.


Constructor & Destructor Documentation

template<class coordtype >
chomp::homology::tPointset< coordtype >::tPointset ( int_t  initialsize = 0,
int  bequiet = 1 
) [inline]

Default constructor for a set of points with the initial size of the set defined here if an upper bound for the size of the set is known and thus it is smart to allocate less memory.

If dimension, grid size and space wrapping was defined for any pointset, these values are automatically copied to all the pointsets created further (until changed).

Definition at line 1180 of file pointset.h.

References chomp::homology::tPointset< coordtype >::initialize().

{
        initialize (initialsize, bequiet);
        return;
} /* tPointset::tPointset */

template<class coordtype >
chomp::homology::tPointset< coordtype >::tPointset ( const tPointset< coordtype > &  p  )  [inline]
template<class coordtype >
chomp::homology::tPointset< coordtype >::~tPointset< coordtype > (  )  [inline]

The destructor.


Member Function Documentation

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::add ( const coordtype *  c  )  [inline]

Definition at line 1004 of file pointset.h.

References chomp::homology::copycoord(), chomp::homology::tPointset< coordtype >::dim, chomp::homology::tPointset< coordtype >::hashcleared, chomp::homology::tPointset< coordtype >::hashfindpoint(), chomp::homology::tPointset< coordtype >::hashsize, chomp::homology::tPointset< coordtype >::hashtable, chomp::homology::tPointset< coordtype >::maximal, chomp::homology::tPointset< coordtype >::minimal, chomp::homology::tPointset< coordtype >::npoints, chomp::homology::tPointset< coordtype >::ntables, chomp::homology::tPointset< coordtype >::rehash(), chomp::homology::tPointset< coordtype >::tablepoints, chomp::homology::tPointset< coordtype >::tables, chomp::homology::tPointset< coordtype >::temp, chomp::homology::tPointset< coordtype >::wrap, and chomp::homology::wrapcoord().

Referenced by chomp::homology::tPointset< coordtype >::add(), chomp::homology::tPointset< coordtype >::hashfindpoint(), and chomp::homology::tPointset< coordtype >::tPointset().

{
        // prevent from adding a 'NULL' point
        if (!c)
                return -1;

        // check if the dimension of the point is known
        if (!dim)
                throw "Trying to add a point of unknown dimension.";

        // wrap the point's coordinates if needed
        if (wrap)
        {
                if (!temp)
                        temp = allocatepoint<coordtype> (dim);
                wrapcoord (temp, c, wrap, dim);
                c = temp;
        }

        // increase the size of the hashing table if needed
        if (hashsize - hashcleared <= npoints + npoints / 5)
                rehash ();

        // find a place for the new point
        int_t addpos = -1;
        int_t pos = hashfindpoint (c, &addpos, 1);

        // if the point is already in the set, return its number
        if (hashtable [pos] >= 0)
                return hashtable [pos];

        // update the range of coordinates for statistical purposes
        if (minimal)
        {
                for (int i = 0; i < dim; ++ i)
                        if (minimal [i] > c [i])
                                minimal [i] = c [i];
        }
        else
        {
                minimal = allocatepoint<coordtype> (dim);
                copycoord (minimal, c, dim);
        }

        if (maximal)
        {
                for (int i = 0; i < dim; ++ i)
                        if (maximal [i] < c [i])
                                maximal [i] = c [i];
        }
        else
        {
                maximal = allocatepoint<coordtype> (dim);
                copycoord (maximal, c, dim);
        }

        // write the point's number into the hashing table
        if (addpos >= 0)
        {
                pos = addpos;
                if (hashtable [pos] == -2)
                        -- hashcleared;
        }
        hashtable [pos] = npoints;

        // compute the number of the table in which the point's coordinates
        // should be stored
        int_t tablenumber = npoints / tablepoints;

        // if there are not enough tables, add some
        if (tablenumber >= ntables)
        {
                int_t moretables = (ntables << 1) + 13;
                coordtype **newtables = new coordtype * [moretables];
                if (!newtables)
                        throw "Unable to alloc a table for tables.";
                for (int_t i = 0; i < moretables; ++ i)
                        newtables [i] = (i < ntables) ? (tables [i]) :
                                (coordtype *) NULL;
                if (tables)
                        delete [] tables;
                tables = newtables;
                ntables = moretables;
        }

        // if the appropriate table has not been allocate yet, allocate it
        if (tables [tablenumber] == NULL)
        {
                tables [tablenumber] = new coordtype [tablepoints * dim];
                if (!tables [tablenumber])
                        throw "Unable to alloc a table for coords.";
        }

        // copy the point's coordinates into the table
        copycoord (tables [tablenumber] +
                ((npoints % tablepoints) * dim), c, dim);

        // return the point's number and increase the number of points
        // in the set
        return (npoints ++);
} /* tPointset::add */

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::add ( double *  c  )  [inline]

Definition at line 1107 of file pointset.h.

References chomp::homology::tPointset< coordtype >::add(), chomp::homology::tPointset< coordtype >::dim, chomp::homology::tPointset< coordtype >::grid, chomp::homology::roundpoint(), and chomp::homology::tPointset< coordtype >::temp.

{
        // prevent from adding a 'NULL' point
        if (!c)
                return -1;

        if (!dim)
                throw "Trying to add a point of unknown dimension.";
        if (!temp)
                temp = allocatepoint<coordtype> (dim);
        roundpoint (c, temp, grid, dim);
        return add (temp);
} /* tPointset::add */

template<class coordtype >
tPointset< coordtype > & chomp::homology::tPointset< coordtype >::add ( const tPointset< coordtype > &  p  )  [inline]

Definition at line 1123 of file pointset.h.

{
        int_t size = p. size ();
        for (int_t i = 0; i < size; ++ i)
                this -> add (p [i]);
        return *this;
} /* tPointset::add */

template<class coordtype >
int chomp::homology::tPointset< coordtype >::check ( int_t  n  )  const [inline]

Definition at line 1276 of file pointset.h.

References chomp::homology::tPointset< coordtype >::npoints.

{
        return ((n >= 0) && (n < npoints));
} /* tPointset::check */

template<class coordtype >
int chomp::homology::tPointset< coordtype >::check ( const coordtype *  c  )  const [inline]

Definition at line 1282 of file pointset.h.

References chomp::homology::tPointset< coordtype >::getnumber().

{
        return (getnumber (c) != -1);
} /* tPointset::check */

template<class coordtype >
int chomp::homology::tPointset< coordtype >::check ( const double *  c  )  const [inline]

Definition at line 1288 of file pointset.h.

References chomp::homology::tPointset< coordtype >::getnumber().

{
        return (getnumber (c) != -1);
} /* tPointset::check */

template<class coordtype >
void chomp::homology::tPointset< coordtype >::deallocate (  )  [inline, protected]

Definition at line 1195 of file pointset.h.

References chomp::homology::tPointset< coordtype >::grid, chomp::homology::tPointset< coordtype >::hashtable, chomp::homology::tPointset< coordtype >::maximal, chomp::homology::tPointset< coordtype >::minimal, chomp::homology::tPointset< coordtype >::ntables, chomp::homology::tPointset< coordtype >::stat, chomp::homology::tPointset< coordtype >::tables, chomp::homology::tPointset< coordtype >::temp, and chomp::homology::tPointset< coordtype >::wrap.

{
        // free the point tables
        for (int_t i = 0; i < ntables; ++ i)
        {
                if (tables [i])
                        delete [] (tables [i]);
        }
        if (tables)
                delete [] tables;

        // remove the grid and wrap tables
        if (grid)
                delete [] grid;
        if (wrap)
                delete [] wrap;

        // remove the temporary point table
        if (temp)
                delete [] temp;

        // remove the minimal and maximal coordinates
        if (minimal)
                delete [] minimal;
        if (maximal)
                delete [] maximal;

        // turn off hashing
        if (hashtable)
                delete [] hashtable;

        if (stat)
                delete stat;

        return;
} /* tPointset::deallocate */

template<class coordtype >
int chomp::homology::tPointset< coordtype >::defaultdimension ( int  d = 0  )  [inline, static]

Sets or gets the default dimension of points.

Definition at line 681 of file pointset.h.

References chomp::homology::tPointset< coordtype >::defaultdim, chomp::homology::tPointset< coordtype >::defaultgrid, and chomp::homology::tPointset< coordtype >::defaultwrap.

Referenced by chomp::homology::tPointset< coordtype >::dimension(), chomp::homology::tPointset< coordtype >::gridsize(), and chomp::homology::tPointset< coordtype >::initialize().

{
        // set the default dimension if needed
        if (d > 0)
        {
                // remove the two tables if the new dimension is higher
                if (d > defaultdim)
                {
                        if (defaultgrid)
                                delete [] defaultgrid;
                        defaultgrid = NULL;
                        if (defaultwrap)
                                delete [] defaultwrap;
                        defaultwrap = NULL;
                }

                // store the default dimension in the global variable
                defaultdim = d;
        }

        // return the default dimension of points
        return defaultdim;
} /* tPointset::defaultdimension */

template<class coordtype >
int chomp::homology::tPointset< coordtype >::dimension ( int  d  )  [inline]

Sets the dimension of points.

Definition at line 839 of file pointset.h.

References chomp::homology::tPointset< coordtype >::defaultdimension(), chomp::homology::tPointset< coordtype >::defaultgrid, chomp::homology::tPointset< coordtype >::defaultwrap, chomp::homology::tPointset< coordtype >::dim, chomp::homology::tPointset< coordtype >::grid, chomp::homology::tPointset< coordtype >::gridsize(), chomp::homology::tPointset< coordtype >::npoints, chomp::homology::tPointset< coordtype >::temp, chomp::homology::tPointset< coordtype >::wrap, and chomp::homology::tPointset< coordtype >::wrapspace().

{
        // set the default dimension if needed
        if (d > 0)
                defaultdimension (d);

        // change the dimension if the set is empty and not a subset
        if (!npoints && (d > 0))
        {
                // remove allocated tables if the new dimension is higher
                if (d > dim)
                {
                        if (grid)
                                delete [] grid;
                        grid = NULL;
                        gridsize (defaultgrid);
                        if (wrap)
                                delete [] wrap;
                        wrap = NULL;
                        wrapspace (defaultwrap);
                        if (temp)
                                delete [] temp;
                        temp = NULL;
                }

                // store the dimension in the structure
                dim = d;
        }

        // return the dimension of points
        return dim;
} /* tPointset::dimension */

template<class coordtype >
int chomp::homology::tPointset< coordtype >::dimension (  )  const [inline]

Returns the dimension of points.

Definition at line 873 of file pointset.h.

References chomp::homology::tPointset< coordtype >::dim.

Referenced by chomp::homology::tPointset< coordtype >::initialize().

{
        return dim;
} /* tPointset::dimension */

template<class coordtype >
bool chomp::homology::tPointset< coordtype >::empty (  )  const [inline]

Returns true if and only if the set of points is empty.

Definition at line 885 of file pointset.h.

References chomp::homology::tPointset< coordtype >::npoints.

{
        return !npoints;
} /* tPointset::empty */

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::gethashsize (  )  const [inline]

Definition at line 1390 of file pointset.h.

References chomp::homology::tPointset< coordtype >::hashsize.

{
        return hashsize;
} /* tPointset::gethashsize */

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::getnumber ( const double *  c  )  const [inline]
template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::getnumber ( const coordtype *  c  )  const [inline]

Definition at line 1250 of file pointset.h.

References chomp::homology::tPointset< coordtype >::hashfindpoint(), and chomp::homology::tPointset< coordtype >::hashtable.

Referenced by chomp::homology::tPointset< coordtype >::check(), chomp::homology::tPointset< coordtype >::getpoint(), and chomp::homology::tPointset< coordtype >::remove().

{
        // prevent from looking for a 'NULL' point
        if (!c)
                return -1;

        // find the position corresponding to this point in the hashing table
        int_t pos = hashfindpoint (c);

        // return the point's number found in the table
        return ((pos >= 0) ? hashtable [pos] : static_cast<int_t> (-1));
} /* tPointset::getnumber */

template<class coordtype >
coordtype * chomp::homology::tPointset< coordtype >::getpoint ( int_t  n  )  const [inline]

Definition at line 1294 of file pointset.h.

{
        return (*this) [n];
} /* tPointset::getpoint */

template<class coordtype >
coordtype * chomp::homology::tPointset< coordtype >::getpoint ( coordtype *  c  )  const [inline]

Definition at line 1300 of file pointset.h.

References chomp::homology::tPointset< coordtype >::getnumber().

{
        return (*this) [getnumber (c)];
} /* tPointset::getpoint */

template<class coordtype >
coordtype * chomp::homology::tPointset< coordtype >::getpoint ( double *  c  )  const [inline]

Definition at line 1306 of file pointset.h.

References chomp::homology::tPointset< coordtype >::getnumber().

{
        return (*this) [getnumber (c)];
} /* tPointset::getpoint */

template<class coordtype >
coordtype * chomp::homology::tPointset< coordtype >::getpoint ( int_t  n,
double *  c 
) const [inline]

Definition at line 1312 of file pointset.h.

References chomp::homology::tPointset< coordtype >::dim, and chomp::homology::tPointset< coordtype >::grid.

{
        coordtype *coord = (*this) [n];
        if (coord && c)
        {
                for (int i = 0; i < dim; ++ i)
                        c [i] = (grid ? grid [i] : 1.0) * (0.5 + coord [i]);
        }

        return coord;
} /* tPointset::getpoint */

template<class coordtype >
double * chomp::homology::tPointset< coordtype >::gridsize ( int  direction,
double  g 
) [inline]

Sets the grid size in one particular direction.

Definition at line 706 of file pointset.h.

References chomp::homology::tPointset< coordtype >::defaultdim, chomp::homology::tPointset< coordtype >::defaultdimension(), chomp::homology::tPointset< coordtype >::defaultgrid, chomp::homology::tPointset< coordtype >::dim, and chomp::homology::tPointset< coordtype >::grid.

{
        // if this is a question or wrong parameters are given,
        // return the grid
        if ((direction < 0) || (direction >= dim) || !dim || (g <= 0))
                return grid;

        // allocate memory for a new grid table if needed
        if (!grid)
        {
                grid = new double [dim];
                if (!grid)
                        throw "Can't allocate memory for the grid.";
                for (int i = 0; i < dim; ++ i)
                        grid [i] = 1.0;
        }

        // update the dimension if it was different
        if (dim != defaultdim)
                defaultdimension (dim);

        // create a new default grid table if needed
        if (!defaultgrid)
        {
                defaultgrid = new double [dim];
                if (!defaultgrid)
                        throw "Can't alloc mem for the default grid.";
                for (int i = 0; i < dim; ++ i)
                        defaultgrid [i] = grid [i];
        }

        // set the grid and the default grid coordinates
        grid [direction] = g;
        defaultgrid [direction] = g;

        // return the new grid
        return grid;
} /* point::gridsize */

template<class coordtype >
double * chomp::homology::tPointset< coordtype >::gridsize ( double *  g = 0  )  [inline]

Gets or sets the size of the grid in R^n.

Definition at line 757 of file pointset.h.

References chomp::homology::tPointset< coordtype >::dim, and chomp::homology::tPointset< coordtype >::grid.

Referenced by chomp::homology::tPointset< coordtype >::dimension(), chomp::homology::tPointset< coordtype >::gridsize(), and chomp::homology::tPointset< coordtype >::initialize().

{
        // if this is only a question, return the current grid
        if (!g)
                return grid;

        // set all the directions of the grid
        for (int i = 0; i < dim; ++ i)
                gridsize (i, g [i]);

        // return the new grid
        return grid;
} /* point::gridsize */

template<class coordtype >
double * chomp::homology::tPointset< coordtype >::gridsize ( double  g  )  [inline]

Sets the grid size (if the same in all the directions).

Definition at line 746 of file pointset.h.

References chomp::homology::tPointset< coordtype >::dim, chomp::homology::tPointset< coordtype >::grid, and chomp::homology::tPointset< coordtype >::gridsize().

{
        // set all the directions of the grid
        for (int i = 0; i < dim; ++ i)
                gridsize (i, g);

        // return the new grid
        return grid;
} /* point::gridsize */

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::hashfindpoint ( const coordtype *  c,
int_t addposition = NULL,
int  wrapped = 0 
) const [inline, protected]

Definition at line 906 of file pointset.h.

References chomp::homology::tPointset< coordtype >::add(), chomp::homology::tPointset< coordtype >::dim, chomp::homology::tPointset< coordtype >::hashsize, chomp::homology::tPointset< coordtype >::hashtable, chomp::homology::pointhashadd(), chomp::homology::pointhashkey(), chomp::homology::tPointset< coordtype >::stat, chomp::homology::tPointset< coordtype >::temp, chomp::homology::thesame(), chomp::homology::tPointset< coordtype >::wrap, and chomp::homology::wrapcoord().

Referenced by chomp::homology::tPointset< coordtype >::add(), chomp::homology::tPointset< coordtype >::getnumber(), chomp::homology::tPointset< coordtype >::rehash(), and chomp::homology::tPointset< coordtype >::remove().

{
        // if there are no points or there is no hashing table, return NULL
        if (!hashsize)
                return -1;

        // wrap coordinates if needed
        if (!wrapped && wrap)
        {
                if (!temp)
                        throw "Unable to wrap point's coordinates.";
                wrapcoord (temp, c, wrap, dim);
                c = temp;
        }

        // prepare hashing keys
        int_t pos = pointhashkey (c, dim, hashsize);
        int_t add = 0;

        // start updating hashing statistics
        ++ (stat -> hashhits);

        // find the position of the point in the hashing table
        int_t number;
        while ((number = hashtable [pos]) != -1)
        {
                if ((number >= 0) && thesame ((*this) [number], c, dim))
                        return (pos);
                if (addpos && (*addpos < 0) && (number == -2))
                        *addpos = pos;
                if (!add)
                        add = pointhashadd (c, dim, hashsize);
                pos = (pos + add) % hashsize;
                ++ (stat -> hashmisses);
        }

        // return the position in the hashing table
        return (pos);
} /* hashfindpoint */

template<class coordtype >
void chomp::homology::tPointset< coordtype >::initialize ( int_t  initialsize,
int  bequiet 
) [inline, protected]

Definition at line 1132 of file pointset.h.

References chomp::homology::tPointset< coordtype >::defaultdimension(), chomp::homology::tPointset< coordtype >::defaultgrid, chomp::homology::tPointset< coordtype >::defaultwrap, chomp::homology::tPointset< coordtype >::dim, chomp::homology::tPointset< coordtype >::dimension(), chomp::homology::tPointset< coordtype >::grid, chomp::homology::tPointset< coordtype >::gridsize(), chomp::homology::tPointset< coordtype >::hashcleared, chomp::homology::tPointset< coordtype >::hashsize, chomp::homology::tPointset< coordtype >::hashtable, chomp::homology::tPointset< coordtype >::initsize, chomp::homology::tPointset< coordtype >::maximal, chomp::homology::tPointset< coordtype >::minimal, chomp::homology::tPointset< coordtype >::npoints, chomp::homology::tPointset< coordtype >::ntables, chomp::homology::tPointset< coordtype >::quiet, chomp::homology::tPointset< coordtype >::stat, chomp::homology::tPointset< coordtype >::tablepoints, chomp::homology::tPointset< coordtype >::tables, chomp::homology::tPointset< coordtype >::temp, chomp::homology::tPointset< coordtype >::wereremoved, chomp::homology::tPointset< coordtype >::wrap, and chomp::homology::tPointset< coordtype >::wrapspace().

Referenced by chomp::homology::tPointset< coordtype >::tPointset().

{
        // set the 'quiet' variable
        quiet = bequiet;

        // correct the initial size if wrong
        if (initialsize < 0)
                initialsize = 0;

        // initialize the point tables
        npoints = 0;
        ntables = 0;
        if (initialsize <= 0)
                tablepoints = 3000;
        else if (initialsize > 10000)
                tablepoints = 10000;
        else
                tablepoints = static_cast<int> (initialsize);
        tables = NULL;

        // initialize default parameters
        dim = 0;
        grid = NULL;
        wrap = NULL;
        temp = NULL;
        wereremoved = 0;
        dimension (defaultdimension ());
        gridsize (defaultgrid);
        wrapspace (defaultwrap);

        // initialize hashing
        hashsize = 0;
        hashcleared = 0;
        hashtable = NULL;
        if (initialsize)
                initsize = initialsize + initialsize / 5 + 3;
        else
                initsize = 0;

        // optional statistic data
        stat = new psethashstat;
        minimal = NULL;
        maximal = NULL;

        return;
} /* tPointset::initialize */

template<class coordtype >
tPointset< coordtype > & chomp::homology::tPointset< coordtype >::operator= ( const tPointset< coordtype > &  p  )  [inline]

The assignment operator.

Definition at line 1234 of file pointset.h.

{
        deallocate ();
        initialize (p. size (), p. quiet);
        add (p);
        return *this;
} /* tPointset::operator = */

template<class coordtype >
coordtype * chomp::homology::tPointset< coordtype >::operator[] ( int_t  n  )  const [inline]
template<class coordtype >
void chomp::homology::tPointset< coordtype >::rehash ( int_t  newsize = 0  )  [inline, protected]

Definition at line 948 of file pointset.h.

References chomp::homology::ceilprimenumber(), chomp::homology::tPointset< coordtype >::hashcleared, chomp::homology::tPointset< coordtype >::hashfindpoint(), chomp::homology::tPointset< coordtype >::hashsize, chomp::homology::tPointset< coordtype >::hashtable, chomp::homology::tPointset< coordtype >::initsize, chomp::homology::tPointset< coordtype >::npoints, chomp::homology::tPointset< coordtype >::quiet, chomp::homology::sout, and chomp::homology::tPointset< coordtype >::stat.

Referenced by chomp::homology::tPointset< coordtype >::add(), and chomp::homology::tPointset< coordtype >::remove().

{
        // adjust the size of the hashing table if needed
        if (newsize)
                newsize = ceilprimenumber (newsize);
        else if (!npoints && initsize && !hashsize)
                newsize = ceilprimenumber (initsize);

        // if the new size is too small, make it bigger
        if (newsize <= npoints + npoints / 5)
        {
                // compute an optimal new size for adding points
                newsize = ceilprimenumber ((npoints << 1) + 131);

                // check if it is not too large for 16-bit programs
                int x = 0xFFFF;
                if ((x < 0) && (newsize >= 16384))
                        throw "Pointset too large for a 16-bit prog.";
        }

        // show a message if needed
        if (hashsize && !quiet)
                sout << "(Changing the hashing table from " << hashsize <<
                        " to " << newsize << " at " << npoints << " points) ";
        else if (!quiet)
                sout << "(Using a hashing table for " << newsize << " ";

        // remove the old hashing table and allocate a new one
        hashsize = newsize;
        if (hashtable)
                delete [] hashtable;
        hashtable = new int_t [hashsize];
        if (!hashtable)
                throw "Can't allocate memory for a hashing table.";
        for (int_t i = 0; i < hashsize; ++ i)
                hashtable [i] = -1;
        hashcleared = 0;

        // build a new hashing table
        for (int_t j = 0; j < npoints; ++ j)
        {
                int_t n = hashfindpoint ((*this) [j], NULL, 1);
                if (hashtable [n] != -1)
                        throw "A repeated point found in the hashing table.";
                hashtable [n] = j;
        }

        ++ (stat -> rehashcount);

        if (!quiet)
                sout << "points.)\n";

        return;
} /* tPointset::rehash */

template<class coordtype >
int chomp::homology::tPointset< coordtype >::remove ( const coordtype *  c  )  [inline]

Definition at line 1369 of file pointset.h.

References chomp::homology::tPointset< coordtype >::getnumber().

{
        return remove (getnumber (c));
} /* tPointset::remove */

template<class coordtype >
int chomp::homology::tPointset< coordtype >::remove ( const tPointset< coordtype > &  p  )  [inline]

Definition at line 1381 of file pointset.h.

References chomp::homology::tPointset< coordtype >::size().

{
        int_t size = p. size ();
        for (int_t i = 0; i < size; ++ i)
                remove (p [i]);
        return 0;
} /* tPointset::remove */

template<class coordtype >
int chomp::homology::tPointset< coordtype >::remove ( int_t  n  )  [inline]

Definition at line 1325 of file pointset.h.

References chomp::homology::copycoord(), chomp::homology::tPointset< coordtype >::dim, chomp::homology::tPointset< coordtype >::hashcleared, chomp::homology::tPointset< coordtype >::hashfindpoint(), chomp::homology::tPointset< coordtype >::hashtable, chomp::homology::tPointset< coordtype >::npoints, chomp::homology::tPointset< coordtype >::ntables, chomp::homology::tPointset< coordtype >::rehash(), chomp::homology::tPointset< coordtype >::tablepoints, chomp::homology::tPointset< coordtype >::tables, and chomp::homology::tPointset< coordtype >::wereremoved.

{
        if ((n < 0) || (n >= npoints))
                return -1;
        wereremoved = 1;

        // find the point's place in the hashing table
        coordtype *coord = (*this) [n];
        int_t pos = hashfindpoint (coord);

        // fill in this entry in the hashing table with -2 (cleared)
        hashtable [pos] = -2;

        // copy the last point in the set to replace the point being removed
        if (n != npoints - 1)
        {
                coordtype *lastcoord = (*this) [npoints - 1];
                int_t lastpos = hashfindpoint (lastcoord);
                hashtable [lastpos] = n;
                copycoord (coord, lastcoord, dim);
        }

        // free an unused table with points' coordinates if it is sensible
        int_t tablenumber = npoints / tablepoints;
        if ((tablenumber + 2 < ntables) && tables [tablenumber + 2])
        {
                delete [] (tables [tablenumber + 2]);
                tables [tablenumber + 2] = NULL;
        }

        // decrease the number of points in the set
        -- npoints;

        // update the number of cleared entries in the hashing table
        ++ hashcleared;

        // rehash if recommended
        if (hashcleared > npoints + 13)
                rehash (13);

        return (0);
} /* tPointset::remove */

template<class coordtype >
int chomp::homology::tPointset< coordtype >::remove ( const double *  c  )  [inline]

Definition at line 1375 of file pointset.h.

References chomp::homology::tPointset< coordtype >::getnumber().

{
        return remove (getnumber (c));
} /* tPointset::remove */

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::size (  )  const [inline]

Returns the number of points in the set.

Definition at line 879 of file pointset.h.

References chomp::homology::tPointset< coordtype >::npoints.

Referenced by chomp::homology::tPointset< coordtype >::remove(), and chomp::homology::tPointset< coordtype >::tPointset().

{
        return npoints;
} /* tPointset::size */

template<class coordtype >
const coordtype * chomp::homology::tPointset< coordtype >::wrapspace ( coordtype  w  )  [inline]

Definition at line 813 of file pointset.h.

References chomp::homology::tPointset< coordtype >::dim, chomp::homology::tPointset< coordtype >::wrap, and chomp::homology::tPointset< coordtype >::wrapspace().

{
        // set all the directions of the wrap table
        for (int i = 0; i < dim; ++ i)
                wrapspace (i, w);

        // return the new wrap table
        return wrap;
} /* point::wrapspace */

template<class coordtype >
const coordtype * chomp::homology::tPointset< coordtype >::wrapspace ( int  direction,
coordtype  w 
) [inline]

Definition at line 773 of file pointset.h.

{
        // if this is a question or wrong parameters are given,
        // return the wrap table
        if ((direction < 0) || (direction >= dim) || !dim || (w < 0))
                return wrap;

        // allocate memory for a new wrap table if needed
        if (!wrap)
        {
                wrap = new coordtype [dim];
                if (!wrap)
                        throw "Can't alloc mem for the wrap table.";
                for (int i = 0; i < dim; ++ i)
                        wrap [i] = 0;
        }

        // update the dimension if it was different
        if (dim != defaultdim)
                defaultdimension (dim);

        // create a new default wrap table if needed
        if (!defaultwrap)
        {
                defaultwrap = new coordtype [dim];
                if (!defaultwrap)
                        throw "Can't alloc mem for the def. WrapTab.";
                for (int i = 0; i < dim; ++ i)
                        defaultwrap [i] = wrap [i];
        }

        // set the wrap and the default wrap coordinates
        wrap [direction] = w;
        defaultwrap [direction] = w;

        // return the new wrap table
        return wrap;
} /* point::wrapspace */

template<class coordtype >
const coordtype * chomp::homology::tPointset< coordtype >::wrapspace ( const coordtype *  w = NULL  )  [inline]

Definition at line 824 of file pointset.h.

References chomp::homology::tPointset< coordtype >::dim, and chomp::homology::tPointset< coordtype >::wrap.

Referenced by chomp::homology::tPointset< coordtype >::dimension(), chomp::homology::tPointset< coordtype >::initialize(), and chomp::homology::tPointset< coordtype >::wrapspace().

{
        // if this is only a question, return the current wrap
        if (!w)
                return wrap;

        // set all the directions of the wrap table
        for (int i = 0; i < dim; ++ i)
                wrapspace (i, w [i]);

        // return the new wrap table
        return wrap;
} /* point::wrapspace */


Member Data Documentation

template<class coordtype>
int chomp::homology::tPointset< coordtype >::defaultdim = 0 [static, protected]
template<class coordtype>
double * chomp::homology::tPointset< coordtype >::defaultgrid = NULL [static, protected]
template<class coordtype>
coordtype * chomp::homology::tPointset< coordtype >::defaultwrap = NULL [static, protected]
template<class coordtype>
int chomp::homology::tPointset< coordtype >::dim [protected]
template<class coordtype>
double* chomp::homology::tPointset< coordtype >::grid [protected]
template<class coordtype>
int_t chomp::homology::tPointset< coordtype >::hashcleared [protected]
template<class coordtype>
int_t chomp::homology::tPointset< coordtype >::hashsize [protected]
template<class coordtype>
int_t* chomp::homology::tPointset< coordtype >::hashtable [protected]
template<class coordtype>
unsigned chomp::homology::tPointset< coordtype >::initsize [protected]
template<class coordtype>
coordtype * chomp::homology::tPointset< coordtype >::maximal
template<class coordtype>
coordtype* chomp::homology::tPointset< coordtype >::minimal
template<class coordtype>
int_t chomp::homology::tPointset< coordtype >::npoints [protected]
template<class coordtype>
int_t chomp::homology::tPointset< coordtype >::ntables [protected]
template<class coordtype>
int chomp::homology::tPointset< coordtype >::quiet

Returns the number of points by simply projecting the set onto an integer number.

WARNING: This function is DEPRECATED! Use the functions "size" and "empty" instead.

Definition at line 577 of file pointset.h.

Referenced by chomp::homology::tPointset< coordtype >::initialize(), chomp::homology::tPointset< coordtype >::rehash(), and chomp::homology::tPointset< coordtype >::tPointset().

template<class coordtype>
psethashstat* chomp::homology::tPointset< coordtype >::stat
template<class coordtype>
int chomp::homology::tPointset< coordtype >::tablepoints [protected]
template<class coordtype>
coordtype** chomp::homology::tPointset< coordtype >::tables [protected]
template<class coordtype>
coordtype* chomp::homology::tPointset< coordtype >::temp [protected]
template<class coordtype>
int chomp::homology::tPointset< coordtype >::wereremoved
template<class coordtype>
coordtype* chomp::homology::tPointset< coordtype >::wrap [protected]

The documentation for this class was generated from the following file: