Re: [PATCH v4 07/11] rust: xarray: add entry API

From: Andreas Hindborg

Date: Fri Aug 28 2026 - 07:34:35 EST


Andreas Hindborg <a.hindborg@xxxxxxxxxx> writes:

> Tamir Duberstein <tamird@xxxxxxxxxx> writes:
>
>> On Thu, 04 Jun 2026 21:58:13 +0200, Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>>> Add an Entry API for XArray that provides ergonomic access to array
>>> slots that may be vacant or occupied. The API follows the pattern of
>>> Rust's standard library HashMap entry API, allowing efficient
>>> conditional insertion and modification of entries.
>>
>> There's a lot more API here than this lets on.
>> `find_next_entry{,_circular}`, `Entry::is_occupied`, `into_guard`,
>> `insert{,_entry}` (do we need both?), `index`, `OccupiedEntry::swap`,
>> `Deref{,Mut}`.
>
> I can amend the commit message to enumerate the added methods.

Looking over this again, I was pondering on removing `insert` in favor
of `insert_entry`, but I decided the duplication is OK. From the caller
perspective, code will be cleaner to read for simple insert operations
with the `insert` method. But complex query/replace operations can be
completed more efficient with the entry API by avoiding multiple tree
walks.

Similarly for `is_occupied`, code at call sites will be easier to read
when using this method.

Best regards,
Andreas Hindborg