The Original CHomP Software
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
chomp::homology::tPointset< coordtype > Class Template Reference

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

#include <pointset.h>

Public Types

typedef coordtype CoordType
 The type of coordinates. More...
 

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. More...
 
 tPointset (const tPointset< coordtype > &p)
 The copy constructor. More...
 
tPointsetoperator= (const tPointset< coordtype > &p)
 The assignment operator. More...
 
 ~tPointset ()
 The destructor. More...
 
int dimension (int d)
 Sets the dimension of points. More...
 
int dimension () const
 Returns the dimension of points. More...
 
double * gridsize (double *g=0)
 Gets or sets the size of the grid in R^n. More...
 
double * gridsize (double g)
 Sets the grid size (if the same in all the directions). More...
 
double * gridsize (int direction, double g)
 Sets the grid size in one particular direction. More...
 
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 checkRounded (const double *c) const
 
int_t getnumber (const coordtype *c) const
 
int_t getnumberRounded (const double *c) const
 
coordtype * operator[] (int_t n) const
 
coordtype * getpoint (int_t n) const
 
coordtype * getpoint (coordtype *c) const
 
coordtype * getpointRounded (double *c) const
 
coordtype * getpointMiddle (int_t n, double *c) const
 
int_t add (const coordtype *c)
 
int_t addRounded (double *c)
 
tPointsetadd (const tPointset< coordtype > &p)
 
int remove (int_t n)
 
int remove (const coordtype *c)
 
int removeRounded (const double *c)
 
int remove (const tPointset< coordtype > &p)
 
int_t size () const
 Returns the number of points in the set. More...
 
bool empty () const
 Returns true if and only if the set of points is empty. More...
 
int_t gethashsize () const
 
void swap (tPointset< coordtype > &other)
 Swaps the data with another object of the same type. More...
 

Static Public Member Functions

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

Public Attributes

int quiet
 Returns the number of points by simply projecting the set onto an integer number. More...
 
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 481 of file pointset.h.

Member Typedef Documentation

◆ CoordType

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

The type of coordinates.

Definition at line 485 of file pointset.h.

Constructor & Destructor Documentation

◆ tPointset() [1/2]

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 1223 of file pointset.h.

1224{
1225 initialize (initialsize, bequiet);
1226 return;
1227} /* tPointset::tPointset */
void initialize(int_t initialsize, int bequiet)
Definition: pointset.h:1175

◆ tPointset() [2/2]

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

The copy constructor.

Definition at line 1230 of file pointset.h.

1231{
1232 initialize (p. size (), p. quiet);
1233 add (p);
1234 return;
1235} /* tPointset::tPointset */
int quiet
Returns the number of points by simply projecting the set onto an integer number.
Definition: pointset.h:593
int_t size() const
Returns the number of points in the set.
Definition: pointset.h:897
int_t add(const coordtype *c)
Definition: pointset.h:1047

◆ ~tPointset()

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

The destructor.

Definition at line 1276 of file pointset.h.

1289{
1290 deallocate ();
1291 return;
1292} /* tPointset::~tPointset */

Member Function Documentation

◆ add() [1/2]

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

Definition at line 1047 of file pointset.h.

