primeChain.h
1 /* Copyright (C) 2012-2020 IBM Corp.
2  * This program is Licensed under the Apache License, Version 2.0
3  * (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software
7  * distributed under the License is distributed on an "AS IS" BASIS,
8  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9  * See the License for the specific language governing permissions and
10  * limitations under the License. See accompanying LICENSE file.
11  */
12 #ifndef HELIB_PRIMECHAIN_H
13 #define HELIB_PRIMECHAIN_H
18 #include <vector>
19 #include <helib/IndexSet.h>
20 
21 namespace helib {
22 
23 class Cmodulus;
24 class Context;
25 
28 {
29 public:
30  typedef std::pair<double, IndexSet> Entry;
31  // each table entry is a pair<double,IndexSet>=(size, set-of-primes)
32 
34  void init(const Context& context);
35 
42  IndexSet getSet4Size(double low,
43  double high,
44  const IndexSet& fromSet,
45  bool reverse) const;
46 
53  IndexSet getSet4Size(double low,
54  double high,
55  const IndexSet& from1,
56  const IndexSet& from2,
57  bool reverse) const;
58 
59  // ASCII I/O
60  friend std::istream& operator>>(std::istream& s, ModuliSizes& szs);
61  friend std::ostream& operator<<(std::ostream& s, const ModuliSizes& szs);
62  // Raw I/O
63  void read(std::istream& str);
64  void write(std::ostream& str) const;
65 
66  void clear()
67  {
68  sizes.clear();
69  iFFT_cost = -1;
70  }
71 
72 private:
73  std::vector<Entry> sizes;
74  long iFFT_cost = -1;
75 };
76 
77 std::ostream& operator<<(std::ostream& s, const ModuliSizes::Entry& e);
78 std::istream& operator>>(std::istream& s, ModuliSizes::Entry& e);
79 void write(std::ostream& s, const ModuliSizes::Entry& e);
80 void read(std::istream& s, ModuliSizes::Entry& e);
81 
82 } // namespace helib
83 
84 #endif // ifndef HELIB_PRIMECHAIN_H
Maintaining the HE scheme parameters.
Definition: Context.h:100
A dynamic set of non-negative integers.
Definition: IndexSet.h:33
A helper class to map required modulo-sizes to primeSets.
Definition: primeChain.h:28
friend std::istream & operator>>(std::istream &s, ModuliSizes &szs)
Definition: primeChain.cpp:342
void clear()
Definition: primeChain.h:66
std::pair< double, IndexSet > Entry
Definition: primeChain.h:30
IndexSet getSet4Size(double low, double high, const IndexSet &fromSet, bool reverse) const
Definition: primeChain.cpp:179
void read(std::istream &str)
Definition: primeChain.cpp:361
friend std::ostream & operator<<(std::ostream &s, const ModuliSizes &szs)
Definition: primeChain.cpp:337
void write(std::ostream &str) const
Definition: primeChain.cpp:354
void init(const Context &context)
initialize helper table for a given chain
Definition: primeChain.cpp:68
Definition: apiAttributes.h:21
void write(std::ostream &s, const ModuliSizes::Entry &e)
Definition: primeChain.cpp:55
std::istream & operator>>(std::istream &s, CtxtPart &p)
Definition: Ctxt.cpp:2762
void reverse(NTL::Vec< T > &v, long lo, long hi)
Reverse a vector in place.
Definition: NumbTh.h:662
void read(std::istream &s, ModuliSizes::Entry &e)
Definition: primeChain.cpp:61
std::ostream & operator<<(std::ostream &os, const ContextBuilder< SCHEME > &cb)
ostream operator for serializing the ContextBuilder object.