main.rs

# Cargo.toml [package] name = "levenshtein" [dependencies] tfhe = { path = "../tfhe-rs/tfhe", features = ["boolean", "shortint", "integer", "x86_64-unix", "gpu"] }
mail@pastecode.io avatar
unknown
rust
5 months ago
2.6 kB
2
Indexable
extern crate tfhe;
use std::collections::HashMap;
use std::time::Instant;
use tfhe::prelude::*;
use tfhe::{set_server_key, ClientKey, CompressedServerKey, ConfigBuilder, FheUint8,
    FheUint16};
use tfhe::shortint::parameters::PARAM_GPU_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS
    ;
struct Levenshtein {
x: Vec<FheUint8>,
y: Vec<FheUint8>,
zero: FheUint16,
}
fn encode(c: u8) -> u8 {
return c - 41u8;
}
impl Levenshtein {
fn encrypt(x: &str, y: &str, client_key: &ClientKey) -> Self {
let fhe_x = x
.bytes()
.map(|b| FheUint8::encrypt(encode(b), client_key))
.collect();
let fhe_y = y
.bytes()
.map(|b| FheUint8::encrypt(encode(b), client_key))
.collect();
let fhe_zero = FheUint16::encrypt(0u16, client_key);
Self { x: fhe_x, y: fhe_y, zero: fhe_zero }
}
fn levenshtein(&self) -> FheUint16 {
let mut memo = HashMap::new();
self._levenshtein(&self.x, &self.y, &mut memo)
}
fn _levenshtein(
&self,
x: &[FheUint8],
y: &[FheUint8],
memo: &mut HashMap<(u16, u16), FheUint16>
) -> FheUint16 {
let key = (x.len() as u16, y.len() as u16);
if let Some(result) = memo.get(&key) {
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Leave a Comment

Please, sign-in to leave a comment.