1048{
1049 // prevent from adding a 'NULL' point
1050 if (!c)
1051 return -1;
1052
1053 // check if the dimension of the point is known
1054 if (!dim)
1055 throw "Trying to add a point of unknown dimension.";
1056
1057 // wrap the point's coordinates if needed
1058 if (wrap)
1059 {
1060 if (!temp)
1061 temp = allocatepoint<coordtype> (dim);
1062 wrapcoord (temp, c, wrap, dim);
1063 c = temp;
1064 }
1065
1066 // increase the size of the hashing table if needed
1067 if (hashsize - hashcleared <= npoints + npoints / 5)
1068 rehash ();
1069
1070 // find a place for the new point
1071 int_t addpos = -1;
1072 int_t pos = hashfindpoint (c, &addpos, 1);
1073
1074 // if the point is already in the set, return its number
1075 if (hashtable [pos] >= 0)
1076 return hashtable [pos];
1077
1078 // update the range of coordinates for statistical purposes
1079 if (minimal)
1080 {
1081 for (int i = 0; i < dim; ++ i)
1082 if (minimal [i] > c [i])
1083 minimal [i] = c [i];
1084 }
1085 else
1086 {
1087 minimal = allocatepoint<coordtype> (dim);
1088 copycoord (minimal, c, dim);
1089 }
1090
1091 if (maximal)
1092 {
1093 for (int i = 0; i < dim; ++ i)
1094 if (maximal [i] < c [i])
1095 maximal [i] = c [i];
1096 }
1097 else
1098 {
1099 maximal = allocatepoint<coordtype> (dim);
1100 copycoord (maximal, c, dim);
1101 }
1102
1103 // write the point's number into the hashing table
1104 if (addpos >= 0)
1105 {
1106 pos = addpos;
1107 if (hashtable [pos] == -2)
1108 -- hashcleared;
1109 }
1110 hashtable [pos] = npoints;
1111
1112 // compute the number of the table in which the point's coordinates
1113 // should be stored
1114 int_t tablenumber = npoints / tablepoints;
1115
1116 // if there are not enough tables, add some
1117 if (tablenumber >= ntables)
1118 {
1119 int_t moretables = (ntables << 1) + 13;
1120 coordtype **newtables = new coordtype * [moretables];
1121 if (!newtables)
1122 throw "Unable to alloc a table for tables.";
1123 for (int_t i = 0; i < moretables; ++ i)
1124 newtables [i] = (i < ntables) ? (tables [i]) :
1125 (coordtype *) NULL;
1126 if (tables)
1127 delete [] tables;
1128 tables = newtables;
1129 ntables = moretables;
1130 }
1131
1132 // if the appropriate table has not been allocate yet, allocate it
1133 if (tables [tablenumber] == NULL)
1134 {
1135 tables [tablenumber] = new coordtype [tablepoints * dim];
1136 if (!tables [tablenumber])
1137 throw "Unable to alloc a table for coords.";
1138 }
1139
1140 // copy the point's coordinates into the table
1141 copycoord (tables [tablenumber] +
1142 ((npoints % tablepoints) * dim), c, dim);
1143
1144 // return the point's number and increase the number of points
1145 // in the set
1146 return (npoints ++);
1147} /* tPointset::add */
int_t hashfindpoint(const coordtype *c, int_t *addposition=NULL, int wrapped=0) const
Definition: pointset.h:949
void rehash(int_t newsize=0)
Definition: pointset.h:991
int int_t
Index type for indexing arrays, counting cubes, etc.
Definition: config.h:115
void wrapcoord(coordtype *destination, const coordtype *source, const coordtype *wrap, int dim)
Wraps coordinates stored in 'c' accordint to the wrap table 'wrap' and store the result in the table ...
Definition: pointset.h:119
void copycoord(coordtype *destination, const coordtype *source, int dim)
Copies the coordinates of one point to another.
Definition: pointset.h:108

References chomp::homology::copycoord(), and chomp::homology::wrapcoord().

◆ add() [2/2]

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

Definition at line 1165 of file pointset.h.

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

◆ addRounded()

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

Definition at line 1150 of file pointset.h.

1151{
1152 // prevent from adding a 'NULL' point
1153 if (!c)
1154 return -1;
1155
1156 if (!dim)
1157 throw "Trying to add a point of unknown dimension.";
1158 if (!temp)
1159 temp = allocatepoint<coordtype> (dim);
1160 roundpoint (c, temp, grid, dim);
1161 return add (temp);
1162} /* tPointset::addRounded */
void roundpoint(const double *p, coordtype *c, const double *grid, int dim)
Rounds down the double coordinates of a point to integer ones.
Definition: pointset.h:226

References chomp::homology::roundpoint().

◆ check() [1/2]

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

Definition at line 1327 of file pointset.h.

1328{
1329 return (getnumber (c) != -1);
1330} /* tPointset::check */
int_t getnumber(const coordtype *c) const
Definition: pointset.h:1295

◆ check() [2/2]

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

Definition at line 1321 of file pointset.h.

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

◆ checkRounded()

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

Definition at line 1333 of file pointset.h.

1334{
1335 return (getnumber (c) != -1);
1336} /* tPointset::checkRounded */

◆ deallocate()

template<class coordtype >
void chomp::homology::tPointset< coordtype >::deallocate
inlineprotected

Definition at line 1238 of file pointset.h.

