Skip to content

Commit

Permalink
Return arrays/slices on each call (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmin764 authored and juliangruber committed Oct 8, 2019
1 parent bae54ed commit 64ef44e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions intersect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"sort"
)

// Complexity: O(n^2)
func Simple(a interface{}, b interface{}) interface{} {
// Simple has complexity: O(n^2)
func Simple(a interface{}, b interface{}) []interface{} {
set := make([]interface{}, 0)
av := reflect.ValueOf(a)

Expand All @@ -20,8 +20,8 @@ func Simple(a interface{}, b interface{}) interface{} {
return set
}

// Complexity: O(n * log(n)), a needs to be sorted
func Sorted(a interface{}, b interface{}) interface{} {
// Sorted has complexity: O(n * log(n)), a needs to be sorted
func Sorted(a interface{}, b interface{}) []interface{} {
set := make([]interface{}, 0)
av := reflect.ValueOf(a)
bv := reflect.ValueOf(b)
Expand All @@ -39,8 +39,8 @@ func Sorted(a interface{}, b interface{}) interface{} {
return set
}

// Complexity: O(n * x) where x is a factor of hash function efficiency (between 1 and 2)
func Hash(a interface{}, b interface{}) interface{} {
// Hash has complexity: O(n * x) where x is a factor of hash function efficiency (between 1 and 2)
func Hash(a interface{}, b interface{}) []interface{} {
set := make([]interface{}, 0)
hash := make(map[interface{}]bool)
av := reflect.ValueOf(a)
Expand Down
3 changes: 3 additions & 0 deletions intersect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

func TestSimple(t *testing.T) {
s := Simple([]int{1}, []int{2})
assert.Equal(t, len(s), 0)
assert.Equal(t, s, []interface{}{})

s = Simple([]int{1, 2}, []int{2})
Expand All @@ -16,6 +17,7 @@ func TestSimple(t *testing.T) {

func TestSorted(t *testing.T) {
s := Sorted([]int{1}, []int{2})
assert.Equal(t, len(s), 0)
assert.Equal(t, s, []interface{}{})

s = Sorted([]int{1, 2}, []int{2})
Expand All @@ -24,6 +26,7 @@ func TestSorted(t *testing.T) {

func TestHash(t *testing.T) {
s := Hash([]int{1}, []int{2})
assert.Equal(t, len(s), 0)
assert.Equal(t, s, []interface{}{})

s = Hash([]int{1, 2}, []int{2})
Expand Down

0 comments on commit 64ef44e

Please sign in to comment.