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

Cleanup the Put function in the FIFO cache #838

Closed
iFrostizz opened this issue Apr 17, 2024 · 0 comments · Fixed by #973
Closed

Cleanup the Put function in the FIFO cache #838

iFrostizz opened this issue Apr 17, 2024 · 0 comments · Fixed by #973

Comments

@iFrostizz
Copy link
Collaborator

As correctly pointed out by @StephenButtolph , and quoting his message about the Put function:

Total aside but Put  would probably be cleaner if it was:
func (f *FIFO[K, V]) Put(key K, val V) bool {
	f.l.Lock()
	defer f.l.Unlock()

	_, exists := f.m[key]
	if !exists {
		f.buffer.Push(key) // Insert will remove the oldest [K] if we are at the [limit]
	}
	f.m[key] = val
	return exists
}
The comment should probably be fixed as well:
// Insert will remove the oldest [K] if we are at the [limit]
Should be:
// Push removes the oldest [K] if we are at the [limit]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done ✅
Development

Successfully merging a pull request may close this issue.

1 participant