Skip to main content

FastOutput

Struct FastOutput 

Source
pub struct FastOutput<W>
where W: Write,
{ buf: BufWriter<W>, }

Fields§

§buf: BufWriter<W>

Implementations§

Source§

impl FastOutput<StdoutLock<'static>>

Source

pub fn stdout() -> Self

Source§

impl<W> FastOutput<W>
where W: Write,

Source

pub fn new(writer: W) -> Self

Source

pub fn with_capacity(capacity: usize, writer: W) -> Self

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 392)
391    pub fn stdout() -> Self {
392        Self::with_capacity(1 << 12, stdout().lock())
393    }
More examples
Hide additional examples
crates/library_checker/src/sample/many_aplusb.rs (line 18)
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 fn flush(&mut self)

Source

fn write_digit4(&mut self, x: usize)

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 437)
434    pub fn u16(&mut self, x: u16) {
435        if x >= 10000 {
436            self.write_digit4_trimmed((x / 10000) as usize);
437            self.write_digit4((x % 10000) as usize);
438        } else {
439            self.write_digit4_trimmed(x as usize);
440        }
441    }
442
443    pub fn u32(&mut self, x: u32) {
444        if x >= 1_0000_0000 {
445            let b = x / 10000;
446            let a = b / 10000;
447            self.write_digit4_trimmed(a as usize);
448            self.write_digit4((b % 10000) as usize);
449            self.write_digit4((x % 10000) as usize);
450        } else if x >= 10000 {
451            self.write_digit4_trimmed((x / 10000) as usize);
452            self.write_digit4((x % 10000) as usize);
453        } else {
454            self.write_digit4_trimmed(x as usize);
455        }
456    }
457
458    pub fn u64(&mut self, x: u64) {
459        if x >= 1_0000_0000_0000_0000 {
460            let d = x / 10000;
461            let c = d / 10000;
462            let b = c / 10000;
463            let a = b / 10000;
464            self.write_digit4_trimmed(a as usize);
465            self.write_digit4((b % 10000) as usize);
466            self.write_digit4((c % 10000) as usize);
467            self.write_digit4((d % 10000) as usize);
468            self.write_digit4((x % 10000) as usize);
469        } else if x >= 1_0000_0000_0000 {
470            let c = x / 10000;
471            let b = c / 10000;
472            let a = b / 10000;
473            self.write_digit4_trimmed(a as usize);
474            self.write_digit4((b % 10000) as usize);
475            self.write_digit4((c % 10000) as usize);
476            self.write_digit4((x % 10000) as usize);
477        } else if x >= 1_0000_0000 {
478            let b = x / 10000;
479            let a = b / 10000;
480            self.write_digit4_trimmed(a as usize);
481            self.write_digit4((b % 10000) as usize);
482            self.write_digit4((x % 10000) as usize);
483        } else if x >= 10000 {
484            self.write_digit4_trimmed((x / 10000) as usize);
485            self.write_digit4((x % 10000) as usize);
486        } else {
487            self.write_digit4_trimmed(x as usize);
488        }
489    }
Source

fn write_digit4_trimmed(&mut self, x: usize)

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 436)
434    pub fn u16(&mut self, x: u16) {
435        if x >= 10000 {
436            self.write_digit4_trimmed((x / 10000) as usize);
437            self.write_digit4((x % 10000) as usize);
438        } else {
439            self.write_digit4_trimmed(x as usize);
440        }
441    }
442
443    pub fn u32(&mut self, x: u32) {
444        if x >= 1_0000_0000 {
445            let b = x / 10000;
446            let a = b / 10000;
447            self.write_digit4_trimmed(a as usize);
448            self.write_digit4((b % 10000) as usize);
449            self.write_digit4((x % 10000) as usize);
450        } else if x >= 10000 {
451            self.write_digit4_trimmed((x / 10000) as usize);
452            self.write_digit4((x % 10000) as usize);
453        } else {
454            self.write_digit4_trimmed(x as usize);
455        }
456    }
457
458    pub fn u64(&mut self, x: u64) {
459        if x >= 1_0000_0000_0000_0000 {
460            let d = x / 10000;
461            let c = d / 10000;
462            let b = c / 10000;
463            let a = b / 10000;
464            self.write_digit4_trimmed(a as usize);
465            self.write_digit4((b % 10000) as usize);
466            self.write_digit4((c % 10000) as usize);
467            self.write_digit4((d % 10000) as usize);
468            self.write_digit4((x % 10000) as usize);
469        } else if x >= 1_0000_0000_0000 {
470            let c = x / 10000;
471            let b = c / 10000;
472            let a = b / 10000;
473            self.write_digit4_trimmed(a as usize);
474            self.write_digit4((b % 10000) as usize);
475            self.write_digit4((c % 10000) as usize);
476            self.write_digit4((x % 10000) as usize);
477        } else if x >= 1_0000_0000 {
478            let b = x / 10000;
479            let a = b / 10000;
480            self.write_digit4_trimmed(a as usize);
481            self.write_digit4((b % 10000) as usize);
482            self.write_digit4((x % 10000) as usize);
483        } else if x >= 10000 {
484            self.write_digit4_trimmed((x / 10000) as usize);
485            self.write_digit4((x % 10000) as usize);
486        } else {
487            self.write_digit4_trimmed(x as usize);
488        }
489    }
Source

pub fn u8(&mut self, x: u8)

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 494)
491    pub fn i8(&mut self, x: i8) {
492        if x < 0 {
493            self.buf.write_all(b"-").unwrap();
494            self.u8(x.wrapping_neg() as u8);
495        } else {
496            self.u8(x as u8);
497        }
498    }
Source

pub fn u16(&mut self, x: u16)

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 503)
500    pub fn i16(&mut self, x: i16) {
501        if x < 0 {
502            self.buf.write_all(b"-").unwrap();
503            self.u16(x.wrapping_neg() as u16);
504        } else {
505            self.u16(x as u16);
506        }
507    }
Source

pub fn u32(&mut self, x: u32)

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 512)
509    pub fn i32(&mut self, x: i32) {
510        if x < 0 {
511            self.buf.write_all(b"-").unwrap();
512            self.u32(x.wrapping_neg() as u32);
513        } else {
514            self.u32(x as u32);
515        }
516    }
Source

pub fn u64(&mut self, x: u64)

Examples found in repository?
crates/competitive/src/tools/fastio.rs (line 521)
518    pub fn i64(&mut self, x: i64) {
519        if x < 0 {
520            self.buf.write_all(b"-").unwrap();
521            self.u64(x.wrapping_neg() as u64);
522        } else {
523            self.u64(x as u64);
524        }
525    }
More examples
Hide additional examples
crates/library_checker/src/sample/many_aplusb.rs (line 24)
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 fn i8(&mut self, x: i8)

Source

pub fn i16(&mut self, x: i16)

Source

pub fn i32(&mut self, x: i32)

Source

pub fn i64(&mut self, x: i64)

Source

pub fn byte(&mut self, b: u8)

Examples found in repository?
crates/library_checker/src/sample/many_aplusb.rs (line 25)
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 fn bytes(&mut self, s: &[u8])

Auto Trait Implementations§

§

impl<W> Freeze for FastOutput<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for FastOutput<W>
where W: RefUnwindSafe,

§

impl<W> Send for FastOutput<W>
where W: Send,

§

impl<W> Sync for FastOutput<W>
where W: Sync,

§

impl<W> Unpin for FastOutput<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for FastOutput<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for FastOutput<W>
where W: UnwindSafe,

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.