Skip to content

Commit

Permalink
support appennd (+=)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryoris committed Feb 17, 2025
1 parent 6a26224 commit faa9863
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions crates/cext/src/sparse_observable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,34 @@ pub unsafe extern "C" fn qk_obs_add(
Box::into_raw(Box::new(result))
}

/// @ingroup QkSparseObservable
/// Add two observables.
///
/// @param left A pointer to the left observable.
/// @param right A pointer to the right observable.
///
/// @return A pointer to the result ``left + right``.
///
/// # Example
///
/// QkSparseObservable *left = qk_obs_identity(100);
/// QkSparseObservable *right = qk_obs_zero(100);
/// QkSparseObservable *result = qk_obs_add(left, right);
///
/// # Safety
///
/// Behavior is undefined if ``left`` or ``right`` are not valid, non-null pointers to
/// ``QkSparseObservable``\ s.
#[no_mangle]
#[cfg(feature = "cbinding")]
pub unsafe extern "C" fn qk_obs_append(obs: *mut SparseObservable, other: *const SparseObservable) {
// SAFETY: Per documentation, the pointers are non-null and aligned.
let obs = unsafe { mut_ptr_as_ref(obs) };
let other = unsafe { const_ptr_as_ref(other) };

*obs += other;
}

/// @ingroup QkSparseObservable
/// Calculate the canonical representation of the observable.
///
Expand Down

0 comments on commit faa9863

Please sign in to comment.