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
//! Per-monomorph routing for the VALUED byte counter increment
//! (`route_increment_bytes`).
//!
//! # Why this module exists (the byte twin of char's `lockfree_value_route`)
//!
//! The byte lock-free overlay's value-write path
//! ([`build_value_path_recursive`](super::dict_impl::PersistentARTrie)) and the
//! valued Order-A durable primitives (`insert_cas_with_value_durable` /
//! `upsert_cas_durable` / `try_increment_cas_durable` / `get_lockfree`) are all
//! defined on the `impl<S> PersistentARTrie<u64, S>` block (the byte counter
//! monomorph, now `u64` matching char). So the u64 add-only counter fast path —
//! which lives in one generic `impl<V: DictionaryValue + Serialize +
//! DeserializeOwned, S>` block that cannot name `PersistentARTrie<u64, S>`'s
//! inherent methods — must route to the overlay ONLY for the `V = u64` monomorph.
//!
//! Rust has no stable specialization, so — exactly as char — the idiomatic,
//! **zero-unsafe** solution is a free function that does a SAFE
//! [`Any`](std::any::Any) downcast of `&self` to the `u64` monomorph
//! (`DictionaryValue: 'static`, and the trie + block storage are `'static`), then
//! calls the thin Order-A overlay primitives. When the downcast fails (`V != u64`)
//! it returns `None`, signalling the caller to run the general overlay value-CAS
//! increment path (which handles a wider counter type and decrements). The overlay
//! is the sole representation for ALL `V`, so both branches write to the overlay.
use Any;
use BlockStorage;
use PersistentARTrie;
use Result;
use crateDictionaryValue;
/// Route `increment_bytes(term, delta)` to the overlay iff `V == u64` AND
/// `delta >= 0`.
///
/// The overlay counter is the add-only `BatchIncrement` seam, so a NEGATIVE delta
/// returns `None` (the caller falls to the value-CAS path
/// `increment_bytes_via_value_cas`, which reads → `cur + delta` → CAS and rejects a
/// below-zero result) — the byte twin of char's `route_increment`. Returns `None`
/// for arbitrary `V` too. On success the new accumulated count (a `u64`) is widened
/// to `i128` so the V-aware caller in `atomic_ops` re-encodes it via
/// `i128_to_counter_value::<V>` (the widening `as i128` is lossless and the ONE cast
/// the counter-codec gate sanctions). `try_increment_cas_durable` itself rejects a
/// non-UTF-8 key (the byte durable increment operates on UTF-8 keys).
pub
// ============================================================================
// SUPERSEDED in Flip F0 (G5) — byte twin of the char supersession. The valued
// mutators (`insert_with_value`/`upsert`/`get_or_insert`/`compare_and_swap`/
// `insert_batch`) now route to the SHARED GENERIC `DurableOverlayWrite::*_default`
// methods (generic over `V` via the `value_publish_inner` seam), so these
// i64-downcast helpers are obsolete. Commented out (NOT deleted — F0 is reversible);
// only `route_increment_bytes` (above) keeps the downcast (counter is u64-only, NH3).
// The downcast-then-`None`-fallback they did is the NH1 data-loss footgun the design
// removes (arbitrary `V` → `None` → owned write → unranked → dropped on reopen).
//
// pub(super) fn route_insert_with_value_bytes<V, S>(trie, term, value) -> Option<Result<bool>>
// { downcast to <u64>; Some(trie_u64.insert_cas_with_value_durable(term, *v_u64)) }
// pub(super) fn route_upsert_bytes<V, S>(trie, term, value) -> Option<Result<bool>>
// { downcast to <u64>; Some(trie_u64.upsert_cas_durable(term, *v_u64)) }
// pub(super) fn route_get_or_insert_bytes<V, S>(trie, term, default) -> Option<Result<V>>
// { downcast to <u64>; insert-if-absent then get_lockfree read-back }
// (Full bodies in git history; the generic `DurableOverlayWrite` defaults replace them.)
// ============================================================================