Skip to main content

BestFirst

Struct BestFirst 

Source
pub struct BestFirst<S = ()> { /* private fields */ }
Expand description

相关性优先的待爬队列。容量由调用方按“还能再抓几页“给出,满了以后新链接只有比队里最差的 好才挤进来:队列长度不超过 limit,和广度优先一样内存有界。 每项带一个打分依据 S(super::LinkSignal),词权重变了以后按它重新打分(Self::rescore)。

Implementations§

Source§

impl<S> BestFirst<S>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn contains(&self, hash: u64) -> bool

Source

pub fn offer( &mut self, hash: u64, url: Url, depth: usize, score: f32, signal: S, room: usize, ) -> Offer

放入一个链接。room 是队列现在最多能有多少项(limit 减去已经调度的页数)。 已经在队里的,分数更高时换成这次的分数和打分依据。

Source

pub fn rescore(&mut self, score: impl Fn(&S) -> f32)

按打分依据重算每一项的分数,同分的还按发现顺序。

Source

pub fn pop_diverse( &mut self, scheduled: &HashMap<String, usize>, cap: usize, proven: impl Fn(&str) -> bool, ) -> Option<(Url, usize, f32)>

按簇分散地出队:分数最高的链接所在的簇已经调度了 cap 页时,改出别的簇里分数不低于 最高分一半的最好链接;没有这样的链接就还是出最高分的。scheduled 是每个簇已调度的页数, proven 说一个簇是不是已经证明了产出好:这样的簇不受 cap 限制,而且队首在没证明过的簇 里时,证明过的簇里分数不低于最高分一半的链接先出。

Source

pub fn peek_score(&self) -> Option<f32>

队首(分数最高)的分数。

Source

pub fn take_signal(&mut self) -> Option<S>

最近一次出队的项的打分依据(取走)。

Trait Implementations§

Source§

impl<S> Default for BestFirst<S>

Source§

fn default() -> BestFirst<S>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for BestFirst<S>
where BTreeMap<(u32, Reverse<u64>), Entry<S>>: Freeze, Option<S>: Freeze,

§

impl<S> RefUnwindSafe for BestFirst<S>

§

impl<S> Send for BestFirst<S>
where BTreeMap<(u32, Reverse<u64>), Entry<S>>: Send, Option<S>: Send,

§

impl<S> Sync for BestFirst<S>
where BTreeMap<(u32, Reverse<u64>), Entry<S>>: Sync, Option<S>: Sync,

§

impl<S> Unpin for BestFirst<S>
where BTreeMap<(u32, Reverse<u64>), Entry<S>>: Unpin, Option<S>: Unpin,

§

impl<S> UnsafeUnpin for BestFirst<S>
where BTreeMap<(u32, Reverse<u64>), Entry<S>>: UnsafeUnpin, Option<S>: UnsafeUnpin,

§

impl<S> UnwindSafe for BestFirst<S>
where BTreeMap<(u32, Reverse<u64>), Entry<S>>: UnwindSafe, Option<S>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more