Trait aoko::no_std::functions::ext::ArrExt[][src]

pub trait ArrExt {
    fn swap_xor(self, i: usize, j: usize) -> Self;
}
Expand description

This trait is to implement some extension functions for [T] type.

Required methods

Implementations on Foreign Types

Swaps two elements in a slice.

Parameters
  • i - The index of the first element
  • j - The index of the second element
Panics

Panics if i or j are out of bounds.

Examples
let mut v = [0, 1, 2, 3, 4];
v.swap(1, 3);
assert!(v == [0, 3, 2, 1, 4]);
Principles
  • a = 甲, b = 乙

  • a = a ^ b => a = 甲 ^ 乙, b = 乙

  • b = a ^ b => a = 甲 ^ 乙, b = 甲 ^ (乙 ^ 乙) = 甲 ^ 0 = 甲

  • a = a ^ b => a = 甲 ^ 乙 ^ 甲 = 甲 ^ 甲 ^ 乙 = 0 ^ 乙 = 乙

Implementors