lookup

package
v0.23.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package lookup implements index structures that we use to improve matching speed in the engines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DomainIndex added in v0.23.0

type DomainIndex struct {
	// contains filtered or unexported fields
}

DomainIndex is an index that uses domains from the $domain modifier to speed up the rules search. Only the rules with $domain modifier are eligible for this index.

func NewDomainIndex added in v0.23.0

func NewDomainIndex() (idx *DomainIndex)

NewDomainIndex creates a new instance of the DomainIndex.

func (*DomainIndex) Add added in v0.23.0

func (idx *DomainIndex) Add(r *rules.NetworkRule, id filterlist.StorageID) (ok bool)

Add adds r to the index if r is eligible. r must not be nil.

func (*DomainIndex) AppendBinary added in v0.23.0

func (idx *DomainIndex) AppendBinary(orig []byte) (res []byte, err error)

AppendBinary implements the encoding.BinaryAppender interface for *DomainIndex. The only guarantee with regards to the backwards compatibility is the following: when the result of AppendBinary is fed into DomainIndex.UnmarshalBinary of an empty or reset *DomainIndex, the results of DomainIndex.AppendMatching of this new table are the same as those of the original one; all of this being within one version of the module.

func (*DomainIndex) AppendMatching added in v0.23.0

func (idx *DomainIndex) AppendMatching(
	orig []filterlist.StorageID,
	r *rules.Request,
) (res []filterlist.StorageID)

AppendMatching appends the IDs of the rules matching r to orig and returns it. r must not be nil.

func (*DomainIndex) Reset added in v0.23.0

func (idx *DomainIndex) Reset()

Reset prepares idx for reuse.

func (*DomainIndex) UnmarshalBinary added in v0.23.0

func (idx *DomainIndex) UnmarshalBinary(b []byte) (err error)

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface for *DomainIndex. b should be data that has been encoded by DomainIndex.AppendBinary.

func (*DomainIndex) UnmarshalBinaryRest added in v0.23.0

func (idx *DomainIndex) UnmarshalBinaryRest(b []byte) (rest []byte, err error)

UnmarshalBinaryRest implements the ufencoding.BinaryUnmarshalerRest interface for *DomainIndex. b should be data that has been encoded by DomainIndex.AppendBinary.

type ShortcutIndex added in v0.23.0

type ShortcutIndex struct {
	// contains filtered or unexported fields
}

ShortcutIndex is an index that relies on the rule shortcuts to quickly find matching rules:

  1. From the rule, it extracts the longest substring without special characters; this string is the [shortcut].
  2. It uses a sliding window of [shortcutLength] and puts it into its map.
  3. When it matches a request, it takes all substrings of length [shortcutsLength] from it and checks if there are any rules in the map.

NOTE: only the rules with a shortcut are eligible for this index.

TODO(a.garipov): Consider all non-regexp rules as having shortcuts?

func NewShortcutIndex added in v0.23.0

func NewShortcutIndex() (idx *ShortcutIndex)

NewShortcutIndex creates a new instance of *ShortcutIndex.

func (*ShortcutIndex) Add added in v0.23.0

func (idx *ShortcutIndex) Add(r *rules.NetworkRule, id filterlist.StorageID) (ok bool)

Add adds r to the index if r is eligible. r must not be nil.

func (*ShortcutIndex) AppendBinary added in v0.23.0

func (idx *ShortcutIndex) AppendBinary(orig []byte) (res []byte, err error)

AppendBinary implements the encoding.BinaryAppender interface for *ShortcutIndex. The only guarantee with regards to the backwards compatibility is the following: when the result of AppendBinary is fed into ShortcutIndex.UnmarshalBinary of an empty or reset *ShortcutIndex, the results of ShortcutIndex.AppendMatching of this new table are the same as those of the original one; all of this being within one version of the module.

func (*ShortcutIndex) AppendMatching added in v0.23.0

func (idx *ShortcutIndex) AppendMatching(
	orig []filterlist.StorageID,
	r *rules.Request,
) (res []filterlist.StorageID)

AppendMatching appends the IDs of the rules matching r to orig and returns it. r must not be nil.

func (*ShortcutIndex) Reset added in v0.23.0

func (idx *ShortcutIndex) Reset()

Reset prepares idx for reuse.

func (*ShortcutIndex) UnmarshalBinary added in v0.23.0

func (idx *ShortcutIndex) UnmarshalBinary(b []byte) (err error)

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface for *ShortcutIndex. b should be data that has been encoded by ShortcutIndex.AppendBinary.

func (*ShortcutIndex) UnmarshalBinaryRest added in v0.23.0

func (idx *ShortcutIndex) UnmarshalBinaryRest(b []byte) (rest []byte, err error)

UnmarshalBinaryRest implements the ufencoding.BinaryUnmarshalerRest interface for *ShortcutIndex. b should be data that has been encoded by ShortcutIndex.AppendBinary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL