Kixiron / lasso

A fast, concurrent string interner
Apache License 2.0
139 stars 19 forks source link

Make interner iterators more like slice iterators #14

Closed jameysharp closed 3 years ago

jameysharp commented 3 years ago

The iterators for iter() and strings() were less useful than iterators over the underlying slice of strings. This commit makes them more equivalent, without having to expose implementation details.

The underlying iterators are efficiently clonable (they're just a couple of pointers and, for Iter, a count) so this crate's iterators can be cloned efficiently too.

Similarly, slice and enumeration iterators can be efficiently navigated both forward and backward, and they're both fused iterators as well.

This does have forward-compatibility implications since this represents a promise that either future implementations will also be efficiently clonable and double-ended, or the semver will change.

A better way to get the same result would be to make iter() and strings() return impl Iterator<...> + Clone + DoubleEndedIterator + ExactSizeIterator + FusedIterator. That would also avoid a bunch of boilerplate and allow using the standard library's efficient implementations of methods like Iterator::nth, instead of the current use of the inefficient default implementations.

Unfortunately, support for impl Trait in associated types hasn't stabilized yet (rust-lang/rust#63063), so that would currently only work on nightly Rust.

Kixiron commented 3 years ago

Thanks!