Skip to content

docs: fix the complexity claim on Database::remove - #1344

Merged
ajeetdsouza merged 2 commits into
ajeetdsouza:mainfrom
ump45nose:qwen/docs-db-remove-complexity
Oct 23, 2026
Merged

ajeetdsouza merged 2 commits into
ajeetdsouza:mainfrom
ump45nose:qwen/docs-db-remove-complexity

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Database::remove is documented as O(1):

/// Removes the directory with `path` from the store. This does not preserve
/// ordering, but is O(1).
pub fn remove(&mut self, path: impl AsRef<str>) -> bool {
    match self.dirs().iter().position(|dir| dir.path == path.as_ref()) {

The lookup is a linear scan over every entry (iter().position(..)), so the call is O(n); only the subsequent swap_remove is O(1) — which is also what "does not preserve ordering" refers to. Reworded the doc comment to state both costs. No behaviour change.

Tested: cargo check --all-targets passes on this branch (exit 0); rustfmt --check reports no diff for src/db/mod.rs (the crate's nightly-only wrap_comments option is ignored by stable rustfmt, so the comment reflow stays within the existing 100-column style).

ump45nose and others added 2 commits October 23, 2026 00:54
The doc comment promised O(1), but remove() first locates the entry with
position() over all dirs, which is O(n); only the swap_remove that
follows is O(1).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@ajeetdsouza ajeetdsouza left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ajeetdsouza
ajeetdsouza merged commit a053d91 into ajeetdsouza:main Oct 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants