Skip to content

Commit

Permalink
Internalize the both the intersecting and unique domain slices in the…
Browse files Browse the repository at this point in the history
… compared list's struct.
  • Loading branch information
StevenBlack committed Apr 27, 2020
1 parent a932483 commit d3d6178
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Binary file modified ghosts
Binary file not shown.
38 changes: 21 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ type TLDtally struct {

// A Hosts struct holds all the facets of a collection of hosts.
type Hosts struct {
Raw []byte
Location string
Header []string
Domains []string
TLDs map[string]int
TLDtallies []TLDtally
Duplicates []string
Raw []byte
Location string
Header []string
Domains []string
TLDs map[string]int
TLDtallies []TLDtally
Duplicates []string
Intersection []string
Unique []string
}

// Reset the Hosts structure to an initial, unloaded state.
Expand All @@ -48,6 +50,8 @@ func (h *Hosts) Reset() bool {
h.TLDs = map[string]int{}
h.TLDtallies = []TLDtally{}
h.Duplicates = []string{}
h.Intersection = []string{}
h.Unique = []string{}

return true
}
Expand Down Expand Up @@ -410,16 +414,16 @@ func main() {
fmt.Println(hf2.Summary("Compared hosts file"))
}

intersection := funk.IntersectString(hf1.Domains, hf2.Domains)
hf2.Intersection = funk.IntersectString(hf1.Domains, hf2.Domains)
if intersectionList {
// for now, unceremoniously dump the intersecting domains.
fmt.Println("intersection:", intersection)
fmt.Println("intersection:", hf2.Intersection)
}
fmt.Println("Intersection:", humanize.Comma(int64(len(intersection))), "domains")
fmt.Println("Intersection:", humanize.Comma(int64(len(hf2.Intersection))), "domains")

if uniquelist {
_, uniq := funk.Difference(intersection, hf2.Domains)
fmt.Println("unique in comparison list:", uniq)
_, hf2.Unique = funk.DifferenceString(hf2.Intersection, hf2.Domains)
fmt.Println("unique in comparison list:", hf2.Unique)
}
} else if sysclipboard {
hf2 := Hosts{}
Expand All @@ -429,17 +433,17 @@ func main() {
fmt.Println(hf2.Summary("Compared hosts from clipboard"))
}

intersection := funk.IntersectString(hf1.Domains, hf2.Domains)
hf2.Intersection = funk.IntersectString(hf1.Domains, hf2.Domains)

if intersectionList {
// for now, unceremoniously dump the intersecting domains.
fmt.Println("intersection:", intersection)
fmt.Println("intersection:", hf2.Intersection)
}
fmt.Println("Intersection:", humanize.Comma(int64(len(intersection))), "domains")
fmt.Println("Intersection:", humanize.Comma(int64(len(hf2.Intersection))), "domains")

if uniquelist {
_, uniq := funk.Difference(hf1.Domains, hf2.Domains)
fmt.Println("unique in comparison list:", uniq)
_, hf2.Unique = funk.DifferenceString(hf2.Intersection, hf2.Domains)
fmt.Println("unique in comparison list:", hf2.Unique)
}
}
}

0 comments on commit d3d6178

Please sign in to comment.