Skip to content

Commit 22cf251

Browse files
committed
chore(docs): add HL strings documentation
1 parent fc4abd5 commit 22cf251

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

tfhe/docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* [Ternary conditional operations](fhe-computation/operations/ternary-conditional-operations.md)
2828
* [Casting operations](fhe-computation/operations/casting-operations.md)
2929
* [Boolean Operations](fhe-computation/operations/boolean-operations.md)
30+
* [String Operations](fhe-computation/operations/string-operations.md)
3031
* [Core workflow](fhe-computation/compute/README.md)
3132
* [Configuration and key generation](fhe-computation/compute/configure-and-generate-keys.md)
3233
* [Server key](fhe-computation/compute/set-the-server-key.md)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# String operations
2+
3+
This document details the string operations supported by **TFHE-rs**.
4+
5+
| clear name | fhe name | first input type | second input type | third input type
6+
| --------------------------------------------------------------------------------------------------------------- | -------------------- | -------------- | ---------------------------------------------- | ------------------
7+
| [eq](https://doc.rust-lang.org/stable/std/primitive.str.html#method.eq) |eq | FheAsciiString | FheAsciiString or ClearString |
8+
| [ne](https://doc.rust-lang.org/stable/std/primitive.str.html#method.ne) |ne | FheAsciiString | FheAsciiString or ClearString |
9+
| [le](https://doc.rust-lang.org/stable/std/primitive.str.html#method.le) |le | FheAsciiString | FheAsciiString or ClearString |
10+
| [ge](https://doc.rust-lang.org/stable/std/primitive.str.html#method.ge) |ge | FheAsciiString | FheAsciiString or ClearString |
11+
| [lt](https://doc.rust-lang.org/stable/std/primitive.str.html#method.lt) |lt | FheAsciiString | FheAsciiString or ClearString |
12+
| [gt](https://doc.rust-lang.org/stable/std/primitive.str.html#method.gt) |gt | FheAsciiString | FheAsciiString or ClearString |
13+
| [len](https://doc.rust-lang.org/stable/std/primitive.str.html#method.len) |len | FheAsciiString | |
14+
| [is_empty](https://doc.rust-lang.org/stable/std/primitive.str.html#method.is_empty) |is_empty | FheAsciiString | |
15+
| [eq_ignore_ascii_case](https://doc.rust-lang.org/stable/std/primitive.str.html#method.eq_ignore_ascii_case) |eq_ignore_case | FheAsciiString | FheAsciiString or ClearString |
16+
| [to_lowercase](https://doc.rust-lang.org/stable/std/primitive.str.html#method.to_lowercase) |to_lowercase | FheAsciiString | |
17+
| [to_uppercase](https://doc.rust-lang.org/stable/std/primitive.str.html#method.to_uppercase) |to_uppercase | FheAsciiString | |
18+
| [contains](https://doc.rust-lang.org/stable/std/primitive.str.html#method.contains) |contains | FheAsciiString | FheAsciiString or ClearString |
19+
| [ends_with](https://doc.rust-lang.org/stable/std/primitive.str.html#method.ends_with) |ends_with | FheAsciiString | FheAsciiString or ClearString |
20+
| [starts_with](https://doc.rust-lang.org/stable/std/primitive.str.html#method.starts_with) |starts_with | FheAsciiString | FheAsciiString or ClearString |
21+
| [find](https://doc.rust-lang.org/stable/std/primitive.str.html#method.find) |find | FheAsciiString | FheAsciiString or ClearString |
22+
| [rfind](https://doc.rust-lang.org/stable/std/primitive.str.html#method.rfind) |rfind | FheAsciiString | FheAsciiString or ClearString |
23+
| [strip_prefix](https://doc.rust-lang.org/stable/std/primitive.str.html#method.strip_prefix) |strip_prefix | FheAsciiString | FheAsciiString or ClearString |
24+
| [strip_suffix](https://doc.rust-lang.org/stable/std/primitive.str.html#method.strip_suffix) |strip_suffix | FheAsciiString | FheAsci---iString or ClearString |
25+
| [concat](https://doc.rust-lang.org/stable/std/primitive.str.html#method.concat) |concat | FheAsciiString | FheAsciiString |
26+
| [repeat](https://doc.rust-lang.org/stable/std/primitive.str.html#method.repeat) |repeat | FheAsciiString | u16 or u32 or i32 or usize or (FheUint16, u16) |
27+
| [trim_end](https://doc.rust-lang.org/stable/std/primitive.str.html#method.trim_end) |trim_end | FheAsciiString | |
28+
| [trim_start](https://doc.rust-lang.org/stable/std/primitive.str.html#method.trim_start) |trim_start | FheAsciiString | |
29+
| [trim](https://doc.rust-lang.org/stable/std/primitive.str.html#method.trim) |trim | FheAsciiString | |
30+
| [replace](https://doc.rust-lang.org/stable/std/primitive.str.html#method.replace) |replace | FheAsciiString | FheAsciiString |
31+
| [replacen](https://doc.rust-lang.org/stable/std/primitive.str.html#method.replacen) |replacen | FheAsciiString | FheAsciiString or ClearString | u16 or u32 or i32 or usize or (FheUint16, u16)
32+
33+
The following example shows how to perform string operations:
34+
35+
```rust
36+
use tfhe::prelude::*;
37+
use tfhe::{
38+
generate_keys, set_server_key, ConfigBuilder, FheAsciiString, FheStringLen,
39+
};
40+
41+
fn main() -> Result<(), Box<dyn std::error::Error>> {
42+
43+
let config = ConfigBuilder::default().build();
44+
let (client_key, server_key) = generate_keys(config);
45+
set_server_key(server_key);
46+
47+
let string1 = FheAsciiString::try_encrypt("tfhe-RS", &client_key).unwrap();
48+
let string2 = FheAsciiString::try_encrypt("TFHE-rs", &client_key).unwrap();
49+
let is_eq = string1.eq_ignore_case(&string2);
50+
51+
assert!(is_eq.decrypt(&client_key));
52+
53+
Ok(())
54+
}
55+
```

tfhe/src/test_user_docs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ mod test_cpu_doc {
101101
"../docs/fhe-computation/operations/ternary-conditional-operations.md",
102102
operations_ternary_conditional_operations
103103
);
104+
doctest!(
105+
"../docs/fhe-computation/operations/string-operations.md",
106+
operations_string_operations
107+
);
104108

105109
// TOOLING
106110
doctest!("../docs/fhe-computation/tooling/debug.md", tooling_debug);

0 commit comments

Comments
 (0)