1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! 計数クエリ。

use std::fmt::Debug;
use std::ops::RangeBounds;

/// 計数クエリ。
pub trait Count<I> {
    fn count(&self, range: impl RangeBounds<usize>, value: I) -> usize;
}

/// 三方向計数クエリ。
pub trait Count3way<I> {
    fn count_3way(
        &self,
        range: impl RangeBounds<usize>,
        value: I,
    ) -> Count3wayResult;
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Count3wayResult {
    lt: usize,
    eq: usize,
    gt: usize,
}

impl Count3wayResult {
    pub fn new(lt: usize, eq: usize, gt: usize) -> Self { Self { lt, eq, gt } }
    pub fn lt(&self) -> usize { self.lt }
    pub fn eq(&self) -> usize { self.eq }
    pub fn gt(&self) -> usize { self.gt }
    pub fn le(&self) -> usize { self.lt + self.eq }
    pub fn ge(&self) -> usize { self.gt + self.eq }
    pub fn ne(&self) -> usize { self.lt + self.gt }
}