Skip to content

Commit 309c614

Browse files
chore(clippy): fix linter on new stable
1 parent 86cd9ed commit 309c614

File tree

11 files changed

+198
-132
lines changed

11 files changed

+198
-132
lines changed

benches/cuckoo_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::collections::HashSet;
16+
1517
use criterion::{criterion_group, criterion_main, Criterion};
16-
use rand::rngs::StdRng;
17-
use rand::Rng;
18+
use rand::{rngs::StdRng, Rng};
1819
use rand_core::SeedableRng;
19-
use std::collections::HashSet;
2020
use swift_homomorphic_encryption_rust::private_information_retrieval::cuckoo_table::{
2121
BucketCountConfig, CuckooBucketEntry, CuckooTable, CuckooTableConfig,
2222
};

src/homomorphic_encryption/context.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::homomorphic_encryption::encryption_parameters::EncryptionParameters;
16-
use crate::homomorphic_encryption::he_scheme::HeScheme;
1715
use std::marker::PhantomData;
1816

17+
use crate::homomorphic_encryption::{
18+
encryption_parameters::EncryptionParameters, he_scheme::HeScheme,
19+
};
20+
1921
/// Pre-computation for the HE operations.
2022
///
21-
/// HE operations are typically only supported between objects, such as ``Ciphertext``, ``Plaintext``,
22-
/// ``EvaluationKey``, ``SecretKey``, with the same context.
23+
/// HE operations are typically only supported between objects, such as ``Ciphertext``,
24+
/// ``Plaintext``, ``EvaluationKey``, ``SecretKey``, with the same context.
2325
pub struct Context<Scheme: HeScheme> {
2426
_marker: PhantomData<Scheme>,
2527
}

src/homomorphic_encryption/he_scheme.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::homomorphic_encryption::context::Context;
16-
use crate::homomorphic_encryption::keys::SecretKey;
15+
use crate::homomorphic_encryption::{context::Context, keys::SecretKey};
1716

