Switch order of MappedInterner generic params

This commit is contained in:
Loïc Lecrenier 2023-03-20 09:37:11 +01:00
parent 9259cdb12e
commit c63c7377e6
8 changed files with 21 additions and 21 deletions

View File

@ -89,7 +89,7 @@ pub struct GraphBasedRankingRuleState<G: RankingRuleGraphTrait> {
/// Cache used to optimistically discard paths that resolve to no documents.
dead_ends_cache: DeadEndsCache<G::Condition>,
/// A structure giving the list of possible costs from each node to the end node
all_distances: MappedInterner<Vec<u16>, QueryNode>,
all_distances: MappedInterner<QueryNode, Vec<u16>>,
/// An index in the first element of `all_distances`, giving the cost of the next bucket
cur_distance_idx: usize,
}

View File

@ -96,7 +96,7 @@ impl<T> FixedSizeInterner<T> {
pub fn len(&self) -> u16 {
self.stable_store.len() as u16
}
pub fn map<U>(&self, map_f: impl Fn(&T) -> U) -> MappedInterner<U, T> {
pub fn map<U>(&self, map_f: impl Fn(&T) -> U) -> MappedInterner<T, U> {
MappedInterner {
stable_store: self.stable_store.iter().map(map_f).collect(),
_phantom: PhantomData,
@ -119,19 +119,19 @@ impl<T> FixedSizeInterner<T> {
///
/// Values in this interner are indexed with [`Interned<From>`].
#[derive(Clone)]
pub struct MappedInterner<T, From> {
pub struct MappedInterner<From, T> {
stable_store: Vec<T>,
_phantom: PhantomData<From>,
}
impl<T, From> MappedInterner<T, From> {
impl<From, T> MappedInterner<From, T> {
pub fn get(&self, interned: Interned<From>) -> &T {
&self.stable_store[interned.idx as usize]
}
pub fn get_mut(&mut self, interned: Interned<From>) -> &mut T {
&mut self.stable_store[interned.idx as usize]
}
pub fn map<U>(&self, map_f: impl Fn(&T) -> U) -> MappedInterner<U, From> {
pub fn map<U>(&self, map_f: impl Fn(&T) -> U) -> MappedInterner<From, U> {
MappedInterner {
stable_store: self.stable_store.iter().map(map_f).collect(),
_phantom: PhantomData,

View File

@ -44,7 +44,7 @@ pub enum SearchEvents {
paths: Vec<Vec<Interned<ProximityCondition>>>,
dead_ends_cache: DeadEndsCache<ProximityCondition>,
universe: RoaringBitmap,
distances: MappedInterner<Vec<u16>, QueryNode>,
distances: MappedInterner<QueryNode, Vec<u16>>,
cost: u16,
},
TypoState {
@ -52,7 +52,7 @@ pub enum SearchEvents {
paths: Vec<Vec<Interned<TypoCondition>>>,
dead_ends_cache: DeadEndsCache<TypoCondition>,
universe: RoaringBitmap,
distances: MappedInterner<Vec<u16>, QueryNode>,
distances: MappedInterner<QueryNode, Vec<u16>>,
cost: u16,
},
RankingRuleSkipBucket {
@ -170,7 +170,7 @@ impl SearchLogger<QueryGraph> for DetailedSearchLogger {
paths_map: &[Vec<Interned<ProximityCondition>>],
dead_ends_cache: &DeadEndsCache<ProximityCondition>,
universe: &RoaringBitmap,
distances: &MappedInterner<Vec<u16>, QueryNode>,
distances: &MappedInterner<QueryNode, Vec<u16>>,
cost: u16,
) {
self.events.push(SearchEvents::ProximityState {
@ -189,7 +189,7 @@ impl SearchLogger<QueryGraph> for DetailedSearchLogger {
paths_map: &[Vec<Interned<TypoCondition>>],
dead_ends_cache: &DeadEndsCache<TypoCondition>,
universe: &RoaringBitmap,
distances: &MappedInterner<Vec<u16>, QueryNode>,
distances: &MappedInterner<QueryNode, Vec<u16>>,
cost: u16,
) {
self.events.push(SearchEvents::TypoState {
@ -525,7 +525,7 @@ shape: class"
graph: &RankingRuleGraph<R>,
paths: &[Vec<Interned<R::Condition>>],
_dead_ends_cache: &DeadEndsCache<R::Condition>,
distances: MappedInterner<Vec<u16>, QueryNode>,
distances: MappedInterner<QueryNode, Vec<u16>>,
file: &mut File,
) {
writeln!(file, "direction: right").unwrap();

View File

@ -67,7 +67,7 @@ pub trait SearchLogger<Q: RankingRuleQueryTrait> {
paths: &[Vec<Interned<ProximityCondition>>],
dead_ends_cache: &DeadEndsCache<ProximityCondition>,
universe: &RoaringBitmap,
distances: &MappedInterner<Vec<u16>, QueryNode>,
distances: &MappedInterner<QueryNode, Vec<u16>>,
cost: u16,
);
@ -78,7 +78,7 @@ pub trait SearchLogger<Q: RankingRuleQueryTrait> {
paths: &[Vec<Interned<TypoCondition>>],
dead_ends_cache: &DeadEndsCache<TypoCondition>,
universe: &RoaringBitmap,
distances: &MappedInterner<Vec<u16>, QueryNode>,
distances: &MappedInterner<QueryNode, Vec<u16>>,
cost: u16,
);
}
@ -138,7 +138,7 @@ impl<Q: RankingRuleQueryTrait> SearchLogger<Q> for DefaultSearchLogger {
_paths_map: &[Vec<Interned<ProximityCondition>>],
_dead_ends_cache: &DeadEndsCache<ProximityCondition>,
_universe: &RoaringBitmap,
_distances: &MappedInterner<Vec<u16>, QueryNode>,
_distances: &MappedInterner<QueryNode, Vec<u16>>,
_cost: u16,
) {
}
@ -149,7 +149,7 @@ impl<Q: RankingRuleQueryTrait> SearchLogger<Q> for DefaultSearchLogger {
_paths: &[Vec<Interned<TypoCondition>>],
_dead_ends_cache: &DeadEndsCache<TypoCondition>,
_universe: &RoaringBitmap,
_distances: &MappedInterner<Vec<u16>, QueryNode>,
_distances: &MappedInterner<QueryNode, Vec<u16>>,
_cost: u16,
) {
}

View File

@ -14,7 +14,7 @@ impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
&mut self,
from: Interned<QueryNode>,
cost: u16,
all_distances: &MappedInterner<Vec<u16>, QueryNode>,
all_distances: &MappedInterner<QueryNode, Vec<u16>>,
dead_ends_cache: &mut DeadEndsCache<G::Condition>,
mut visit: impl FnMut(
&[Interned<G::Condition>],
@ -38,7 +38,7 @@ impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
&mut self,
from: Interned<QueryNode>,
cost: u16,
all_distances: &MappedInterner<Vec<u16>, QueryNode>,
all_distances: &MappedInterner<QueryNode, Vec<u16>>,
dead_ends_cache: &mut DeadEndsCache<G::Condition>,
visit: &mut impl FnMut(
&[Interned<G::Condition>],
@ -137,7 +137,7 @@ impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
Ok(any_valid)
}
pub fn initialize_distances_with_necessary_edges(&self) -> MappedInterner<Vec<u16>, QueryNode> {
pub fn initialize_distances_with_necessary_edges(&self) -> MappedInterner<QueryNode, Vec<u16>> {
let mut distances_to_end = self.query_graph.nodes.map(|_| vec![]);
let mut enqueued = SmallBitmap::new(self.query_graph.nodes.len());

View File

@ -114,7 +114,7 @@ pub trait RankingRuleGraphTrait: Sized {
paths: &[Vec<Interned<Self::Condition>>],
dead_ends_cache: &DeadEndsCache<Self::Condition>,
universe: &RoaringBitmap,
distances: &MappedInterner<Vec<u16>, QueryNode>,
distances: &MappedInterner<QueryNode, Vec<u16>>,
cost: u16,
logger: &mut dyn SearchLogger<QueryGraph>,
);
@ -127,7 +127,7 @@ pub trait RankingRuleGraphTrait: Sized {
pub struct RankingRuleGraph<G: RankingRuleGraphTrait> {
pub query_graph: QueryGraph,
pub edges_store: FixedSizeInterner<Option<Edge<G::Condition>>>,
pub edges_of_node: MappedInterner<SmallBitmap<Option<Edge<G::Condition>>>, QueryNode>,
pub edges_of_node: MappedInterner<QueryNode, SmallBitmap<Option<Edge<G::Condition>>>>,
pub conditions_interner: FixedSizeInterner<G::Condition>,
}
impl<G: RankingRuleGraphTrait> Clone for RankingRuleGraph<G> {

View File

@ -67,7 +67,7 @@ impl RankingRuleGraphTrait for ProximityGraph {
paths: &[Vec<Interned<ProximityCondition>>],
dead_ends_cache: &DeadEndsCache<Self::Condition>,
universe: &RoaringBitmap,
distances: &MappedInterner<Vec<u16>, QueryNode>,
distances: &MappedInterner<QueryNode, Vec<u16>>,
cost: u16,
logger: &mut dyn SearchLogger<QueryGraph>,
) {

View File

@ -138,7 +138,7 @@ impl RankingRuleGraphTrait for TypoGraph {
paths: &[Vec<Interned<TypoCondition>>],
dead_ends_cache: &DeadEndsCache<TypoCondition>,
universe: &RoaringBitmap,
distances: &MappedInterner<Vec<u16>, QueryNode>,
distances: &MappedInterner<QueryNode, Vec<u16>>,
cost: u16,
logger: &mut dyn SearchLogger<QueryGraph>,
) {