Categorygithub.com/juliangruber/go-intersect

# README

go-intersect

Find the intersection of two iterable values.

This library provides multiple implementations which each have their strong and weak points.

Read the docs.

Build Status

Installation

$ go get github.com/juliangruber/go-intersect

Example

import "github.com/juliangruber/go-intersect"
import "fmt"

func main() {
  a := []int{1, 2, 3}
  b := []int{2, 3, 4}
  fmt.Println(intersect.SimpleGeneric(a, b))
}

Generics

Go v1.18 now supports generics which increases performance compared to reflection. Below are benchmark results between reflection and generics of the hash intersection functions. Slice sizes of 1, 10, 100 1.000 and 10.000 are used.

The average time and allocated bytes are more than halved when using generics, and the number of times bytes have to be allocated from the heap are improved significantly.

NameRunsAverageAllocatedAllocations from heap
BenchmarkHash/Size_1-_interface-84.631.326248.1 ns/op80 B/op5 allocs/op
BenchmarkHash/Size_1-_generics-822.551.09146.19 ns/op8 B/op1 allocs/op
BenchmarkHash/Size_10-_interface-8581.2622.042 ns/op547 B/op24 allocs/op
BenchmarkHash/Size_10-_generics-82.043.096549.6 ns/op187 B/op2 allocs/op
BenchmarkHash/Size_100-_interface-859.90718.721 ns/op7.325 B/op213 allocs/op
BenchmarkHash/Size_100-_generics-8126.6228.221 ns/op3.359 B/op19 allocs/op
BenchmarkHash/Size_1000-_interface-87.11422.1721 ns/op112.405 B/op2.038 allocs/op
BenchmarkHash/Size_1000-_generics-813.34591.197 ns/op53.323 B/op74 allocs/op
BenchmarkHash/Size_10000-_interface-85232.067.330 ns/op875.731 B/op20.173 allocs/op
BenchmarkHash/Size_10000-_generics-81.264828.214 ns/op427.541 B/op320 allocs/op

# Packages

No description provided by the author