This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Integer Square Root | |
| /// | |
| /// `n` is the positive integer for which the return value is the greatest | |
| /// integer less than or equal to the square root of n. | |
| pub fn isqrt(mut n: usize) -> usize { | |
| let mut res = 0; | |
| let mut b = 1 << ((::std::mem::size_of::<usize>() * 8) - 2); | |
| while b > n { | |
| b >>= 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::ops::Range; | |
| fn sum_range2(range: Range<usize>, step: usize) -> usize { | |
| assert!(range.start < range.end && step > 0); | |
| let mut start = range.start; | |
| while start % step != 0 { | |
| start += 1; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[macro_use] | |
| extern crate mopa; | |
| use std::any::TypeId; | |
| use std::fmt::Debug; | |
| // Add std::any::Any methods to Object. | |
| mopafy!(Object); | |
| trait Object: mopa::Any + Debug { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn all_splits<T>(s: &[T]) -> Vec<Vec<&[T]>> { | |
| let len = s.len(); | |
| let mut vv = Vec::with_capacity(1<<(len - 1)); | |
| for mask in 0usize..(1<<(len - 1)) { | |
| let mut v = Vec::with_capacity(mask.count_ones() as usize + 1); | |
| let mut prev = 0; | |
| for i in 1..len { | |
| if (mask >> (i - 1)) & 0b1 != 0 { | |
| v.push(&s[prev..i]); | |
| prev = i; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Diff of https://github.com/brayniac/mpmc/blob/master/src/lib.rs | |
| --- a/src/lib.rs | |
| +++ b/src/lib.rs | |
| @@ -102,7 +102,7 @@ impl<T: Send> State<T> { | |
| let mask = self.mask; | |
| let mut pos = self.enqueue_pos.load(Relaxed); | |
| loop { | |
| - let node = &self.buffer[pos & mask]; | |
| + let node = unsafe { self.buffer.get_unchecked(pos & mask) }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trait Command<T> { | |
| type Err; | |
| fn forward(&mut self, receiver: &mut T) -> Result<(), Self::Err>; | |
| fn backwards(&mut self, receiver: &mut T) -> Result<(), Self::Err>; | |
| } | |
| struct CommandStack<T, C: Command<T>>{ | |
| stack: Vec<C>, | |
| receiver: T, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Running target/debug/deps/test-6852390ff37b5910 | |
| running 73 tests | |
| WARNING: dropped an in-progress AioCbtest sys::test_aio::test_lio_listio_read_immutable ... ok | |
| test sys::test_aio::test_aio_suspend ... ok | |
| test sys::test_aio::test_drop ... ok | |
| test sys::test_aio::test_lio_listio_wait ... ok | |
| test sys::test_aio::test_read_immutable_buffer ... ok | |
| test sys::test_aio::test_cancel ... ok | |
| test sys::test_aio::test_aio_cancel_all ... ok |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| thread 'main' panicked at 'write failed: Value too large for defined data type (os error 75)', test/test_mount.rs:53 | |
| stack backtrace: | |
| 0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace | |
| at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49 | |
| 1: std::sys_common::backtrace::_print | |
| at /checkout/src/libstd/sys_common/backtrace.rs:71 | |
| 2: std::panicking::default_hook::{{closure}} | |
| at /checkout/src/libstd/sys_common/backtrace.rs:60 | |
| at /checkout/src/libstd/panicking.rs:355 | |
| 3: std::panicking::default_hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [package] | |
| name = "load-library-test" | |
| version = "0.1.0" | |
| authors = ["Henning Ottesen <henning@live.no>"] | |
| [dependencies] | |
| winapi = "0.2" | |
| kernel32-sys = "0.2.2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::any::{Any, TypeId}; | |
| use std::collections::BTreeMap; | |
| trait AnySlice { | |
| fn as_any_mut(&mut self) -> &mut Any; | |
| fn any_get(&self, index: usize) -> Option<&Any>; | |
| fn any_len(&self) -> usize; | |
| } | |
| struct AnyCollection(BTreeMap<TypeId, Box<AnySlice>>); |
NewerOlder