Skip to main content

FastInput

Struct FastInput 

Source
pub struct FastInput {
    ptr: *const u8,
}

Fields§

§ptr: *const u8

Implementations§

Source§

impl FastInput

Source

pub unsafe fn stdin() -> Self

Source

pub unsafe fn from_slice(s: &[u8]) -> Self

Examples found in repository?
crates/library_checker/src/sample/many_aplusb.rs (line 19)
16pub fn many_aplusb_fast(reader: impl Read, writer: impl Write) {
17    let s = read_all_unchecked(reader);
18    let mut writer = FastOutput::with_capacity(1 << 12, writer);
19    let mut scanner = unsafe { FastInput::from_slice(s.as_bytes()) };
20    let t = unsafe { scanner.u64() };
21    for _ in 0..t {
22        let a = unsafe { scanner.u64() };
23        let b = unsafe { scanner.u64() };
24        writer.u64(a + b);
25        writer.byte(b'\n');
26    }
27}
Source

unsafe fn fetch_ud4(&mut self) -> u16

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 73)
72    pub unsafe fn u8(&mut self) -> u8 {
73        unsafe { self.fetch_ud4() as u8 }
74    }
Source

unsafe fn fetch_ud8(&mut self) -> u32

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 77)
76    pub unsafe fn u16(&mut self) -> u16 {
77        unsafe { self.fetch_ud8() as u16 }
78    }
79
80    /// 0..=99_999_999
81    pub unsafe fn u32_small(&mut self) -> u32 {
82        unsafe { self.fetch_ud8() }
83    }
Source

pub unsafe fn u8(&mut self) -> u8

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 276)
272    pub unsafe fn i8(&mut self) -> i8 {
273        unsafe {
274            let b = *self.ptr == b'-';
275            self.ptr = self.ptr.add(b as usize);
276            let mut x = self.u8() as i8;
277            if b {
278                x = x.wrapping_neg();
279            }
280            x
281        }
282    }
Source

pub unsafe fn u16(&mut self) -> u16

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 288)
284    pub unsafe fn i16(&mut self) -> i16 {
285        unsafe {
286            let b = *self.ptr == b'-';
287            self.ptr = self.ptr.add(b as usize);
288            let mut x = self.u16() as i16;
289            if b {
290                x = x.wrapping_neg();
291            }
292            x
293        }
294    }
Source

pub unsafe fn u32_small(&mut self) -> u32

0..=99_999_999

Source

pub unsafe fn u32(&mut self) -> u32

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 300)
296    pub unsafe fn i32(&mut self) -> i32 {
297        unsafe {
298            let b = *self.ptr == b'-';
299            self.ptr = self.ptr.add(b as usize);
300            let mut x = self.u32() as i32;
301            if b {
302                x = x.wrapping_neg();
303            }
304            x
305        }
306    }
Source

pub unsafe fn u64(&mut self) -> u64

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 269)
268    pub unsafe fn usize(&mut self) -> usize {
269        unsafe { self.u64() as usize }
270    }
271
272    pub unsafe fn i8(&mut self) -> i8 {
273        unsafe {
274            let b = *self.ptr == b'-';
275            self.ptr = self.ptr.add(b as usize);
276            let mut x = self.u8() as i8;
277            if b {
278                x = x.wrapping_neg();
279            }
280            x
281        }
282    }
283
284    pub unsafe fn i16(&mut self) -> i16 {
285        unsafe {
286            let b = *self.ptr == b'-';
287            self.ptr = self.ptr.add(b as usize);
288            let mut x = self.u16() as i16;
289            if b {
290                x = x.wrapping_neg();
291            }
292            x
293        }
294    }
295
296    pub unsafe fn i32(&mut self) -> i32 {
297        unsafe {
298            let b = *self.ptr == b'-';
299            self.ptr = self.ptr.add(b as usize);
300            let mut x = self.u32() as i32;
301            if b {
302                x = x.wrapping_neg();
303            }
304            x
305        }
306    }
307
308    pub unsafe fn i64(&mut self) -> i64 {
309        unsafe {
310            let b = *self.ptr == b'-';
311            self.ptr = self.ptr.add(b as usize);
312            let mut x = self.u64() as i64;
313            if b {
314                x = x.wrapping_neg();
315            }
316            x
317        }
318    }
More examples
Hide additional examples
crates/library_checker/src/sample/many_aplusb.rs (line 20)
16pub fn many_aplusb_fast(reader: impl Read, writer: impl Write) {
17    let s = read_all_unchecked(reader);
18    let mut writer = FastOutput::with_capacity(1 << 12, writer);
19    let mut scanner = unsafe { FastInput::from_slice(s.as_bytes()) };
20    let t = unsafe { scanner.u64() };
21    for _ in 0..t {
22        let a = unsafe { scanner.u64() };
23        let b = unsafe { scanner.u64() };
24        writer.u64(a + b);
25        writer.byte(b'\n');
26    }
27}
Source

pub unsafe fn u128(&mut self) -> u128

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 324)
320    pub unsafe fn i128(&mut self) -> i128 {
321        unsafe {
322            let b = *self.ptr == b'-';
323            self.ptr = self.ptr.add(b as usize);
324            let mut x = self.u128() as i128;
325            if b {
326                x = x.wrapping_neg();
327            }
328            x
329        }
330    }
Source

pub unsafe fn usize(&mut self) -> usize

Source

pub unsafe fn i8(&mut self) -> i8

Source

pub unsafe fn i16(&mut self) -> i16

Source

pub unsafe fn i32(&mut self) -> i32

Source

pub unsafe fn i64(&mut self) -> i64

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 333)
332    pub unsafe fn isize(&mut self) -> isize {
333        unsafe { self.i64() as isize }
334    }
Source

pub unsafe fn i128(&mut self) -> i128

Source

pub unsafe fn isize(&mut self) -> isize

Source

pub unsafe fn byte(&mut self) -> u8

Source

pub unsafe fn bytes<'a>(&mut self) -> &'a [u8]

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 361)
356    pub unsafe fn parse<T>(&mut self) -> T
357    where
358        T: FromStr,
359    {
360        unsafe {
361            let s = std::str::from_utf8_unchecked(self.bytes());
362            s.parse().ok().unwrap()
363        }
364    }
Source

pub unsafe fn parse<T>(&mut self) -> T
where T: FromStr,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToArrayVecScalar for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.