1239{
1240 // free the point tables
1241 for (int_t i = 0; i < ntables; ++ i)
1242 {
1243 if (tables [i])
1244 delete [] (tables [i]);
1245 }
1246 if (tables)
1247 delete [] tables;
1248
1249 // remove the grid and wrap tables
1250 if (grid)
1251 delete [] grid;
1252 if (wrap)
1253 delete [] wrap;
1254
1255 // remove the temporary point table
1256 if (temp)
1257 delete [] temp;
1258
1259 // remove the minimal and maximal coordinates
1260 if (minimal)
1261 delete [] minimal;
1262 if (maximal)
1263 delete [] maximal;
1264
1265 // turn off hashing
1266 if (hashtable)
1267 delete [] hashtable;
1268
1269 if (stat)
1270 delete stat;
1271
1272 return;
1273} /* tPointset::deallocate */
psethashstat * stat
Definition: pointset.h:605

◆ defaultdimension()

template<class coordtype >
int chomp::homology::tPointset< coordtype >::defaultdimension ( int  d = 0)
inlinestatic

Sets or gets the default dimension of points.

Definition at line 699 of file pointset.h.

700{
701 // set the default dimension if needed
702 if (d > 0)
703 {
704 // remove the two tables if the new dimension is higher
705 if (d > defaultdim)
706 {
707 if (defaultgrid)
708 delete [] defaultgrid;
709 defaultgrid = NULL;
710 if (defaultwrap)
711 delete [] defaultwrap;
712 defaultwrap = NULL;
713 }
714
715 // store the default dimension in the global variable
716 defaultdim = d;
717 }
718
719 // return the default dimension of points
720 return defaultdim;
721} /* tPointset::defaultdimension */
static double * defaultgrid
Definition: pointset.h:649
static coordtype * defaultwrap
Definition: pointset.h:650

◆ dimension() [1/2]

template<class coordtype >
int chomp::homology::tPointset< coordtype >::dimension
inline

Returns the dimension of points.

Definition at line 891 of file pointset.h.

892{
893 return dim;
894} /* tPointset::dimension */

◆ dimension() [2/2]

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

Sets the dimension of points.

Definition at line 857 of file pointset.h.

858{
859 // set the default dimension if needed
860 if (d > 0)
862
863 // change the dimension if the set is empty and not a subset
864 if (!npoints && (d > 0))
865 {
866 // remove allocated tables if the new dimension is higher
867 if (d > dim)
868 {
869 if (grid)
870 delete [] grid;
871 grid = NULL;
873 if (wrap)
874 delete [] wrap;
875 wrap = NULL;
877 if (temp)
878 delete [] temp;
879 temp = NULL;
880 }
881
882 // store the dimension in the structure
883 dim = d;
884 }
885
886 // return the dimension of points
887 return dim;
888} /* tPointset::dimension */
double * gridsize(double *g=0)
Gets or sets the size of the grid in R^n.
Definition: pointset.h:775
const coordtype * wrapspace(const coordtype *w=NULL)
Definition: pointset.h:842
static int defaultdimension(int d=0)
Sets or gets the default dimension of points.
Definition: pointset.h:699

◆ empty()

template<class coordtype >
bool chomp::homology::tPointset< coordtype >::empty
inline

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

Definition at line 903 of file pointset.h.

904{
905 return !npoints;
906} /* tPointset::empty */

◆ gethashsize()

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::gethashsize
inline

Definition at line 1435 of file pointset.h.

1436{
1437 return hashsize;
1438} /* tPointset::gethashsize */

◆ getnumber()

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

Definition at line 1295 of file pointset.h.

1296{
1297 // prevent from looking for a 'NULL' point
1298 if (!c)
1299 return -1;
1300
1301 // find the position corresponding to this point in the hashing table
1302 int_t pos = hashfindpoint (c);
1303
1304 // return the point's number found in the table
1305 return ((pos >= 0) ? hashtable [pos] : static_cast<int_t> (-1));
1306} /* tPointset::getnumber */

◆ getnumberRounded()

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

Definition at line 1309 of file pointset.h.

1310{
1311 if (!npoints)
1312 return -1;
1313 if (!temp)
1314 throw "Cannot round point's coordinates.";
1315 roundpoint (c, temp, grid, dim);
1316 int_t pos = hashfindpoint (temp);
1317 return ((pos >= 0) ? hashtable [pos] : static_cast<int_t> (-1));
1318} /* tPointset::getnumberRounded */

