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
36
37
38
39
40
41
42
use std::{cmp::Ordering, marker::PhantomData};

use cfx_types::U256;
use treap_map::{Direction, TreapMapConfig};

use crate::packing_batch::PackingBatch;

use super::{
    key_mng::PackingPoolExtMap, transaction::PackingPoolTransaction,
    weight::PackingPoolWeight,
};

pub(crate) struct PackingPoolMap<TX: PackingPoolTransaction>(PhantomData<TX>);

impl<TX: PackingPoolTransaction> TreapMapConfig for PackingPoolMap<TX> {
    type ExtMap = PackingPoolExtMap<TX::Sender>;
    type SearchKey = TX::Sender;
    type SortKey = U256;
    type Value = PackingBatch<TX>;
    type Weight = PackingPoolWeight;

    #[inline]
    fn next_node_dir(
        me: (&Self::SortKey, &Self::SearchKey),
        other: (&Self::SortKey, &Self::SearchKey),
    ) -> Option<Direction> {
        match me.0.cmp(other.0) {
            Ordering::Greater => {
                return Some(Direction::Left);
            }
            Ordering::Equal => {}
            Ordering::Less => {
                return Some(Direction::Right);
            }
        }
        match me.1.cmp(other.1) {
            Ordering::Less => Some(Direction::Left),
            Ordering::Equal => None,
            Ordering::Greater => Some(Direction::Right),
        }
    }
}