08.01.2015 Views

Design and Implementation of a Homomorphic ... - Researcher

Design and Implementation of a Homomorphic ... - Researcher

Design and Implementation of a Homomorphic ... - Researcher

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.6 IndexSet <strong>and</strong> IndexMap: Sets <strong>and</strong> Indexes<br />

In our implementation, all the polynomials are represented in double-CRT format, relative to some<br />

subset <strong>of</strong> the small primes in our list (cf. Section 1.2). The subset itself keeps changing throughout<br />

the computation, <strong>and</strong> so we can have the same polynomial represented at one point relative to<br />

many primes, then a small number <strong>of</strong> primes, then many primes again, etc. (For example see the<br />

implementation <strong>of</strong> key-switching in Section 3.1.6.) To provide flexibility with these transformations,<br />

the IndexSet class implements an arbitrary subset <strong>of</strong> integers, <strong>and</strong> the IndexMap class implements<br />

a collection <strong>of</strong> data items that are indexed by such a subset.<br />

2.6.1 The IndexSet class<br />

The IndexSet class implements all the st<strong>and</strong>ard interfaces <strong>of</strong> the abstract data-type <strong>of</strong> a set, along<br />

with just a few extra interfaces that are specialized to sets <strong>of</strong> integers. It uses the st<strong>and</strong>ard C++<br />

container vector to keep the actual set, <strong>and</strong> provides the following methods:<br />

Constructors. The constructors IndexSet(), IndexSet(long j), <strong>and</strong> IndexSet(long low, long<br />

high), initialize an empty set, a singleton, <strong>and</strong> an interval, respectively.<br />

Empty sets <strong>and</strong> cardinality. The static method IndexSet::emptySet() provides a read-only access<br />

to an empty set, <strong>and</strong> the method s.clear() removes all the elements in s, which is<br />

equivalent to s=IndexSet::emptySet().<br />

The method s.card() returns the number <strong>of</strong> elements in s.<br />

Traversing a set. The methods s.first() <strong>and</strong> s.last() return the smallest <strong>and</strong> largest element<br />

in the set, respectively. For an empty set s, s.first() returns 0 <strong>and</strong> s.last() returns −1.<br />

The method s.next(j) return the next element after j, if any; otherwise j + 1. Similarly<br />

s.prev(j) return the previous element before j, if any; otherwise j − 1. With these methods,<br />

we can iterate through a set s using one <strong>of</strong>:<br />

for (long i = s.first(); i = s.first(); i = s.prev(i)) ...<br />

Comparison <strong>and</strong> membership methods. operator== <strong>and</strong> operator!= are provided to test for<br />

equality, whereas s1.disjointFrom(s2) <strong>and</strong> its synonym disjoint(s1,s2) test if the two<br />

sets are disjoint. Also, s.contains(j) returns true if s contains the element j, s.contains(other)<br />

returns true if s is a superset <strong>of</strong> other. For convenience, the operators are<br />

also provided for testing the subset relation between sets.<br />

Set operations. The method s.insert(j) inserts the integer j if it is not in s, <strong>and</strong> s.remove(j)<br />

removes it if it is there.<br />

Similarly s1.insert(s2) returns in s1 the union <strong>of</strong> the two sets, <strong>and</strong> s1.remove(s2) returns<br />

in s1 the set difference s1 \ s2. Also, s1.retain(s2) returns in s1 the intersection <strong>of</strong> the<br />

two sets. For convenience we also provide the operators s1|s2 (union), s1&s2 (intersection),<br />

s1^s2 (symmetric difference, aka xor), <strong>and</strong> s1/s2 (set difference).<br />

8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!