1817
pub trait HeScheme: Sized {
1918
type CanonicalCiphertext;
@@ -27,7 +26,6 @@ pub trait HeScheme: Sized {
2726
/// # Returns
2827
///
2928
/// A `SecretKey` for the given `Context`.
30-
///
3129
fn generate_secret_key(_context: &Context<Self>) -> SecretKey<Self> {
3230
todo!()
3331
}

src/homomorphic_encryption/scalar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
/// # Parameters
2121
/// - `value`: The number we divide.
2222
/// - `divisor`: The number to divide by.
23-
/// - `variable_time`: Must be `true`, indicating this value and `divisor` are leaked through timing.
23+
/// - `variable_time`: Must be `true`, indicating this value and `divisor` are leaked through
24+
/// timing.
2425
///
2526
/// # Returns
2627
/// `ceil(value / divisor)`.

src/private_information_retrieval/cuckoo_table.rs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,45 @@
2323
//!
2424
//! This module provides the following key components:
2525
//!
26-
//! - `CuckooTableConfig`: Configuration for the cuckoo table, including the number of hash functions,
27-
//! maximum eviction count, maximum serialized bucket size, and bucket count configuration.
28-
//! - `CuckooTable`: The main data structure implementing the cuckoo hash table, supporting insertion,
29-
//! lookup, and expansion of the table.
26+
//! - `CuckooTableConfig`: Configuration for the cuckoo table, including the number of hash
27+
//! functions, maximum eviction count, maximum serialized bucket size, and bucket count
28+
//! configuration.
29+
//! - `CuckooTable`: The main data structure implementing the cuckoo hash table, supporting
30+
//! insertion, lookup, and expansion of the table.
3031
//! - `CuckooBucket`: Represents a single bucket in the cuckoo table, storing a list of entries.
31-
//! - `CuckooBucketEntry`: Represents a single entry in a cuckoo bucket, consisting of a keyword and a value.
32-
//! - `CuckooTableInformation`: Provides a summary of the cuckoo table, including entry count, bucket count,
33-
//! empty bucket count, and load factor.
32+
//! - `CuckooBucketEntry`: Represents a single entry in a cuckoo bucket, consisting of a keyword and
33+
//! a value.
34+
//! - `CuckooTableInformation`: Provides a summary of the cuckoo table, including entry count,
35+
//! bucket count, empty bucket count, and load factor.
3436
//!
35-
//! The implementation of hash table entries, `CuckooBucketEntry`, is taken from the `hash_bucket` module.
37+
//! The implementation of hash table entries, `CuckooBucketEntry`, is taken from the `hash_bucket`
38+
//! module.
39+
40+
use std::fmt;
3641

37-
use crate::homomorphic_encryption::scalar::dividing_ceil;
38-
use crate::private_information_retrieval::error::PirError;
39-
use crate::private_information_retrieval::hash_bucket::{HashBucket, HashKeyword};
40-
use crate::private_information_retrieval::keyword_database::{Keyword, KeywordValue};
4142
use eyre::Result;
4243
use rand::seq::SliceRandom;
4344
use rand_core::RngCore;
44-
use std::fmt;
4545
use thiserror::Error;
4646

47+
use crate::{
48+
homomorphic_encryption::scalar::dividing_ceil,
49+
private_information_retrieval::{
50+
error::PirError,
51+
hash_bucket::{HashBucket, HashKeyword},
52+
keyword_database::{Keyword, KeywordValue},
53+
},
54+
};
55+
4756
/// Cuckoo table config errors.
4857
#[derive(Debug, Clone, Error, PartialEq)]
4958
pub enum CuckooTableConfigError {
5059
/// Invalid hash function count. Must be greater than 0.
5160
#[error("Invalid hash function count")]
5261
InvalidHashFunctionCount,
5362

54-
/// Invalid maximum serialized bucket size. Must be greater than zero and less than `HashBucket::serialized_size_with_value_size(0)`.
63+
/// Invalid maximum serialized bucket size. Must be greater than zero and less than
64+
/// `HashBucket::serialized_size_with_value_size(0)`.
5565
#[error("Invalid maximum serialized bucket size")]
5666
InvalidMaxSerializedBucketSize,
5767

@@ -73,11 +83,12 @@ pub enum CuckooTableConfigError {
7383
pub enum BucketCountConfig {
7484
/// Allow increasing the number of buckets.
7585
///
76-
/// The load factor measures what fraction of the cuckoo table's capacity is filled with data, as measured by
77-
/// serialization size. The target load factor is used to reserve capacity in the cuckoo table at initialization
78-
/// and expansion as entries are inserted.
86+
/// The load factor measures what fraction of the cuckoo table's capacity is filled with data,
87+
/// as measured by serialization size. The target load factor is used to reserve capacity
88+
/// in the cuckoo table at initialization and expansion as entries are inserted.
7989
AllowExpansion {
80-
/// Multiplicative factor by which to increase the number of buckets during expansion. Must be > 1.0.
90+
/// Multiplicative factor by which to increase the number of buckets during expansion. Must
91+
/// be > 1.0.
8192
expansion_factor: f64,
8293
/// Fraction of the cuckoo table's capacity to fill with data. Must be in `[0.0, 1.0]`.
8394
target_load_factor: f64,
@@ -118,7 +129,6 @@ impl CuckooTableConfig {
118129
/// - `max_eviction_count`: Maximum number of evictions to perform when inserting a new entry.
119130
/// - `max_serialized_bucket_size`: Maximum size of a serialized bucket, in bytes.
120131
/// - `bucket_count`: Number of buckets in the cuckoo table.
121-
///
122132
pub fn new(
123133
hash_function_count: usize,
124134
max_eviction_count: usize,
@@ -263,7 +273,6 @@ impl CuckooBucket {
263273
///
264274
/// - `value`: The value to insert.
265275
/// - `config`: The cuckoo table configuration.
266-
///
267276
pub fn can_insert(&self, value: &KeywordValue, config: &CuckooTableConfig) -> bool {
268277
if self.slots.len() >= HashBucket::MAX_SLOT_COUNT {
269278
return false;
@@ -279,7 +288,6 @@ impl CuckooBucket {
279288
///
280289
/// - `new_value`: The value to insert.
281290
/// - `config`: The cuckoo table configuration.
282-
///
283291
pub fn swap_indices(&self, new_value: &Vec<u8>, config: &CuckooTableConfig) -> Vec<usize> {
284292
let current_values: Vec<&Vec<u8>> = self.slots.iter().map(|entry| &entry.value).collect();
285293
// Loop over prefixes that include `newValue` but omit a single existing value
@@ -327,8 +335,8 @@ impl EvictIndex {
327335
}
328336
}
329337

330-
/// A Cuckoo table is a data structure that stores a set of keyword-value pairs, using cuckoo hashing to resolve
331-
/// conflicts.
338+
/// A Cuckoo table is a data structure that stores a set of keyword-value pairs, using cuckoo
339+
/// hashing to resolve conflicts.
332340
pub struct CuckooTable {
333341
/// The configuration for the cuckoo table.
334342
pub config: CuckooTableConfig,
@@ -527,7 +535,6 @@ impl CuckooTable {
527535
/// - `hash_index`: The index of the hash, provided by `HashKeyword::hash_indices`.
528536
///
529537
/// # Returns
530-
///
531538
pub fn index(&self, table_index: usize, hash_index: usize) -> usize {
532539
if self.table_count() == 1 {
533540
hash_index
@@ -538,8 +545,9 @@ impl CuckooTable {
538545

539546
/// Expands the cuckoo table.
540547
///
541-
/// Expansion is only allowed if the configuration allows it. If allowed, the number of buckets is increased by the
542-
/// expansion factor. Old entries are rehashed and inserted into the new buckets.
548+
/// Expansion is only allowed if the configuration allows it. If allowed, the number of buckets
549+
/// is increased by the expansion factor. Old entries are rehashed and inserted into the new
550+
/// buckets.
543551
///
544552
/// # Errors
545553
///
@@ -628,12 +636,13 @@ impl CuckooTable {
628636

629637
#[cfg(test)]
630638
mod tests {
631-
use crate::private_information_retrieval::cuckoo_table::*;
632-
use crate::private_information_retrieval::hash_bucket::HashKeyword;
633-
use crate::private_information_retrieval::pir_test_utils::get_test_table;
634639
use rand::rngs::StdRng;
635640
use rand_core::SeedableRng;
636641

642+
use crate::private_information_retrieval::{
643+
cuckoo_table::*, hash_bucket::HashKeyword, pir_test_utils::get_test_table,
644+
};
645+
637646
fn get_test_cuckoo_table_config(max_serialized_bucket_size: usize) -> CuckooTableConfig {
638647
CuckooTableConfig {
639648
hash_function_count: 2,

src/private_information_retrieval/error.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::private_information_retrieval::cuckoo_table::{
16-
CuckooTableConfigError, CuckooTableError,
17-
};
18-
use crate::private_information_retrieval::hash_bucket::HashBucketError;
19-
use crate::private_information_retrieval::keyword_database::KeywordDatabaseError;
2015
use thiserror::Error;
2116

17+
use crate::private_information_retrieval::{
18+
cuckoo_table::{CuckooTableConfigError, CuckooTableError},
19+
hash_bucket::HashBucketError,
20+
keyword_database::KeywordDatabaseError,
21+
};
22+
2223
#[derive(Debug, Clone, Error, PartialEq)]
2324
pub enum PirError {
2425
#[error("HashBucketError: {0}")]

0 commit comments

Comments
 (0)