Skip to content

Commit

Permalink
[score] rename PositionsRef to Positions
Browse files Browse the repository at this point in the history
  • Loading branch information
aslpavel committed Nov 13, 2024
1 parent 080920c commit 98b3ac3
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 91 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.package]
authors = ["Pavel Aslanov <[email protected]>"]
edition = "2021"
version = "0.24.2"
version = "0.25.0"
repository = "https://github.com/aslpavel/sweep-rs"

[workspace.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions chronicler-cli/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Haystack for HistoryEntry {
fn view(
&self,
ctx: &Self::Context,
positions: sweep::PositionsRef<&[u8]>,
positions: sweep::Positions<&[u8]>,
theme: &Theme,
) -> Self::View {
let cmd = HaystackDefaultView::new(ctx, self, positions, theme);
Expand Down Expand Up @@ -97,7 +97,7 @@ impl Haystack for HistoryEntry {
fn preview(
&self,
_ctx: &Self::Context,
_positions: sweep::PositionsRef<&[u8]>,
_positions: sweep::Positions<&[u8]>,
theme: &Theme,
) -> Option<Self::Preview> {
let mut text = Text::new();
Expand Down
8 changes: 4 additions & 4 deletions chronicler-cli/src/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use sweep::{
view::{Either, View},
Glyph,
},
Haystack, PositionsRef, Sweep, SweepEvent, SweepOptions,
Haystack, Positions, Sweep, SweepEvent, SweepOptions,
};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -104,7 +104,7 @@ impl Haystack for NavigatorItem {
fn view(
&self,
ctx: &Self::Context,
positions: PositionsRef<&[u8]>,
positions: Positions<&[u8]>,
theme: &sweep::Theme,
) -> Self::View {
use NavigatorItem::*;
Expand All @@ -117,7 +117,7 @@ impl Haystack for NavigatorItem {
fn preview(
&self,
ctx: &Self::Context,
positions: PositionsRef<&[u8]>,
positions: Positions<&[u8]>,
theme: &sweep::Theme,
) -> Option<Self::Preview> {
use NavigatorItem::*;
Expand All @@ -130,7 +130,7 @@ impl Haystack for NavigatorItem {
fn preview_large(
&self,
ctx: &Self::Context,
positions: PositionsRef<&[u8]>,
positions: Positions<&[u8]>,
theme: &sweep::Theme,
) -> Option<Self::PreviewLarge> {
use NavigatorItem::*;
Expand Down
4 changes: 2 additions & 2 deletions chronicler-cli/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Haystack for PathItem {
fn view(
&self,
ctx: &Self::Context,
positions: sweep::PositionsRef<&[u8]>,
positions: sweep::Positions<&[u8]>,
theme: &sweep::Theme,
) -> Self::View {
let path = HaystackDefaultView::new(ctx, self, positions, theme);
Expand All @@ -154,7 +154,7 @@ impl Haystack for PathItem {
fn preview(
&self,
ctx: &Self::Context,
_positions: sweep::PositionsRef<&[u8]>,
_positions: sweep::Positions<&[u8]>,
_theme: &sweep::Theme,
) -> Option<Self::Preview> {
let metadata = self.metadata.as_ref()?;
Expand Down
4 changes: 2 additions & 2 deletions sweep-lib/benches/scorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ pub fn scorer_benchmark(c: &mut Criterion) {
group.throughput(Throughput::Elements(1_u64));

let mut score = Score::MIN;
let mut positions = Positions::new(CANDIDATE.len());
let mut positions = Positions::new_owned(CANDIDATE.len());
group.bench_function("fuzzy", |b| {
b.iter(|| fuzzy.score_ref(haystack.as_slice(), &mut score, positions.as_mut()))
});

let mut score = Score::MIN;
let mut positions = Positions::new(CANDIDATE.len());
let mut positions = Positions::new_owned(CANDIDATE.len());
group.bench_function("substr", |b| {
b.iter(|| substr.score_ref(haystack.as_slice(), &mut score, positions.as_mut()))
});
Expand Down
17 changes: 6 additions & 11 deletions sweep-lib/src/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::{
common::{json_from_slice_seed, LockExt, VecDeserializeSeed},
rpc::{RpcParams, RpcPeer},
widgets::ProcessOutput,
Haystack, HaystackBasicPreview, PositionsRef, Process, ProcessCommandArg,
ProcessCommandBuilder, Theme,
Haystack, HaystackBasicPreview, Positions, Process, ProcessCommandArg, ProcessCommandBuilder,
Theme,
};
use anyhow::Error;
use futures::Stream;
Expand Down Expand Up @@ -381,12 +381,7 @@ impl Haystack for Candidate {
self.inner.hotkey.clone()
}

fn view(
&self,
ctx: &Self::Context,
positions: PositionsRef<&[u8]>,
theme: &Theme,
) -> Self::View {
fn view(&self, ctx: &Self::Context, positions: Positions<&[u8]>, theme: &Theme) -> Self::View {
// left side
let mut positions_offset = 0;
let left = fields_view(
Expand Down Expand Up @@ -434,7 +429,7 @@ impl Haystack for Candidate {
fn preview(
&self,
ctx: &Self::Context,
positions: PositionsRef<&[u8]>,
positions: Positions<&[u8]>,
theme: &Theme,
) -> Option<Self::Preview> {
if self.inner.preview.is_empty() {
Expand All @@ -460,7 +455,7 @@ impl Haystack for Candidate {
fn preview_large(
&self,
ctx: &Self::Context,
_positions: PositionsRef<&[u8]>,
_positions: Positions<&[u8]>,
_theme: &Theme,
) -> Option<Self::PreviewLarge> {
ctx.preview_get(self)
Expand All @@ -481,7 +476,7 @@ type FieldsView = either::Either<Flex<'static>, Text>;
#[allow(clippy::too_many_arguments)]
pub fn fields_view(
fields: &[Field<'_>],
positions: PositionsRef<&[u8]>,
positions: Positions<&[u8]>,
positions_offset: &mut usize,
candidate_context: &CandidateContext,
face_default: Face,
Expand Down
29 changes: 7 additions & 22 deletions sweep-lib/src/haystack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use surf_n_term::{
CellWrite, KeyChord, Position, TerminalSurface,
};

use crate::{PositionsRef, Theme};
use crate::{Positions, Theme};

/// Haystack
///
Expand All @@ -31,18 +31,13 @@ pub trait Haystack: std::fmt::Debug + Clone + Send + Sync + 'static {
}

/// Return a view that renders haystack item in a list
fn view(
&self,
ctx: &Self::Context,
positions: PositionsRef<&[u8]>,
theme: &Theme,
) -> Self::View;
fn view(&self, ctx: &Self::Context, positions: Positions<&[u8]>, theme: &Theme) -> Self::View;

/// Side preview of the current item
fn preview(
&self,
_ctx: &Self::Context,
_positions: PositionsRef<&[u8]>,
_positions: Positions<&[u8]>,
_theme: &Theme,
) -> Option<Self::Preview> {
None
Expand All @@ -52,7 +47,7 @@ pub trait Haystack: std::fmt::Debug + Clone + Send + Sync + 'static {
fn preview_large(
&self,
_ctx: &Self::Context,
_positions: PositionsRef<&[u8]>,
_positions: Positions<&[u8]>,
_theme: &Theme,
) -> Option<Self::PreviewLarge> {
None
Expand Down Expand Up @@ -135,7 +130,7 @@ impl HaystackDefaultView {
pub fn new<H: Haystack>(
ctx: &H::Context,
haystack: &H,
positions: PositionsRef<&[u8]>,
positions: Positions<&[u8]>,
theme: &Theme,
) -> Self {
let mut text = Text::new();
Expand Down Expand Up @@ -222,12 +217,7 @@ impl Haystack for String {
type Preview = ();
type PreviewLarge = ();

fn view(
&self,
ctx: &Self::Context,
positions: PositionsRef<&[u8]>,
theme: &Theme,
) -> Self::View {
fn view(&self, ctx: &Self::Context, positions: Positions<&[u8]>, theme: &Theme) -> Self::View {
HaystackDefaultView::new(ctx, self, positions, theme)
}

Expand All @@ -245,12 +235,7 @@ impl Haystack for &'static str {
type Preview = ();
type PreviewLarge = ();

fn view(
&self,
ctx: &Self::Context,
positions: PositionsRef<&[u8]>,
theme: &Theme,
) -> Self::View {
fn view(&self, ctx: &Self::Context, positions: Positions<&[u8]>, theme: &Theme) -> Self::View {
HaystackDefaultView::new(ctx, self, positions, theme)
}

Expand Down
4 changes: 2 additions & 2 deletions sweep-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub use haystack::{Haystack, HaystackBasicPreview, HaystackDefaultView, Haystack

mod scorer;
pub use scorer::{
FuzzyScorer, KMPPattern, Positions, PositionsRef, Score, ScoreArray, ScoreItem, ScoreIter,
Scorer, SubstrScorer,
FuzzyScorer, KMPPattern, Positions, Score, ScoreArray, ScoreItem, ScoreIter, Scorer,
SubstrScorer,
};

mod rank;
Expand Down
Loading

0 comments on commit 98b3ac3

Please sign in to comment.