From bbf862351343d56d0b593de1d620a128712a767e Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 7 Jul 2018 18:06:31 +0100 Subject: [PATCH] Rename diff to diffsect --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 95ce63e..2db8469 100644 --- a/main.go +++ b/main.go @@ -40,20 +40,22 @@ func versionString() string { return buffer.String() } -func diff(a, b, c *HeapDump) *[]string { +// diffsect removes all items in `a` from `b`, then removes all items from `b` +// which are not in `c`. Effectively: intersect(difference(b, a), c) +func diffsect(a, b, c *[]string) *[]string { result := []string{} mapA := map[string]bool{} mapC := map[string]bool{} - for _, x := range a.Index { + for _, x := range *a { mapA[x] = true } - for _, x := range c.Index { + for _, x := range *c { mapC[x] = true } - for _, x := range b.Index { + for _, x := range *b { _, okA := mapA[x] _, okC := mapC[x] @@ -98,7 +100,7 @@ func main() { } fmt.Printf(" Loaded %d addresses\n", len(dump3.Index)) - leaked := diff(dump1, dump2, dump3) + leaked := diffsect(&dump1.Index, &dump2.Index, &dump3.Index) if *formatFlag == "hex" { printHexDiff(leaked, dump2)