28 #ifndef _CHAINCON_CHAIN_H_ 29 #define _CHAINCON_CHAIN_H_ 37 #include "chomp/system/config.h" 38 #include "chomp/struct/hashsets.h" 49 template <
class CellT,
class CoefT>
69 const CellT &
getCell (int_t n)
const;
72 const CoefT &
getCoef (int_t n)
const;
76 int_t
position (
const CellT &c)
const;
79 void add (
const CellT &cell,
const CoefT &coef);
98 chomp::homology::hashedset<CellT>
cells;
107 template <
class CellT,
class CoefT>
114 template <
class CellT,
class CoefT>
120 template <
class CellT,
class CoefT>
126 template <
class CellT,
class CoefT>
132 template <
class CellT,
class CoefT>
138 template <
class CellT,
class CoefT>
141 return cells. getnumber (c);
144 template <
class CellT,
class CoefT>
147 int_t pos =
cells. getnumber (cell);
156 CoefT &c =
coefs [pos];
160 cells. removenum (pos);
171 template <
class CellT,
class CoefT>
183 for (int_t i = 0; i <
size; ++ i)
189 template <
class CellT,
class CoefT>
193 for (int_t i = 0; i <
size; ++ i)
198 template <
class CellT,
class CoefT>
204 chomp::homology::hashedset<CellT> emptyCells (1);
212 for (int_t i = 0; i <
size; ++ i)
218 template <
class CellT,
class CoefT>
223 if (size != ch.
cells. size ())
225 for (int_t pos = 0; pos <
size; ++ pos)
227 int_t chPos = ch.
cells. getnumber (
cells [pos]);
236 template <
class CellT,
class CoefT>
247 template <
class CellT,
class CoefT>
248 std::ostream &operator << (std::ostream &out, const tChain<CellT,CoefT> &c)
255 for (int_t i = 0; i <
size; ++ i)
266 template <
class CellT,
class CoefT>
269 throw "Operator >> not implemented for tChain.";
276 template <
class CellT,
class CoefT>
286 template <
class CellT,
class CoefT>
292 ((a.
size () < b.
size ()) ? a : b);
294 ((a.
size () < b.
size ()) ? b : a);
300 int_t length = shorter. length ();
301 for (int_t i = 0; i < length; ++ i)
318 #endif // _CHAINCON_CHAIN_H_
chomp::homology::hashedset< CellT > cells
The set of elements in the chain.
CoefT operator*(const tChain< CellT, CoefT > &a, const tChain< CellT, CoefT > &b)
Computes the dot product of two chains.
CellT CellType
The type of cells in the chain.
bool empty() const
Returns true if and only if the chain is zero.
const CoefT & getCoef(int_t n) const
Returns the coefficient at the n-th cell of the chain.
A chain with coefficients in an arbitrary ring.
CoefT CoefType
The type of coefficients in the chain.
void add(const CellT &cell, const CoefT &coef)
Adds a given cell to the chain with the given coefficient.
tChain< CellT, CoefT > operator+(const tChain< CellT, CoefT > &a, const tChain< CellT, CoefT > &b)
Computes the sum of two chains.
int_t position(const CellT &c) const
Returns the position of the given cell in the chain or -1 if the cell is not there.
bool operator==(const tChain< CellT, CoefT > &ch) const
Compares if the two chains are equal.
tChain< CellT, CoefT > & operator+=(const tChain< CellT, CoefT > &ch)
Adds a given chain to the chain.
int_t size() const
Returns the number of elements in the chain.
const CellT & getCell(int_t n) const
Returns the n-th cell of the chain.
tChain< CellT, CoefT > & negate()
Negates all the coefficients in the chain.
std::istream & operator>>(std::istream &in, tChain< CellT, CoefT > &c)
Reads a chain from an input stream.
tChain()
The default constructor of an empty chain.
tChain< CellT, CoefT > & operator*=(const CoefT &coef)
Multiples the chain by a given coefficient.
void swap(tChain< CellT, CoefT > &ch)
Swaps the data with another chain.
extarray< CoefT > coefs
The coefficients that appear at the cells in the chain.