References chomp::homology::roundpoint().

◆ getpoint() [1/2]

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

Definition at line 1345 of file pointset.h.

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

◆ getpoint() [2/2]

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

Definition at line 1339 of file pointset.h.

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

◆ getpointMiddle()

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

Definition at line 1357 of file pointset.h.

1358{
1359 coordtype *coord = (*this) [n];
1360 if (coord && c)
1361 {
1362 for (int i = 0; i < dim; ++ i)
1363 c [i] = (grid ? grid [i] : 1.0) * (0.5 + coord [i]);
1364 }
1365
1366 return coord;
1367} /* tPointset::getpointMiddle */

◆ getpointRounded()

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

Definition at line 1351 of file pointset.h.

1352{
1353 return (*this) [getnumberRounded (c)];
1354} /* tPointset::getpointRounded */
int_t getnumberRounded(const double *c) const
Definition: pointset.h:1309

◆ gridsize() [1/3]

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 775 of file pointset.h.

776{
777 // if this is only a question, return the current grid
778 if (!g)
779 return grid;
780
781 // set all the directions of the grid
782 for (int i = 0; i < dim; ++ i)
783 gridsize (i, g [i]);
784
785 // return the new grid
786 return grid;
787} /* point::gridsize */

◆ gridsize() [2/3]

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 764 of file pointset.h.

765{
766 // set all the directions of the grid
767 for (int i = 0; i < dim; ++ i)
768 gridsize (i, g);
769
770 // return the new grid
771 return grid;
772} /* point::gridsize */

◆ gridsize() [3/3]

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 724 of file pointset.h.

725{
726 // if this is a question or wrong parameters are given,
727 // return the grid
728 if ((direction < 0) || (direction >= dim) || !dim || (g <= 0))
729 return grid;
730
731 // allocate memory for a new grid table if needed
732 if (!grid)
733 {
734 grid = new double [dim];
735 if (!grid)
736 throw "Can't allocate memory for the grid.";
737 for (int i = 0; i < dim; ++ i)
738 grid [i] = 1.0;
739 }
740
741 // update the dimension if it was different
742 if (dim != defaultdim)
744
745 // create a new default grid table if needed
746 if (!defaultgrid)
747 {
748 defaultgrid = new double [dim];
749 if (!defaultgrid)
750 throw "Can't alloc mem for the default grid.";
751 for (int i = 0; i < dim; ++ i)
752 defaultgrid [i] = grid [i];
753 }
754
755 // set the grid and the default grid coordinates
756 grid [direction] = g;
757 defaultgrid [direction] = g;
758
759 // return the new grid
760 return grid;
761} /* point::gridsize */

◆ hashfindpoint()

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

Definition at line 949 of file pointset.h.

951{
952 // if there are no points or there is no hashing table, return NULL
953 if (!hashsize)
954 return -1;
955
956 // wrap coordinates if needed
957 if (!wrapped && wrap)
958 {
959 if (!temp)
960 throw "Unable to wrap point's coordinates.";
961 wrapcoord (temp, c, wrap, dim);
962 c = temp;
963 }
964
965 // prepare hashing keys
966 int_t pos = pointhashkey (c, dim, hashsize);
967 int_t add = 0;
968
969 // start updating hashing statistics
970 ++ (stat -> hashhits);
971
972 // find the position of the point in the hashing table
973 int_t number;
974 while ((number = hashtable [pos]) != -1)
975 {
976 if ((number >= 0) && thesame ((*this) [number], c, dim))
977 return (pos);
978 if (addpos && (*addpos < 0) && (number == -2))
979 *addpos = pos;
980 if (!add)
982 pos = (pos + add) % hashsize;
983 ++ (stat -> hashmisses);
984 }
985
986 // return the position in the hashing table
987 return (pos);
988} /* hashfindpoint */
int thesame(const coordtype *c1, const coordtype *c2, int dim)
Compare two points. Returns true iff they have the same coordinates.
Definition: pointset.h:98
int_t pointhashkey(const coordtype *c, int dim, int_t hashsize)
Generates the main hashing key for points.
Definition: pointset.h:180
int_t pointhashadd(const coordtype *c, int dim, int_t hashsize)
Generates the second hashing key for points.
Definition: pointset.h:198

