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
package arena | |
func ArenaAlloc[T any](n int) <-chan *T { | |
c := make(chan *T, n/2) | |
go func() { | |
for { | |
s := make([]T, n) | |
for k := range s { | |
c <- &s[k] |
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
package slicefilter | |
// FilterSliceFunc filters the input slice based on a pass function | |
// and returns the filtered slice | |
// it filters inplace and modifies the input slice, so be careful! | |
func FilterSliceFunc[S any](in []S, pass func(S) bool) []S { | |
outIdx := 0 | |
for _, v := range in { | |
if !pass(v) { | |
continue |