diff --git a/dex/src/critbit.rs b/dex/src/critbit.rs index 5c3fcfa..e04052f 100644 --- a/dex/src/critbit.rs +++ b/dex/src/critbit.rs @@ -28,12 +28,12 @@ enum NodeTag { #[derive(Copy, Clone)] #[repr(packed)] #[allow(dead_code)] -pub struct InnerNode { - pub tag: u32, - pub prefix_len: u32, - pub key: u128, - pub children: [u32; 2], - pub _padding: [u64; 5], +struct InnerNode { + tag: u32, + prefix_len: u32, + key: u128, + children: [u32; 2], + _padding: [u64; 5], } unsafe impl Zeroable for InnerNode {} unsafe impl Pod for InnerNode {} @@ -139,6 +139,7 @@ const fn _const_max(a: usize, b: usize) -> usize { let gt = (a > b) as usize; gt * a + (1 - gt) * b } + const _INNER_NODE_SIZE: usize = size_of::(); const _LEAF_NODE_SIZE: usize = size_of::(); const _FREE_NODE_SIZE: usize = size_of::(); @@ -167,12 +168,12 @@ pub struct AnyNode { unsafe impl Zeroable for AnyNode {} unsafe impl Pod for AnyNode {} -pub enum NodeRef<'a> { +enum NodeRef<'a> { Inner(&'a InnerNode), Leaf(&'a LeafNode), } -pub enum NodeRefMut<'a> { +enum NodeRefMut<'a> { Inner(&'a mut InnerNode), Leaf(&'a mut LeafNode), } @@ -200,7 +201,7 @@ impl AnyNode { } } - pub fn case(&self) -> Option { + fn case(&self) -> Option { match NodeTag::try_from(self.tag) { Ok(NodeTag::InnerNode) => Some(NodeRef::Inner(cast_ref(self))), Ok(NodeTag::LeafNode) => Some(NodeRef::Leaf(cast_ref(self))), @@ -251,13 +252,13 @@ const_assert_eq!(_NODE_ALIGN, align_of::()); #[derive(Copy, Clone)] #[repr(packed)] -pub struct SlabHeader { - pub bump_index: u64, - pub free_list_len: u64, - pub free_list_head: u32, +struct SlabHeader { + bump_index: u64, + free_list_len: u64, + free_list_head: u32, - pub root_node: u32, - pub leaf_count: u64, + root_node: u32, + leaf_count: u64, } unsafe impl Zeroable for SlabHeader {} unsafe impl Pod for SlabHeader {} @@ -346,19 +347,19 @@ impl Slab { (header, nodes) } - pub fn header(&self) -> &SlabHeader { + fn header(&self) -> &SlabHeader { self.parts().0 } - pub fn header_mut(&mut self) -> &mut SlabHeader { + fn header_mut(&mut self) -> &mut SlabHeader { self.parts_mut().0 } - pub fn nodes(&self) -> &[AnyNode] { + fn nodes(&self) -> &[AnyNode] { self.parts().1 } - pub fn nodes_mut(&mut self) -> &mut [AnyNode] { + fn nodes_mut(&mut self) -> &mut [AnyNode] { self.parts_mut().1 } } @@ -491,7 +492,7 @@ pub enum SlabTreeError { } impl Slab { - pub fn root(&self) -> Option { + fn root(&self) -> Option { if self.header().leaf_count == 0 { return None; } diff --git a/dex/src/matching.rs b/dex/src/matching.rs index b90574a..ae6b6e2 100644 --- a/dex/src/matching.rs +++ b/dex/src/matching.rs @@ -45,7 +45,7 @@ pub enum OrderType { PostOnly = 2, } -pub fn extract_price_from_order_id(order_id: u128) -> u64 { +fn extract_price_from_order_id(order_id: u128) -> u64 { (order_id >> 64) as u64 } @@ -57,14 +57,14 @@ pub struct OrderBookState<'a> { } impl<'ob> OrderBookState<'ob> { - pub fn orders_mut(&mut self, side: Side) -> &mut Slab { + fn orders_mut(&mut self, side: Side) -> &mut Slab { match side { Side::Bid => self.bids, Side::Ask => self.asks, } } - pub fn find_bbo(&self, side: Side) -> Option { + fn find_bbo(&self, side: Side) -> Option { match side { Side::Bid => self.bids.find_max(), Side::Ask => self.asks.find_min(), @@ -143,7 +143,7 @@ impl<'ob> OrderBookState<'ob> { } } -pub struct RequestProceeds { +pub(crate) struct RequestProceeds { pub coin_unlocked: u64, pub native_pc_unlocked: u64, @@ -182,7 +182,7 @@ impl RequestProceeds { impl_incr_method!(debit_native_pc, native_pc_debit); } -pub struct NewOrderParams { +pub(crate) struct NewOrderParams { side: Side, order_type: OrderType, order_id: u128, @@ -195,13 +195,13 @@ pub struct NewOrderParams { self_trade_behavior: SelfTradeBehavior, } -pub struct OrderRemaining { +struct OrderRemaining { coin_qty_remaining: NonZeroU64, native_pc_qty_remaining: Option, } impl<'ob> OrderBookState<'ob> { - pub fn new_order( + fn new_order( &mut self, params: NewOrderParams, diff --git a/dex/src/state.rs b/dex/src/state.rs index cef8e53..1062d2e 100644 --- a/dex/src/state.rs +++ b/dex/src/state.rs @@ -258,7 +258,7 @@ impl MarketState { Ok(open_orders) } - pub fn load_bids_mut<'a>(&self, bids: &'a AccountInfo) -> DexResult> { + fn load_bids_mut<'a>(&self, bids: &'a AccountInfo) -> DexResult> { check_assert_eq!(&bids.key.to_aligned_bytes(), &identity(self.bids)) .map_err(|_| DexErrorCode::WrongBidsAccount)?; let (header, buf) = strip_header::(bids, false)?; @@ -267,7 +267,7 @@ impl MarketState { Ok(RefMut::map(buf, Slab::new)) } - pub fn load_asks_mut<'a>(&self, asks: &'a AccountInfo) -> DexResult> { + fn load_asks_mut<'a>(&self, asks: &'a AccountInfo) -> DexResult> { check_assert_eq!(&asks.key.to_aligned_bytes(), &identity(self.asks)) .map_err(|_| DexErrorCode::WrongAsksAccount)?; let (header, buf) = strip_header::(asks, false)?;