References chomp::homology::pointhashadd(), chomp::homology::pointhashkey(), chomp::homology::thesame(), and chomp::homology::wrapcoord().

◆ initialize()

template<class coordtype >
void chomp::homology::tPointset< coordtype >::initialize ( int_t  initialsize,
int  bequiet 
)
inlineprotected

Definition at line 1175 of file pointset.h.

1176{
1177 // set the 'quiet' variable
1178 quiet = bequiet;
1179
1180 // correct the initial size if wrong
1181 if (initialsize < 0)
1182 initialsize = 0;
1183
1184 // initialize the point tables
1185 npoints = 0;
1186 ntables = 0;
1187 if (initialsize <= 0)
1188 tablepoints = 3000;
1189 else if (initialsize > 10000)
1190 tablepoints = 10000;
1191 else
1192 tablepoints = static_cast<int> (initialsize);
1193 tables = NULL;
1194
1195 // initialize default parameters
1196 dim = 0;
1197 grid = NULL;
1198 wrap = NULL;
1199 temp = NULL;
1200 wereremoved = 0;
1204
1205 // initialize hashing
1206 hashsize = 0;
1207 hashcleared = 0;
1208 hashtable = NULL;
1209 if (initialsize)
1210 initsize = initialsize + initialsize / 5 + 3;
1211 else
1212 initsize = 0;
1213
1214 // optional statistic data
1215 stat = new psethashstat;
1216 minimal = NULL;
1217 maximal = NULL;
1218
1219 return;
1220} /* tPointset::initialize */
int dimension() const
Returns the dimension of points.
Definition: pointset.h:891

◆ operator=()

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

The assignment operator.

Definition at line 1276 of file pointset.h.

1278{
1279 if (this == &p)
1280 return *this;
1281 deallocate ();
1282 initialize (p. size (), p. quiet);
1283 add (p);
1284 return *this;
1285} /* tPointset::operator = */

◆ operator[]()

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

Definition at line 940 of file pointset.h.

941{
942 if ((n < 0) || (n >= npoints))
943 return NULL;
944
945 return (tables [n / tablepoints] + (n % tablepoints) * dim);
946} /* tPointset::operator [] */

◆ rehash()

template<class coordtype >
void chomp::homology::tPointset< coordtype >::rehash ( int_t  newsize = 0)
inlineprotected

Definition at line 991 of file pointset.h.

992{
993 // adjust the size of the hashing table if needed
994 if (newsize)
995 newsize = ceilprimenumber (newsize);
996 else if (!npoints && initsize && !hashsize)
997 newsize = ceilprimenumber (initsize);
998
999 // if the new size is too small, make it bigger
1000 if (newsize <= npoints + npoints / 5)
1001 {
1002 // compute an optimal new size for adding points
1003 newsize = ceilprimenumber ((npoints << 1) + 131);
1004
1005 // check if it is not too large for 16-bit programs
1006 int x = 0xFFFF;
1007 if ((x < 0) && (newsize >= 16384))
1008 throw "Pointset too large for a 16-bit prog.";
1009 }
1010
1011 // show a message if needed
1012 if (hashsize && !quiet)
1013 sout << "(Changing the hashing table from " << hashsize <<
1014 " to " << newsize << " at " << npoints << " points) ";
1015 else if (!quiet)
1016 sout << "(Using a hashing table for " << newsize << " ";
1017
1018 // remove the old hashing table and allocate a new one
1019 hashsize = newsize;
1020 if (hashtable)
1021 delete [] hashtable;
1022 hashtable = new int_t [hashsize];
1023 if (!hashtable)
1024 throw "Can't allocate memory for a hashing table.";
1025 for (int_t i = 0; i < hashsize; ++ i)
1026 hashtable [i] = -1;
1027 hashcleared = 0;
1028
1029 // build a new hashing table
1030 for (int_t j = 0; j < npoints; ++ j)
1031 {
1032 int_t n = hashfindpoint ((*this) [j], NULL, 1);
1033 if (hashtable [n] != -1)
1034 throw "A repeated point found in the hashing table.";
1035 hashtable [n] = j;
1036 }
1037
1038 ++ (stat -> rehashcount);
1039
1040 if (!quiet)
1041 sout << "points.)\n";
1042
1043 return;
1044} /* tPointset::rehash */
outputstream sout
A replacement for standard output stream, with optional logging and other features provided by the cl...
unsigned ceilprimenumber(unsigned n)
Computes the smallest prime number greater than or equal to the given number.
Definition: pointset.h:170

