pub fn diff_balances_iter<I1, I2>(base: I1, target: I2) -> BalancesDiffExpand description
Computes a compact balance delta between two balance iterators.
This is the generic counterpart to diff_balances. It is intended for
consensus clients whose balance storage is not represented as a contiguous
&[u64].
The iterators must implement ExactSizeIterator, allowing the function
to determine the size of the common portion and distinguish existing
balances from balances appended to the target.
The iterators are consumed during encoding and do not need to implement
Clone.
The common portion is first collected into a compact list of changed balances so that the most frequently occurring balance difference can be selected as the encoding mode. Remaining items in the target iterator are stored as appended balances.
ยงComplexity
O(n) time and O(k + a) additional space, where:
nis the number of balances in the common portion;kis the number of changed balances; andais the number of balances appended to the target.