Categories
Tags
3d ABI Actions algorithms alignment analyze APIT Arc Architecture arm array ascii ash assembly asynchronous attribute base64 bithacks Blogging box c c23 cdylib CHAR_BIT clamp clang clang-format client clippy cmake compiler Computer concat concurrency const_fn constexpr contravariant cos covariant cpp cpu crate CS Customization cybersecurity DataStructure db debugging Demo deserialization discrete dll doc DP drawio dtruss dylib Dynamic emulator example Example FFI ffmpeg flamegraph flat_map fold format FP fsanitize Functional FunctionalProgramming functions futures Fuwari game GATs gcc gccrs generics gitignore glibc GUI hacking hashmap haskell heap hyperfine Imperative inference intel interop invariant iterator join justfile kernel LaTeX leak LFU limits linux lto MachineLearning macOS map Markdown math ML mmap mod mp3 nc nextest OnceLock optimization OS ownership panic parallels perf physics pin postgresql procedure product profiling pub radare2 rayon release reverse RPIT rust sanitizer Science science serialization server shift SIMD sin size SmallProjects so socket std strace String StringView strip strlen struct sum super surrealdb SWAR swisstable synchronous syscall tan test thread time toml tracing traits trap triangulation type uint32_t UnsafeRust utf16 utf8 vector Video vulkan wsl x86_64 xilem zig
218 words
1 minutes
240702_shift_training
link
shift001(0 index를 삭제하기)
use std::ops::Shl;
// Newtype wrapper to enable Shl implementation
struct ShiftVec<T>(Vec<T>);
impl<T: Copy> Shl<usize> for ShiftVec<T> {
type Output = ShiftVec<T>;
fn shl(mut self, rhs: usize) -> Self::Output {
// Left shift: remove elements from front
for _ in 0..rhs {
if !self.0.is_empty() {
self.0.remove(0);
}
}
self
}
}
fn main() {
let my_arr = ShiftVec(vec![1, 2, 3, 4, 5]);
println!("before arr : {:?}", my_arr.0);
let res = my_arr << 1;
println!("after arr : {:?}", res.0);
}- result
before arr : [1, 2, 3, 4, 5]
after arr : [2, 3, 4, 5]shift002(0 index에 0추가하기)
use std::ops::Shl;
// Newtype wrapper to enable Shl implementation
struct ShiftVec<T>(Vec<T>);
impl<T: Copy + Default> Shl<usize> for ShiftVec<T> {
type Output = ShiftVec<T>;
fn shl(mut self, rhs: usize) -> Self::Output {
// Left shift: add zeros to front (push_front)
for _ in 0..rhs {
// insert 0 at the beginning (push_front equivalent)
self.0.insert(0, T::default());
}
self
}
}
fn main() {
let my_arr = ShiftVec(vec![1i32, 2, 3, 4, 5]);
println!("before arr : {:?}", my_arr.0);
let res = my_arr << 1;
println!("after arr : {:?}", res.0);
}- result
before arr : [1, 2, 3, 4, 5]
after arr : [0, 1, 2, 3, 4, 5]240702_shift_training
https://younghakim7.github.io/blog/posts/240702_shift_training/