Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added outersection functions for Int. #12

Merged
merged 4 commits into from
May 5, 2021
Merged

Added outersection functions for Int. #12

merged 4 commits into from
May 5, 2021

Conversation

Skandalik
Copy link
Contributor

No description provided.

slicex/int_test.go Show resolved Hide resolved
slicex/int.go Outdated

// IntOuterRight returns right outersection of 2 slices.
func IntOuterRight(slice1, slice2 []int) []int {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this exactly the same as InOuterLeft, but with arguments order reversed? If so, why not call InOuterLeft(slice2, slice1)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, fixed

slicex/int_test.go Show resolved Hide resolved
slicex/int.go Outdated

// IntOuter returns outersection of 2 slices.
func IntOuter(slice1, slice2 []int) []int {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that you wanted to achieve this: https://en.wikipedia.org/wiki/Symmetric_difference
you could put that link to comment somewhere here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, changed naming as well :).

slicex/int_test.go Show resolved Hide resolved
// IntOuter returns outersection of 2 slices.
func IntOuter(slice1, slice2 []int) []int {
checks := make(map[int]int8, len(slice1)+len(slice2))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to avoid a map, then you could sort joined slices and then look if consecutive values are repeating, e.g. for one of the test cases:
1,2,3,3,4,5
pros: not using map
con: sort operation, which is also not free

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minus of this approach is reiterating for repetitions, in current approach there are 3 fors.

  • 1st slice
  • 2nd slice
  • map to find out difference.

Map is very useful in these cases to find out if value is existing or find out counts.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there would be only one sort and one for, but it's not that important

@Skandalik Skandalik merged commit bd01612 into master May 5, 2021
@Skandalik Skandalik deleted the outersection branch May 5, 2021 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants