From 95871dcc45f6531b4c692ff892aad56bdd95e16f Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 10 Feb 2023 12:14:36 +0100 Subject: pkg/subsystem: restructure the package Remove the entity and match subpackages. Regenerate the linux.go file. --- pkg/subsystem/linux/coincidence.go | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 pkg/subsystem/linux/coincidence.go (limited to 'pkg/subsystem/linux/coincidence.go') diff --git a/pkg/subsystem/linux/coincidence.go b/pkg/subsystem/linux/coincidence.go new file mode 100644 index 000000000..86ee0794f --- /dev/null +++ b/pkg/subsystem/linux/coincidence.go @@ -0,0 +1,55 @@ +// Copyright 2023 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package linux + +import "github.com/google/syzkaller/pkg/subsystem" + +// CoincidenceMatrix represents a matrix that, for every pair of subsystems +// A and B, stores the number of times A and B have coincided in the input data. +// So far we only need it for subsystem.Subsystem, so its interface is tailored to it. +type CoincidenceMatrix struct { + matrix map[*subsystem.Subsystem]map[*subsystem.Subsystem]int +} + +func MakeCoincidenceMatrix() *CoincidenceMatrix { + return &CoincidenceMatrix{ + matrix: make(map[*subsystem.Subsystem]map[*subsystem.Subsystem]int), + } +} + +func (cm *CoincidenceMatrix) Record(items ...*subsystem.Subsystem) { + for i := 0; i < len(items); i++ { + for j := 0; j < len(items); j++ { + cm.inc(items[i], items[j]) + } + } +} + +func (cm *CoincidenceMatrix) Count(a *subsystem.Subsystem) int { + return cm.Get(a, a) +} + +func (cm *CoincidenceMatrix) Get(a, b *subsystem.Subsystem) int { + return cm.matrix[a][b] +} + +func (cm *CoincidenceMatrix) NonEmptyPairs(cb func(a, b *subsystem.Subsystem, val int)) { + for a, sub := range cm.matrix { + for b, val := range sub { + if a == b { + continue + } + cb(a, b, val) + } + } +} + +func (cm *CoincidenceMatrix) inc(a, b *subsystem.Subsystem) { + subMatrix, ok := cm.matrix[a] + if !ok { + subMatrix = make(map[*subsystem.Subsystem]int) + cm.matrix[a] = subMatrix + } + subMatrix[b]++ +} -- cgit mrf-deployment