Live data from Hacker News

Show HN: A LRU cache using go generics

github.com

1–10 of 14 posts

Re: Show HN: A LRU cache using go generics

#5
post #4
post #2

This is a simple LRU cache I made to get my hands on generics which is available in the go 1.18 beta. Feedback is welcome :-)

Might you or anyone else have any good links or references that helped you come up to speed on generics in Go?

The tutorial from the Go team is pretty good to learn the basics: https://go.dev/doc/tutorial/generics

Re: Show HN: A LRU cache using go generics

#7
post #6

> Feedback is welcome You'll probably be a lot better off a) preallocating the elements so your memory is nicely contiguous, b) tracking indices and not pointers. If I wanted to pay 24b overhead per item I'd use an `interface{}`. :)

Which pointer are you wanting to replace, there are a few and I can’t work out which would be best replaced with an int :) (not the author, and not a go developer, just reading through the code and couldn’t work out which you were talking about :) )

Similar for what you want to preallocate.

Re: Show HN: A LRU cache using go generics

#8
post #7
post #6

> Feedback is welcome You'll probably be a lot better off a) preallocating the elements so your memory is nicely contiguous, b) tracking indices and not pointers. If I wanted to pay 24b overhead per item I'd use an `interface{}`. :)

Which pointer are you wanting to replace, there are a few and I can’t work out which would be best replaced with an int :) (not the author, and not a go developer, just reading through the code and couldn’t work out which you were talking about :) ) Similar for what you want to preallocate.

[deleted]

Re: Show HN: A LRU cache using go generics

#9
post #7
post #6

> Feedback is welcome You'll probably be a lot better off a) preallocating the elements so your memory is nicely contiguous, b) tracking indices and not pointers. If I wanted to pay 24b overhead per item I'd use an `interface{}`. :)

Which pointer are you wanting to replace, there are a few and I can’t work out which would be best replaced with an int :) (not the author, and not a go developer, just reading through the code and couldn’t work out which you were talking about :) ) Similar for what you want to preallocate.

Preallocate the map and the entry ({V, next, prev}) objects. Replace next and prev and the map value with indices.

Re: Show HN: A LRU cache using go generics

#10
post #4
post #2

This is a simple LRU cache I made to get my hands on generics which is available in the go 1.18 beta. Feedback is welcome :-)

Might you or anyone else have any good links or references that helped you come up to speed on generics in Go?

There's also the type parameters proposal document which covers a lot of ground.

https://go.googlesource.com/proposal/+/refs/heads/master/des...

Post reply on HN