Chris Mikkelson [Sat, 21 Jun 2025 20:33:18 +0000 (15:33 -0500)]
Massive refactor #N for borrowing iteration
New "Cursor" abstraction returns a tuple of references to a byte slice
key and associated Value type. This tuple replaces Entry (removed), and
the cursor's immutable get() allows the merger heap to use the cursor
directly for ordering.
WIP, several bugs likely remain, but unit tests pass.
Chris Mikkelson [Fri, 2 May 2025 05:42:52 +0000 (00:42 -0500)]
Lots of WIP on new lending "Cursor" abstraction
Added merger of cursors and of duplicates. IntoIterator implementations
for Cursors which maintain a local copy of the value modified to use
take() instead of .clone()ing values. Getting closer to zero copy.
Merger uses Ord wrappers on the cursors themselves to provide duplicate
sorting or unsorting, which removes the need to copy values to wrap them
in an ordering wrapper.
Overall, code is getting simpler with fewer copies, a win-win.
Chris Mikkelson [Wed, 16 Apr 2025 05:06:47 +0000 (00:06 -0500)]
Refactor, again (WIP)
Break up some larger files into smaller chunks, also decouple Iter
and Iterator again, in favor of implementing IntoIterator for
Iter implementations.
Still a few remaining nits to work out -- the IntoIterator trait
isn't coming into scope where I expect it, so may need to back
off of `impl Iter` in favor of an associated type on Source which
requires IntoIterator.
Chris Mikkelson [Fri, 13 Sep 2024 17:55:46 +0000 (12:55 -0500)]
Simplify merge_func, dupsort helpers
Add the iterator wrapper methods to the Iter trait, allowing
the source implementations to apply them to the inner iterator
rather than constructing the implementation structs directly.
Chris Mikkelson [Fri, 6 Sep 2024 21:23:57 +0000 (16:23 -0500)]
More cleanup from "impl Iter" based sources
Not having to explicitly name the iterator return types saves
the need to name the returned iterator's reference lifetimes, if any.
This removes the need to implement Source on a reference to a type
in order to assign `&self` a lifetime.
Once again, we can implment Source on an owned type reliably, saving
the need for pointer indirections.
Chris Mikkelson [Tue, 23 Jul 2024 20:15:21 +0000 (15:15 -0500)]
Generic sources working after big refactor.
Root cause was Box<dyn Trait> defaults to Box<dyn Trait + 'static>,
leading to the 'static lifetime "infecting" the generated iterators,
causing the borrow to last beyond the end of the function which dropped
the box or its containing structure.
The quick fix was to inject and add an explicit lifetime to the Box.
While tuning that fix, opted to inject lifetimes by implementing
Source methods on references. This tracks more with the C mtbl API,
where:
m = mtbl_merger_init(mopt);
/* populate m */
mtbl_merger_source(m);
Chris Mikkelson [Sun, 21 Jul 2024 00:40:23 +0000 (19:40 -0500)]
Refactor Source trait hierarchy
Source implements get/prefix/range, and is a subtrait of
IterSource which implements only iter(). The Default
implementation is now another subtrait of IterSource.
This avoids several of the previouas `Source<'a> + Ranges<'a>`
and 'Source<'a> + DefaultRanges' type constraints, and
simplifies type paths.
Chris Mikkelson [Fri, 19 Jul 2024 17:10:19 +0000 (12:10 -0500)]
WIP commit: attempt to make Source object safe
Use associated iterator types instead of `impl Iter`. Move
get, get_prefix, get_range to separate "Ranges" trait, with
a generic default implementation based on iter() enabled by
"DefaultRanges" trait.
Chris Mikkelson [Mon, 29 Apr 2024 01:44:00 +0000 (20:44 -0500)]
Modify filter_map to only map values
Mapping keys requires a conversion on seek from the
mapped key to the inner key. Since the keys are passed
to seek by reference to avoid moves, this complicates
consuming the key for a full conversion to the inner
key.
For now, restrict mapping to values only. This required
changing the filter function signature to take a reference
to the key so its caller could retain the key for returning.