Documentation
¶
Overview ¶
Package fingerprint builds deterministic static summaries of Go function bodies and scores how similar two of them are. No network, no model, no cache: the same source always yields the same fingerprint and the same score.
Index ¶
Constants ¶
const ( LevelToken uint8 = iota // L0: token 3-gram windows LevelExpr // L1: call / binary-operator shapes LevelAction // L2: statement-with-salient-structure LevelMotif // L3: loop-body call summaries, statement bigrams )
Pattern levels: each level metabolizes the one below it — tokens feed expressions, expressions feed actions, actions feed motif chains. Higher levels carry more behavioral meaning; corpus IC (computed downstream) decides how much evidence any one pattern is worth.
Variables ¶
var FlowLabels = [flowKinds]string{
"if", "for", "range", "switch", "typeswitch",
"select", "return", "defer", "go", "funclit",
}
FlowLabels names the control-flow histogram slots, index-aligned with Fingerprint.Flow. The array length is tied to flowKinds so a new slot cannot be added without naming it.
Functions ¶
This section is empty.
Types ¶
type Breakdown ¶
type Breakdown struct {
AST float64 // Jaccard over AST 3-gram shingles
Flow float64 // cosine over the control-flow histogram
Signature float64 // Jaccard over normalized parameter and result types
SizeRatio float64 // min(Nodes)/max(Nodes); reported, not scored
Score float64 // weighted composite, 0.0-1.0
}
Breakdown is the per-component result of comparing two Fingerprints.
func Similarity ¶
func Similarity(a, b Fingerprint) Breakdown
Similarity scores two Fingerprints. It is symmetric, and returns the zero Breakdown when either side has no body.
type Fingerprint ¶
type Fingerprint struct {
Shingles []uint64 // sorted, deduped FNV-1a hashes of AST 3-grams
Flow []int // control-flow node histogram, length flowKinds
Types []string // sorted, deduped normalized param + result types
Nodes int // AST node count of the body (size / triviality guard)
Patterns []Pattern // multi-level structural pattern multiset, sorted by hash
}
Fingerprint is a deterministic static summary of one function body. The zero value means "no body" and never matches anything.
func Build ¶
func Build(fd *ast.FuncDecl) Fingerprint
Build summarises a function declaration. A nil declaration or a declaration without a body (external or forward-declared) yields the zero Fingerprint.
type Pattern ¶
type Pattern struct {
Hash uint64 // FNV-1a over "L<level>|" + canonical serialization
Level uint8
Count uint16 // multiset count within the function, saturating
Render string // canonical human-readable form; "" for levels 0-1
}
Pattern is one structural feature of a function body, at one level of the hierarchy. For levels 1-3 the Render string IS the canonical serialization the Hash is computed over, so hash and human-readable form cannot drift; level-0 windows hash their tokens directly and carry no render.