-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package extractor | ||
|
||
import ( | ||
"net/url" | ||
"sort" | ||
) | ||
|
||
// compareURLs compares two slices of *url.URL | ||
func compareURLs(a, b []*url.URL) bool { | ||
if len(a) != len(b) { | ||
return false | ||
} | ||
|
||
// Create a map to store the count of each URL in slice a | ||
counts := make(map[string]int) | ||
for _, url := range a { | ||
counts[url.String()]++ | ||
} | ||
|
||
// Decrement the count for each URL in slice b | ||
for _, url := range b { | ||
counts[url.String()]-- | ||
} | ||
|
||
// Check if any count is non-zero, indicating a mismatch | ||
for _, count := range counts { | ||
if count != 0 { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
// sortURLs sorts a slice of *url.URL | ||
func sortURLs(urls []*url.URL) { | ||
sort.Slice(urls, func(i, j int) bool { | ||
return urls[i].String() < urls[j].String() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters