LibSWIFFT  1.2.0
swifft.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Yaron Gvili and Gvili Tech Ltd.
3  *
4  * See the accompanying LICENSE.txt file for licensing information.
5  */
10 #ifndef __LIBSWIFFT_SWIFFT_HPP__
11 #define __LIBSWIFFT_SWIFFT_HPP__
12 
13 #include "libswifft/swifft.h"
14 #include <string.h>
15 
16 namespace LibSwifft {
17 
19 SwifftInput& Copy(SwifftInput &dst, const SwifftInput &src);
20 SwifftInput & Set(SwifftInput &lhs, const BitSequence value);
21 
23 SwifftOutput& Copy(SwifftOutput &dst, const SwifftOutput &src);
24 SwifftOutput & Set(SwifftOutput &lhs, const int16_t value);
25 
28 SwifftCompact & Set(SwifftCompact &lhs, const BitSequence value);
29 
34 
39  LIBSWIFFT_INLINE SwifftInput & operator=(const SwifftInput &rhs) { Copy(*this, rhs); return *this; }
44  LIBSWIFFT_INLINE SwifftInput & operator=(const BitSequence value) { Set(*this, value); return *this; }
45 
46 };
47 
52 
57  LIBSWIFFT_INLINE SwifftOutput & operator=(const SwifftOutput &rhs) { Copy(*this, rhs); return *this; }
62  LIBSWIFFT_INLINE SwifftOutput & operator=(const int16_t value) { Set(*this, value); return *this; }
63 
64 };
65 
70 
75  LIBSWIFFT_INLINE SwifftCompact & operator=(const SwifftCompact &rhs) { Copy(*this, rhs); return *this; }
80  LIBSWIFFT_INLINE SwifftCompact & operator=(const BitSequence value) { Set(*this, value); return *this; }
81 
82 };
83 
88 LIBSWIFFT_INLINE bool operator==(const SwifftInput &si1, const SwifftInput &si2) {
89  return memcmp(si1.data, si2.data, sizeof(SwifftInput)) == 0;
90 }
91 
96 LIBSWIFFT_INLINE bool operator!=(const SwifftInput &si1, const SwifftInput &si2) {
97  return !(si1 == si2);
98 }
99 
104 LIBSWIFFT_INLINE bool operator==(const SwifftOutput &so1, const SwifftOutput &so2) {
105  return memcmp(so1.data, so2.data, sizeof(SwifftOutput)) == 0;
106 }
107 
112 LIBSWIFFT_INLINE bool operator!=(const SwifftOutput &so1, const SwifftOutput &so2) {
113  return !(so1 == so2);
114 }
115 
121  return memcmp(sc1.data, sc2.data, sizeof(SwifftCompact)) == 0;
122 }
123 
129  return !(sc1 == sc2);
130 }
131 
138  memcpy(dst.data, src.data, sizeof(dst.data));
139  return dst;
140 }
141 
148  memcpy(dst.data, src.data, sizeof(dst.data));
149  return dst;
150 }
151 
158  memcpy(dst.data, src.data, sizeof(dst.data));
159  return dst;
160 }
161 
168  memset(lhs.data, value, sizeof(lhs.data));
169  return lhs;
170 }
171 
177 LIBSWIFFT_INLINE SwifftOutput & Set(SwifftOutput &lhs, const int16_t value) {
178  SWIFFT_ConstSet(lhs.data, value);
179  return lhs;
180 }
181 
188  memset(lhs.data, value, sizeof(lhs.data));
189  return lhs;
190 }
191 
197 LIBSWIFFT_INLINE SwifftOutput & operator+=(SwifftOutput &lhs, const int16_t value) {
198  SWIFFT_ConstAdd(lhs.data, value);
199  return lhs;
200 }
201 
207 LIBSWIFFT_INLINE SwifftOutput & operator-=(SwifftOutput &lhs, const int16_t value) {
208  SWIFFT_ConstSub(lhs.data, value);
209  return lhs;
210 }
211 
216 LIBSWIFFT_INLINE SwifftOutput & operator*=(SwifftOutput &lhs, const int16_t value) {
217  SWIFFT_ConstMul(lhs.data, value);
218  return lhs;
219 }
220 
227  SWIFFT_Add(lhs.data, rhs.data);
228  return lhs;
229 }
230 
237  SWIFFT_Sub(lhs.data, rhs.data);
238  return lhs;
239 }
240 
247  SWIFFT_Mul(lhs.data, rhs.data);
248  return lhs;
249 }
250 
251 } // end namespace LibSwifft
252 
253 #endif // __LIBSWIFFT_SWIFFT_HPP__
BitSequence data[SWIFFT_COMPACT_BLOCK_SIZE]
The compact-form data structure.
Definition: swifft.hpp:69
#define SWIFFT_ALIGN
Align attribute for SWIFFT vector.
Definition: swifft_common.h:25
void LIBSWIFFT_API() SWIFFT_ConstAdd(BitSequence output[SWIFFT_OUTPUT_BLOCK_SIZE], const int16_t operand)
Adds a constant value to each SWIFFT hash value element.
Definition: swifft.c:156
Definition: swifft.hpp:16
unsigned char BitSequence
Basic buffer type.
Definition: swifft_common.h:15
#define SWIFFT_INPUT_BLOCK_SIZE
The size in bytes of SWIFFT input.
Definition: swifft_common.h:28
LIBSWIFFT_INLINE SwifftCompact & operator=(const BitSequence value)
Set all 8-bit elements to a value.
Definition: swifft.hpp:80
LIBSWIFFT_INLINE SwifftOutput & operator=(const int16_t value)
Set all 16-bit elements to a value.
Definition: swifft.hpp:62
void LIBSWIFFT_API() SWIFFT_ConstMul(BitSequence output[SWIFFT_OUTPUT_BLOCK_SIZE], const int16_t operand)
Multiply a constant value into each SWIFFT hash value element.
Definition: swifft.c:176
LIBSWIFFT_INLINE SwifftOutput & operator=(const SwifftOutput &rhs)
Copy a source SWIFFT output.
Definition: swifft.hpp:57
LIBSWIFFT_INLINE SwifftOutput & operator-=(SwifftOutput &lhs, const int16_t value)
Subtracts a value from each 16-bit element of a SWIFFT output data structure.
Definition: swifft.hpp:207
An auto-memory-aligned SWIFFT compact-form data structure.
Definition: swifft.hpp:67
LIBSWIFFT_INLINE SwifftCompact & operator=(const SwifftCompact &rhs)
Copy a source SWIFFT compact-form.
Definition: swifft.hpp:75
void LIBSWIFFT_API() SWIFFT_Mul(BitSequence output[SWIFFT_OUTPUT_BLOCK_SIZE], const BitSequence operand[SWIFFT_OUTPUT_BLOCK_SIZE])
Multiplies a SWIFFT hash value from another, element-wise.
Definition: swifft.c:216
SwifftInput & Set(SwifftInput &lhs, const BitSequence value)
Set all 8-bit elements of a SWIFFT input data structure to a value.
Definition: swifft.hpp:167
An auto-memory-aligned SWIFFT input data structure.
Definition: swifft.hpp:31
LIBSWIFFT_INLINE SwifftInput & operator=(const BitSequence value)
Set all 8-bit elements to a value.
Definition: swifft.hpp:44
An auto-memory-aligned SWIFFT output data structure.
Definition: swifft.hpp:49
void LIBSWIFFT_API() SWIFFT_Sub(BitSequence output[SWIFFT_OUTPUT_BLOCK_SIZE], const BitSequence operand[SWIFFT_OUTPUT_BLOCK_SIZE])
Subtracts a SWIFFT hash value from another, element-wise.
Definition: swifft.c:206
SwifftInput & Copy(SwifftInput &dst, const SwifftInput &src)
Copy a SWIFFT input data structure.
Definition: swifft.hpp:137
LIBSWIFFT_INLINE bool operator!=(const SwifftInput &si1, const SwifftInput &si2)
Tests for inequality of two SWIFFT input data structures.
Definition: swifft.hpp:96
BitSequence data[SWIFFT_OUTPUT_BLOCK_SIZE]
The output data structure.
Definition: swifft.hpp:51
#define LIBSWIFFT_INLINE
Definition: common.h:19
void LIBSWIFFT_API() SWIFFT_ConstSub(BitSequence output[SWIFFT_OUTPUT_BLOCK_SIZE], const int16_t operand)
Subtracts a constant value from each SWIFFT hash value element.
Definition: swifft.c:166
#define SWIFFT_OUTPUT_BLOCK_SIZE
The size in bytes of SWIFFT output block.
Definition: swifft_common.h:31
#define SWIFFT_COMPACT_BLOCK_SIZE
The size in bytes of SWIFFT compact-form.
Definition: swifft_common.h:34
void LIBSWIFFT_API() SWIFFT_ConstSet(BitSequence output[SWIFFT_OUTPUT_BLOCK_SIZE], const int16_t operand)
Sets a constant value at each SWIFFT hash value element.
Definition: swifft.c:146
LibSWIFFT public C API.
LIBSWIFFT_INLINE bool operator==(const SwifftInput &si1, const SwifftInput &si2)
Tests for equality of two SWIFFT input data structures.
Definition: swifft.hpp:88
BitSequence data[SWIFFT_INPUT_BLOCK_SIZE]
The input data structure.
Definition: swifft.hpp:33
LIBSWIFFT_INLINE SwifftOutput & operator*=(SwifftOutput &lhs, const int16_t value)
Multiplies each 16-bit element of a SWIFFT output data structure by a value.
Definition: swifft.hpp:216
LIBSWIFFT_INLINE SwifftInput & operator=(const SwifftInput &rhs)
Copy a source SWIFFT input.
Definition: swifft.hpp:39
void LIBSWIFFT_API() SWIFFT_Add(BitSequence output[SWIFFT_OUTPUT_BLOCK_SIZE], const BitSequence operand[SWIFFT_OUTPUT_BLOCK_SIZE])
Adds a SWIFFT hash value to another, element-wise.
Definition: swifft.c:196
LIBSWIFFT_INLINE SwifftOutput & operator+=(SwifftOutput &lhs, const int16_t value)
Adds a value to each 16-bit element of a SWIFFT output data structure.
Definition: swifft.hpp:197