Skip to main content

RuleIndex

Struct RuleIndex 

Source
pub struct RuleIndex {
    by_id: BTreeMap<String, Vec<usize>>,
    by_class: BTreeMap<String, Vec<usize>>,
    by_tag: BTreeMap<String, Vec<usize>>,
    universal: Vec<usize>,
    rule_count: usize,
    state_masks: Vec<u8>,
}
Expand description

スタイルシート内のルールを右端キーで振り分けた索引。 保持するのは元の rules スライスに対する添字のみで、ルール本体は複製しない。

Fields§

§by_id: BTreeMap<String, Vec<usize>>§by_class: BTreeMap<String, Vec<usize>>§by_tag: BTreeMap<String, Vec<usize>>§universal: Vec<usize>§rule_count: usize§state_masks: Vec<u8>

ルールごとの動的疑似クラス使用ビット(bit0=hover, bit1=focus, bit2=active)。

「そのルールが :hover を使うか」はノードに依存しない。 以前はカスケードがノードごとに候補ルール全部へ rule_uses_state を 呼んでおり、同じ答えを N×C 回計算し直していた。 索引を作るのと同じ 1 回の走査で求めておく。

Implementations§

Source§

impl RuleIndex

Source

pub fn states_of(&self, cands: &[usize]) -> Option<u8>

与えられた候補ルール群が使う動的疑似クラスのビットを OR して返す。

範囲外の添字が混ざっていたら None。呼び出し側は 「全状態を計算する」へフォールバックする(取りこぼしより遅い方を選ぶ)。

計算量: O(C)

【2026-08-05】グローバルの ACTIVE を介さずに問い合わせられるよう、 active_states_of から本体をこちらへ移した。 試験がグローバル状態に依存していたため、並列実行される他の試験が clear_active() した瞬間に None が返って落ちていた (実測: 8 回に 1 回程度。spec/logging_policy.md T-1 の再発)。 索引そのものの性質は索引だけで確かめられる。

Source

pub fn build(rules: &[Rule]) -> Self

ルール列から索引を構築する。

1 ルールが複数セレクタ(a, b, c)を持つ場合、いずれかのセレクタが マッチすればそのルールは適用対象なので、全セレクタのキーへ登録する。

Source

pub fn rule_count(&self) -> usize

索引が対象としているルール総数。

Source

pub fn universal_count(&self) -> usize

常時照合が必要な(絞り込めなかった)ルール数。 これが総数に近いほど索引の効果は薄い。

Source

pub fn candidates( &self, tag: &str, id: Option<&str>, classes: &[String], ) -> Result<Vec<usize>, IndexError>

ある要素について照合すべきルールの添字を昇順・重複なしで返す。 昇順なのはカスケードの後勝ち規則(同特異度なら後のルールが勝つ)を 元の宣言順のまま保つため。

引数が不正(タグ名が空)なときは黙って戻らず、エラーログを出して Err を返す。 呼び出し側は「全ルールを照合する」従来動作へフォールバックすること (絞り込みを誤って描画が欠けるより、遅くても正しい方を選ぶ)。

Trait Implementations§

Source§

impl Debug for RuleIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RuleIndex

Source§

fn default() -> RuleIndex

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

Auto Trait Implementations§

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, 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.