suffixmap

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package suffixmap provides a domain-suffix lookup table that implements the ||domain^ anchor semantics from AdGuard and ABP filter lists.

A pattern "example.com" matches "example.com" itself and every subdomain such as "ads.example.com" or "www.ads.example.com", but not "notexample.com" (must be a label-boundary match). Lookups are performed by walking the DNS labels of the query from left to right, probing the map at each suffix. The maximum number of probes equals the number of labels in the query (typically 2–4 for real-world DNS names).

This package is intentionally decoupled from the automaton and filterlist packages so it can be tested and reasoned about in isolation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SuffixMap

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

SuffixMap stores domain patterns and matches queries against them using domain-suffix semantics.

The zero value is not usable; create instances via New.

func New

func New(entries map[string][]uint32) *SuffixMap

New creates a SuffixMap from the given entries.

Each entry maps a canonicalized domain pattern (lowercase, no wildcards) to its rule IDs. The entries map is owned by the SuffixMap after the call; callers must not modify it afterwards. Passing a nil or empty map creates a valid but empty SuffixMap that never matches.

func (*SuffixMap) Len

func (s *SuffixMap) Len() int

Len returns the number of distinct domain patterns stored.

func (*SuffixMap) Match

func (s *SuffixMap) Match(input string) (matched bool, ruleIDs []uint32)

Match checks whether input matches any stored pattern via domain-suffix lookup.

For a query like "sub.ads.example.com" the method probes the following suffixes in order:

"sub.ads.example.com"
"ads.example.com"
"example.com"
"com"

If any of these is present in the map, the query matches. When multiple suffixes match (e.g. both "ads.example.com" and "example.com" are stored), all corresponding rule IDs are returned.

The input parameter should be a lowercase DNS name. Match returns false and nil when no pattern matches.

Jump to

Keyboard shortcuts

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