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
//! Value merge strategies for unioning dictionaries.
//!
//! Extracted from `union_zipper.rs` (C6 dedup) into its own module so the
//! merge-strategy surface is easier to find and extend. Re-exported from
//! [`crate::union_zipper`] for back-compat.
/// Strategy for merging values when the same term exists in multiple dictionaries.
///
/// This trait allows customization of how duplicate values are handled during
/// union iteration.
///
/// # Built-in Strategies
///
/// - [`FirstWins`]: Keep the value from the first dictionary (default)
/// - [`LastWins`]: Keep the value from the last dictionary
///
/// For value types that form a lattice, see
/// [`super::lattice::LatticeJoin`] and [`super::lattice::LatticeMeet`].
///
/// # Custom Strategies
///
/// Implement this trait for custom merge logic:
///
/// ```rust
/// use libdictenstein::union_zipper::ValueMergeStrategy;
///
/// #[derive(Clone)]
/// struct Sum;
///
/// impl ValueMergeStrategy<i32> for Sum {
/// fn merge(&self, existing: i32, new: i32) -> i32 {
/// existing + new
/// }
/// }
/// ```
/// Keep the first value seen (from earlier dictionaries in the union).
///
/// This is the default strategy. When a term exists in multiple dictionaries,
/// the value from the first dictionary (lowest index) wins.
///
/// # Example
///
/// ```rust
/// use libdictenstein::union_zipper::{UnionZipper, FirstWins};
/// # use libdictenstein::prelude::*;
/// # use libdictenstein::double_array_trie_zipper::DoubleArrayTrieZipper;
///
/// // dict1 has "cat" -> 1, dict2 has "cat" -> 10
/// // With FirstWins, "cat" -> 1
/// ```
;
/// Keep the last value seen (from later dictionaries in the union).
///
/// When a term exists in multiple dictionaries, the value from the last
/// dictionary (highest index) wins.
///
/// # Example
///
/// ```rust
/// use libdictenstein::union_zipper::{UnionZipper, LastWins};
/// # use libdictenstein::prelude::*;
/// # use libdictenstein::double_array_trie_zipper::DoubleArrayTrieZipper;
///
/// // dict1 has "cat" -> 1, dict2 has "cat" -> 10
/// // With LastWins, "cat" -> 10
/// ```
;