00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef OMC_SIGNED_SET_H
00017 #define OMC_SIGNED_SET_H
00018
00019 #include "Core.h"
00020 #include "Permutation.h"
00021 #include "Combination.h"
00022 #include <vector>
00023 #include <iostream>
00024 #include <string>
00025 #include <algorithm>
00026
00027 namespace omc
00028 {
00029 class SignedSet {
00030
00031 public:
00032 SignedSet (size_t);
00033 SignedSet (const std::string);
00034 SignedSet (const char*);
00035 SignedSet (const SignedSet &);
00036
00037 ~SignedSet () {};
00038
00039 size_t size () const;
00040
00041 void shrink ();
00042
00043 size_t numZeros () const;
00044 size_t numNonZeros () const;
00045
00046 sign_t & operator[] (index_t i);
00047 sign_t operator[] (index_t i) const;
00048
00049 bool negative () const;
00050
00051 void negate ();
00052
00053 void compose (SignedSet &);
00054
00055 void relabel (index_t, index_t);
00056 void relabel (const Permutation &);
00057 void reorient (index_t i);
00058 void reorient (const Combination &);
00059
00060 bool operator< (const SignedSet &) const;
00061 bool operator== (const SignedSet &) const;
00062 bool operator!= (const SignedSet &) const;
00063
00064 bool operator*= (const SignedSet &) const;
00065 bool operator/= (const SignedSet &) const;
00066 bool operator-= (const SignedSet &) const;
00067 bool operator+= (const SignedSet &) const;
00068 SignedSet operator- (const SignedSet &) const;
00069
00070 SignedSet operator- () const;
00071
00072 std::ostream & show (std::ostream &) const;
00073
00074 protected:
00075 std::vector <sign_t> m_Sign;
00076
00077 };
00078
00079
00080 std::ostream & operator<< (std::ostream &, SignedSet &);
00081 std::istream & operator>> (std::istream &, SignedSet &);
00082
00083
00085 inline SignedSet::SignedSet (size_t len)
00086 : m_Sign (len, 0)
00087 {}
00088
00090 inline SignedSet::SignedSet (const SignedSet & sSet)
00091 : m_Sign (sSet.m_Sign)
00092 {}
00093
00095 inline size_t SignedSet::size () const {
00096 return m_Sign.size();
00097 }
00098
00100 inline void SignedSet::shrink () {
00101 m_Sign.pop_back();
00102 }
00103
00105 inline size_t SignedSet::numNonZeros () const {
00106 return m_Sign.size() - numZeros();
00107 }
00108
00110 inline sign_t & SignedSet::operator[] (index_t i) {
00111 return m_Sign[i];
00112 }
00113
00115 inline sign_t SignedSet::operator[] (index_t i) const {
00116 return m_Sign[i];
00117 }
00118
00120 inline void SignedSet::negate () {
00121 for (index_t i=0; i<m_Sign.size(); i++)
00122 m_Sign[i] *= -1;
00123 }
00124
00126 inline SignedSet SignedSet::operator- () const {
00127 SignedSet S (*this);
00128 S.negate ();
00129 return S;
00130 }
00131
00133 inline void SignedSet::relabel (index_t i, index_t j) {
00134 std::swap (m_Sign[i], m_Sign[j]);
00135 }
00136
00138 inline void SignedSet::relabel (const Permutation & perm) {
00139 std::vector <sign_t> Sign (m_Sign);
00140 for (index_t i=0; i<m_Sign.size(); i++)
00141 m_Sign[perm(i)] = Sign[i];
00142 }
00143
00145 inline void SignedSet::reorient (index_t i) {
00146 if (i >= m_Sign.size())
00147 throw OMCException ("Index out of bound", "SignedSet::reorient");
00148
00149 m_Sign[i] *= -1;
00150 }
00151
00153 inline void SignedSet::reorient (const Combination & comb) {
00154 if (comb.size() != m_Sign.size())
00155 throw OMCException ("Incompatible combination size", "SignedSet::reorient");
00156
00157 for (int i=0; i<comb.size(); i++)
00158 if (comb.has (i))
00159 m_Sign[i] *= -1;
00160 }
00161
00163 inline std::ostream & SignedSet::show (std::ostream & os) const {
00164 for (index_t i=0; i<m_Sign.size(); i++)
00165 os << (m_Sign[i] ? (m_Sign[i] > 0 ? "+" : "-") : "0");
00166 return os;
00167 }
00168
00169
00171 inline std::ostream & operator<< (std::ostream & os, SignedSet & S) {
00172 for (index_t i=0; i<S.size(); i++)
00173 os << (S[i] ? (S[i] > 0 ? "+" : "-") : "0");
00174 return os;
00175 }
00176
00180 inline std::istream & operator>> (std::istream & is, SignedSet & S) {
00181 std::string s; is >> s;
00182 S = SignedSet (s);
00183 return is;
00184 }
00185
00186 };
00187
00188 #endif // OMC_SIGNED_SET_H