Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
Public Member Functions | Public Attributes | List of all members
libsnark::integer_permutation Class Reference

#include <integer_permutation.hpp>

Public Member Functions

 integer_permutation (const size_t size=0)
 
 integer_permutation (const size_t min_element, const size_t max_element)
 
 integer_permutation (const integer_permutation &other)=default
 
integer_permutationoperator= (const integer_permutation &other)=default
 
size_t size () const
 
bool operator== (const integer_permutation &other) const
 
void set (const size_t position, const size_t value)
 
size_t get (const size_t position) const
 
bool is_valid () const
 
integer_permutation inverse () const
 
integer_permutation slice (const size_t slice_min_element, const size_t slice_max_element) const
 
bool next_permutation ()
 
void random_shuffle ()
 

Public Attributes

size_t min_element
 
size_t max_element
 

Detailed Description

Definition at line 22 of file integer_permutation.hpp.

Constructor & Destructor Documentation

◆ integer_permutation() [1/3]

libsnark::integer_permutation::integer_permutation ( const size_t  size = 0)

Definition at line 24 of file integer_permutation.cpp.

25  : min_element(0), max_element(size - 1)
26 {
27  contents.resize(size);
28  std::iota(contents.begin(), contents.end(), 0);
29 }
Here is the call graph for this function:

◆ integer_permutation() [2/3]

libsnark::integer_permutation::integer_permutation ( const size_t  min_element,
const size_t  max_element 
)

Definition at line 31 of file integer_permutation.cpp.

34 {
35  assert(min_element <= max_element);
36  const size_t size = max_element - min_element + 1;
37  contents.resize(size);
38  std::iota(contents.begin(), contents.end(), min_element);
39 }
Here is the call graph for this function:

◆ integer_permutation() [3/3]

libsnark::integer_permutation::integer_permutation ( const integer_permutation other)
default

Member Function Documentation

◆ get()

size_t libsnark::integer_permutation::get ( const size_t  position) const

Definition at line 60 of file integer_permutation.cpp.

61 {
62  assert(min_element <= position && position <= max_element);
63  return contents[position - min_element];
64 }
Here is the caller graph for this function:

◆ inverse()

integer_permutation libsnark::integer_permutation::inverse ( ) const

Definition at line 82 of file integer_permutation.cpp.

83 {
85 
86  for (size_t position = min_element; position <= max_element; ++position) {
87  result.contents[this->contents[position - min_element] - min_element] =
88  position;
89  }
90 
91 #ifdef DEBUG
92  assert(result.is_valid());
93 #endif
94 
95  return result;
96 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_valid()

bool libsnark::integer_permutation::is_valid ( ) const

Definition at line 66 of file integer_permutation.cpp.

67 {
68  std::unordered_set<size_t> elems;
69 
70  for (auto &el : contents) {
71  if (el < min_element || el > max_element ||
72  elems.find(el) != elems.end()) {
73  return false;
74  }
75 
76  elems.insert(el);
77  }
78 
79  return true;
80 }
Here is the caller graph for this function:

◆ next_permutation()

bool libsnark::integer_permutation::next_permutation ( )

Definition at line 117 of file integer_permutation.cpp.

118 {
119  return std::next_permutation(contents.begin(), contents.end());
120 }

◆ operator=()

integer_permutation& libsnark::integer_permutation::operator= ( const integer_permutation other)
default

◆ operator==()

bool libsnark::integer_permutation::operator== ( const integer_permutation other) const

Definition at line 46 of file integer_permutation.cpp.

47 {
48  return (
49  this->min_element == other.min_element &&
50  this->max_element == other.max_element &&
51  this->contents == other.contents);
52 }

◆ random_shuffle()

void libsnark::integer_permutation::random_shuffle ( )

Definition at line 122 of file integer_permutation.cpp.

123 {
124  return std::random_shuffle(contents.begin(), contents.end());
125 }
Here is the caller graph for this function:

◆ set()

void libsnark::integer_permutation::set ( const size_t  position,
const size_t  value 
)

Definition at line 54 of file integer_permutation.cpp.

55 {
56  assert(min_element <= position && position <= max_element);
57  contents[position - min_element] = value;
58 }
Here is the caller graph for this function:

◆ size()

size_t libsnark::integer_permutation::size ( ) const

Definition at line 41 of file integer_permutation.cpp.

42 {
43  return max_element - min_element + 1;
44 }
Here is the caller graph for this function:

◆ slice()

integer_permutation libsnark::integer_permutation::slice ( const size_t  slice_min_element,
const size_t  slice_max_element 
) const

Definition at line 98 of file integer_permutation.cpp.

100 {
101  assert(
102  min_element <= slice_min_element &&
103  slice_min_element <= slice_max_element &&
104  slice_max_element <= max_element);
105  integer_permutation result(slice_min_element, slice_max_element);
106  std::copy(
107  this->contents.begin() + (slice_min_element - min_element),
108  this->contents.begin() + (slice_max_element - min_element) + 1,
109  result.contents.begin());
110 #ifdef DEBUG
111  assert(result.is_valid());
112 #endif
113 
114  return result;
115 }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ max_element

size_t libsnark::integer_permutation::max_element

Definition at line 29 of file integer_permutation.hpp.

◆ min_element

size_t libsnark::integer_permutation::min_element

Definition at line 28 of file integer_permutation.hpp.


The documentation for this class was generated from the following files:
libsnark::integer_permutation::max_element
size_t max_element
Definition: integer_permutation.hpp:29
libsnark::integer_permutation::min_element
size_t min_element
Definition: integer_permutation.hpp:28
libsnark::integer_permutation::integer_permutation
integer_permutation(const size_t size=0)
Definition: integer_permutation.cpp:24
libsnark::integer_permutation::size
size_t size() const
Definition: integer_permutation.cpp:41