File: iohandler.h

package info (click to toggle)
cohomcalg 0.32%2Bds-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 2,008 kB
  • sloc: cpp: 3,291; makefile: 46; ansic: 17
file content (177 lines) | stat: -rw-r--r-- 7,302 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                //
//  iohandler.h                                                                                   //
//  ===========                                                                                   //
//                                                                                                //
//  Code: Benjamin Jurke, http://benjaminjurke.net                                                //
//                                                                                                //
////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                //
//  File history:                                                                                 //
//        - 17.04.2010  File created as iohandler.h                                               //
//                                                                                                //
////////////////////////////////////////////////////////////////////////////////////////////////////


#ifndef INC_IOHANDLER_H
#define INC_IOHANDLER_H


#include <stdint.h>
#include <string>
#include <vector>
#include <set>


////////////////////////////////////////////////////////////////////////////////////////////////////

// This file handles the translation from the input file or string to the internal data format using
// first the tokenizer and then some pretty elementary (read: non-sophisticated) parsing.
//
// There are several internal data format and due to the quite limited amount of input data several
// redundant copies are held by the computation classes. However, the CInternalData class provides
// the "common ground" and also contains the output functions to "human readable" format.
//
// Internally, for most of the program we are working with 64-bit integer variables, because the
// usage of bitmasks and bit-wise operators in general is very fast and rather memory efficient.
// The usage of those internal variables also puts some limitations on the input data: only up to
// 63 coordinates/vertices and Stanley-Reisner ideal generator are supported (the top bit is
// reserved!), butat the current state of technology those cases are way out of the league of modern
// computers.


// For speedup we use some fixed-width arrays of 64 integer variables
template <class T> class vec64
{
  public:
    T x[64];

  public:
    inline void Fill(T val) { for (unsigned int i=0; i<64; i++) x[i]=val; }
    inline void Clear()     { Fill(0); };
};

typedef vec64<int32_t>  i32vec64;
typedef vec64<uint32_t> ui32vec64;

typedef vec64<int64_t>  i64vec64;
typedef vec64<uint64_t> ui64vec64;

// For each coordinate/vertex we hold the following data
typedef struct
{
    uint64_t    liVar;
    std::string strName;
    i32vec64    GLSMch;
} InternalCoordData;


class CInternalData
{
  friend class CInputFile;

  private:
    // The input data
    std::vector<InternalCoordData> vCoords;         // The coordinates/vertices
    std::vector<uint64_t>          vSRgens;         // The Stanley-Reisner ideal generators
    std::vector<i32vec64>          vTargetDivisors; // The requested ambient cohomology bundle charges
    size_t                         numGLSMch;

    // For output formatting
    size_t nMaxMonomWidth;

    // Some internal data
    uint64_t liCompleteUnion;

  private:
    void Clear();

  public:
    CInternalData();

    // Output functions
    std::string Int64ToCoordProduct(uint64_t liProduct, std::string strSep = "*", std::string strZeroVal = "1") const;
    std::string Int64ToCoordProductPadded(uint64_t liProduct, std::string strSep = "*", std::string strZeroVal = "1") const;
    std::string Int64ToMonomial(uint64_t liProduct) const;
    std::string Int64ToMonomialPadded(uint64_t liProduct) const;

    void        PrintInternalData();
    std::string PrintInternalDataAsMathematicaScriptInput();

    // Internal data retrival
    inline size_t                                GetDimension() const         { return vCoords.size() - numGLSMch; };
    inline uint64_t                              GetCompleteUnion() const     { return liCompleteUnion; };
    inline size_t                                GetNumGLSMch() const         { return numGLSMch; };
    inline size_t                                GetNumCoordinates() const    { return vCoords.size(); };
    inline size_t                                GetNumSRgens() const         { return vSRgens.size(); };
    inline size_t                                GetNumTargetDivisors() const { return vTargetDivisors.size(); };
    inline const std::vector<InternalCoordData> &GetInternalCoordData() const { return vCoords; };
    inline const std::vector<uint64_t> &         GetSRgens() const            { return vSRgens; };
    inline const std::vector<i32vec64> &         GetTargetDivisors() const    { return vTargetDivisors; };

    void GetCanonicalDivisor(i32vec64 &candiv_out) const;

    // Data input
    bool ReadAndParseInputFile(std::string strFileName, std::string strAppend);
};


////////////////////////////////////////////////////////////////////////////////////////////////////

// The CMonomialsList class contains the data which is ultimately produced by the processes. Encoded
// in 64-bit variables, again, it contains the list of all contributing monomials and their respective
// factor, which was derived from the secondary/remnant cohomology. Note that the monomials are split
// up in two sets: the monomials which have a contribution to an uniquely determined cohomology group
// and the ambiguously contributing monomials, whose actual contribution has to be sorted out later.

typedef struct
{
    uint32_t nGroup;
    uint32_t nFactor;
} CohomContrib;

typedef struct
{
    CohomContrib Cohom;
    uint32_t nRationals;
    uint32_t nRationalsDual;
} UniqueContribData;

typedef struct
{
    std::vector<CohomContrib> vCohoms;
    uint32_t nRationals;
    uint32_t nRationalsDual;
} AmbiguousContribData;

class CMonomialsList
{
  friend class CSecondaryCohomology;
  friend class CRationals;
  friend class CMonomialFile;

  private:
    // Associative monomial contribution data
    std::map<uint64_t, UniqueContribData>    unique_monoms;
    std::map<uint64_t, AmbiguousContribData> ambiguous_monoms;

  private:
    // Adding monomials
    bool AddUniqueContribution(uint64_t liMonomial, uint32_t nCohomGroup, uint32_t nFactor);
    bool AddAmbiguousContribution(uint64_t liMonomial, const std::vector<CohomContrib> &vContributions);

  public:
    void Clear();
    void ClearRationals();

    // Output functions
    void PrintMonomialList(const CInternalData &id, bool bPrintFactors, bool bPrintRationals, bool bShortList) const;

    // Intermediate monomial file I/O
    bool ReadMonomialsFile(const CInternalData &id, std::string strFileName);
    bool WriteMonomialsFile(const CInternalData &id, std::string strFileName) const;
};

bool GetIntSequenceStartEnd(const std::vector<uint64_t> &seq, size_t &min_out, size_t &max_out);

#endif