1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! Document-transaction data type for the char trie.
//!
//! Split out of char `dict_impl_char.rs` (lines ~124-200) as part of the
//! Phase-6 decomposition, mirroring the byte variant's
//! `persistent_artrie::transactions::DocumentTransaction`. The commit /
//! abort machinery (begin_document, tx_insert, tx_insert_chars,
//! commit_document, abort_document) stays on `PersistentARTrieChar` in
//! `dict_impl_char.rs`; only the data carrier lives here.
use crateTransactionState;
use crateDictionaryValue;
/// A document transaction for per-document atomicity in the character trie.
///
/// This struct buffers all terms for a single document in memory. When the
/// document processing succeeds, `commit_document()` atomically applies all
/// terms to the trie with a single batch WAL write. If processing fails,
/// `abort_document()` discards the buffer without polluting the trie or WAL.
///
/// # Character vs Byte Handling
///
/// This transaction stores terms as both string bytes (for WAL serialization)
/// and allows direct `char` slice insertion. Internally, characters are stored
/// as UTF-8 bytes for WAL compatibility with the 1-byte trie format.
///
/// # Example
///
/// ```rust,no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use libdictenstein::persistent_artrie_char::{PersistentARTrieChar, CharDocumentTransaction};
///
/// let mut trie = PersistentARTrieChar::<u64>::create("unicode_docs.trie")?;
///
/// // Start a transaction for a document
/// let mut tx = trie.begin_document("doc_001")?;
///
/// // Buffer terms (not yet committed)
/// trie.tx_insert(&mut tx, "日本語", Some(1));
/// trie.tx_insert(&mut tx, "中文", Some(2));
/// trie.tx_insert_chars(&mut tx, &['한', '글'], Some(3));
///
/// // Commit all terms atomically
/// let count = trie.commit_document(tx)?;
/// assert_eq!(count, 3);
/// # Ok(())
/// # }
/// ```