Skip to content

Commit

Permalink
Add table showing complexity of methods for Input (#10126)
Browse files Browse the repository at this point in the history
# Objective

Fixes #10106 

Adds a table showing computational complexity, as seen for Query (and
similar to std::collections docs).

## Solution

Add the complexity table

---

## Changelog

- Add complexity table for Input methods

Co-authored-by: James Liu <[email protected]>
  • Loading branch information
ShadowMitia and james7132 authored Mar 10, 2024
1 parent f0a9864 commit 1b3c2b0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions crates/bevy_input/src/button_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ use bevy_ecs::schedule::State;
/// * Using [`ButtonInput::clear_just_pressed`] or [`ButtonInput::clear_just_released`] instead.
/// * Calling [`ButtonInput::clear`] or [`ButtonInput::reset`] immediately after the state change.
///
/// ## Performance
///
/// For all operations, the following conventions are used:
/// - **n** is the number of stored inputs.
/// - **m** is the number of input arguments passed to the method.
/// - **\***-suffix denotes an amortized cost.
/// - **~**-suffix denotes an expected cost.
///
/// See Rust's [std::collections doc on performance](https://doc.rust-lang.org/std/collections/index.html#performance) for more details on the conventions used here.
///
/// | **[`ButtonInput`] operations** | **Computational complexity** |
/// |-----------------------------------|------------------------------------|
/// | [`ButtonInput::any_just_pressed`] | *O*(m*n) |
/// | [`ButtonInput::any_just_released`] | *O*(m*n) |
/// | [`ButtonInput::any_pressed`] | *O*(m*n) |
/// | [`ButtonInput::get_just_pressed`] | *O*(n) |
/// | [`ButtonInput::get_just_released`] | *O*(n) |
/// | [`ButtonInput::get_pressed`] | *O*(n) |
/// | [`ButtonInput::just_pressed`] | *O*(1)~ |
/// | [`ButtonInput::just_released`] | *O*(1)~ |
/// | [`ButtonInput::pressed`] | *O*(1)~ |
/// | [`ButtonInput::press`] | *O*(1)~* |
/// | [`ButtonInput::release`] | *O*(1)~* |
/// | [`ButtonInput::release_all`] | *O*(n)~* |
/// | [`ButtonInput::clear_just_pressed`] | *O*(1)~ |
/// | [`ButtonInput::clear_just_released`] | *O*(1)~ |
/// | [`ButtonInput::reset_all`] | *O*(n) |
/// | [`ButtonInput::clear`] | *O*(n) |
///
/// ## Window focus
///
/// `ButtonInput<KeyCode>` is tied to window focus. For example, if the user holds a button
Expand Down

0 comments on commit 1b3c2b0

Please sign in to comment.