References chomp::homology::ceilprimenumber(), and chomp::homology::sout.

◆ remove() [1/3]

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

Definition at line 1414 of file pointset.h.

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

◆ remove() [2/3]

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

Definition at line 1426 of file pointset.h.

1427{
1428 int_t size = p. size ();
1429 for (int_t i = 0; i < size; ++ i)
1430 remove (p [i]);
1431 return 0;
1432} /* tPointset::remove */

◆ remove() [3/3]

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

Definition at line 1370 of file pointset.h.

1371{
1372 if ((n < 0) || (n >= npoints))
1373 return -1;
1374 wereremoved = 1;
1375
1376 // find the point's place in the hashing table
1377 coordtype *coord = (*this) [n];
1378 int_t pos = hashfindpoint (coord);
1379
1380 // fill in this entry in the hashing table with -2 (cleared)
1381 hashtable [pos] = -2;
1382
1383 // copy the last point in the set to replace the point being removed
1384 if (n != npoints - 1)
1385 {
1386 coordtype *lastcoord = (*this) [npoints - 1];
1387 int_t lastpos = hashfindpoint (lastcoord);
1388 hashtable [lastpos] = n;
1389 copycoord (coord, lastcoord, dim);
1390 }
1391
1392 // free an unused table with points' coordinates if it is sensible
1393 int_t tablenumber = npoints / tablepoints;
1394 if ((tablenumber + 2 < ntables) && tables [tablenumber + 2])
1395 {
1396 delete [] (tables [tablenumber + 2]);
1397 tables [tablenumber + 2] = NULL;
1398 }
1399
1400 // decrease the number of points in the set
1401 -- npoints;
1402
1403 // update the number of cleared entries in the hashing table
1404 ++ hashcleared;
1405
1406 // rehash if recommended
1407 if (hashcleared > npoints + 13)
1408 rehash (13);
1409
1410 return (0);
1411} /* tPointset::remove */

References chomp::homology::copycoord().

◆ removeRounded()

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

Definition at line 1420 of file pointset.h.

1421{
1422 return remove (getnumberRounded (c));
1423} /* tPointset::removeRounded */

◆ size()

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::size
inline

Returns the number of points in the set.

Definition at line 897 of file pointset.h.

898{
899 return npoints;
900} /* tPointset::size */

◆ swap()

template<class coordtype >
void chomp::homology::tPointset< coordtype >::swap ( tPointset< coordtype > &  other)
inline

Swaps the data with another object of the same type.

Definition at line 909 of file pointset.h.

910{
911 if (this == &other)
912 return;
913 std::swap (this -> quiet, other. quiet);
914 std::swap (this -> stat, other. stat);
915 std::swap (this -> minimal, other. minimal);
916 std::swap (this -> maximal, other. maximal);
917 std::swap (this -> wereremoved, other. wereremoved);
918 std::swap (this -> dim, other. dim);
919 std::swap (this -> npoints, other. npoints);
920 std::swap (this -> ntables, other. ntables);
921 std::swap (this -> tablepoints, other. tablepoints);
922 std::swap (this -> tables, other. tables);
923 std::swap (this -> grid, other. grid);
924 std::swap (this -> wrap, other. wrap);
925 std::swap (this -> temp, other. temp);
926 std::swap (this -> hashsize, other. hashsize);
927 std::swap (this -> hashcleared, other. hashcleared);
928 std::swap (this -> hashtable, other. hashtable);
929 std::swap (this -> initsize, other. initsize);
930 return;
931} /* tPointset::tPointset */
void swap(mwWorkerData &data1, mwWorkerData &data2)
Definition: mwcoord.h:108

References chomp::multiwork::swap().

◆ wrapspace() [1/3]

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

Definition at line 842 of file pointset.h.

843{
844 // if this is only a question, return the current wrap
845 if (!w)
846 return wrap;
847
848 // set all the directions of the wrap table
849 for (int i = 0; i < dim; ++ i)
850 wrapspace (i, w [i]);
851
852 // return the new wrap table
853 return wrap;
854} /* point::wrapspace */

◆ wrapspace() [2/3]

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

Definition at line 831 of file pointset.h.

832{
833 // set all the directions of the wrap table
834 for (int i = 0; i < dim; ++ i)
835 wrapspace (i, w);
836
837 // return the new wrap table
838 return wrap;
839} /* point::wrapspace */

◆ wrapspace() [3/3]

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

Definition at line 790 of file pointset.h.

792{
793 // if this is a question or wrong parameters are given,
794 // return the wrap table
795 if ((direction < 0) || (direction >= dim) || !dim || (w < 0))
796 return wrap;
797
798 // allocate memory for a new wrap table if needed
799 if (!wrap)
800 {
801 wrap = new coordtype [dim];
802 if (!wrap)
803 throw "Can't alloc mem for the wrap table.";
804 for (int i = 0; i < dim; ++ i)
805 wrap [i] = 0;
806 }
807
808 // update the dimension if it was different
809 if (dim != defaultdim)
811
812 // create a new default wrap table if needed
813 if (!defaultwrap)
814 {
815 defaultwrap = new coordtype [dim];
816 if (!defaultwrap)
817 throw "Can't alloc mem for the def. WrapTab.";
818 for (int i = 0; i < dim; ++ i)
819 defaultwrap [i] = wrap [i];
820 }
821
822 // set the wrap and the default wrap coordinates
823 wrap [direction] = w;
824 defaultwrap [direction] = w;
825
826 // return the new wrap table
827 return wrap;
828} /* point::wrapspace */

Member Data Documentation

◆ defaultdim

template<class coordtype >
int chomp::homology::tPointset< coordtype >::defaultdim = 0
staticprotected

Definition at line 648 of file pointset.h.

◆ defaultgrid

template<class coordtype >
double * chomp::homology::tPointset< coordtype >::defaultgrid = NULL
staticprotected

Definition at line 649 of file pointset.h.

◆ defaultwrap

template<class coordtype >
coordtype * chomp::homology::tPointset< coordtype >::defaultwrap = NULL
staticprotected

Definition at line 650 of file pointset.h.

◆ dim

template<class coordtype >
int chomp::homology::tPointset< coordtype >::dim
protected

Definition at line 622 of file pointset.h.

◆ grid

template<class coordtype >
double* chomp::homology::tPointset< coordtype >::grid
protected

Definition at line 638 of file pointset.h.

◆ hashcleared

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::hashcleared
protected

Definition at line 663 of file pointset.h.

◆ hashsize

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::hashsize
protected

Definition at line 660 of file pointset.h.

◆ hashtable

template<class coordtype >
int_t* chomp::homology::tPointset< coordtype >::hashtable
protected

Definition at line 666 of file pointset.h.

◆ initsize

template<class coordtype >
unsigned chomp::homology::tPointset< coordtype >::initsize
protected

Definition at line 669 of file pointset.h.

◆ maximal

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

Definition at line 608 of file pointset.h.

◆ minimal

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

Definition at line 608 of file pointset.h.

◆ npoints

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::npoints
protected

Definition at line 625 of file pointset.h.

◆ ntables

template<class coordtype >
int_t chomp::homology::tPointset< coordtype >::ntables
protected

Definition at line 628 of file pointset.h.

◆ quiet

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 593 of file pointset.h.

◆ stat

template<class coordtype >
psethashstat* chomp::homology::tPointset< coordtype >::stat

Definition at line 605 of file pointset.h.

◆ tablepoints

template<class coordtype >
int chomp::homology::tPointset< coordtype >::tablepoints
protected

Definition at line 631 of file pointset.h.

◆ tables

template<class coordtype >
coordtype** chomp::homology::tPointset< coordtype >::tables
protected

Definition at line 635 of file pointset.h.

◆ temp

template<class coordtype >
coordtype* chomp::homology::tPointset< coordtype >::temp
protected

Definition at line 645 of file pointset.h.

◆ wereremoved

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

Definition at line 614 of file pointset.h.

◆ wrap

template<class coordtype >
coordtype* chomp::homology::tPointset< coordtype >::wrap
protected

Definition at line 641 of file pointset.h.


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