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

Add Delete function #194

Merged
merged 6 commits into from
Jun 19, 2023
Merged

Add Delete function #194

merged 6 commits into from
Jun 19, 2023

Conversation

chocolacula
Copy link
Contributor

@chocolacula chocolacula commented Jun 8, 2023

I believe checking index and bounds is better than keep it without the check and panicking with a bit weird error.

@chocolacula
Copy link
Contributor Author

@elliotchance any thoughts?

v2/remove.go Outdated Show resolved Hide resolved
@chocolacula
Copy link
Contributor Author

I don't like the way it uses an output parameter. It should return a new slice not containing the element. Also, Delete a more common term used by languages when deleting something by it's key. And finally, are you sure this works with a single element? It looks like it would panic.

Done. One element will be deleted correctly. Added a test for that case.

v2/delete.go Outdated Show resolved Hide resolved
@chocolacula
Copy link
Contributor Author

I tried a few approaches and chose the best one. I added a little benchmark:

BenchmarkDelete-8                   3372           355714 ns/op          8003676 B/op      3 allocs/op
BenchmarkDelete-8                   2890           357530 ns/op          8003675 B/op      3 allocs/op
BenchmarkDeleteShort-8          14604861           80.06 ns/op           176 B/op          3 allocs/op
BenchmarkDeleteShort-8          14294144           80.04 ns/op           176 B/op          3 allocs/op
BenchmarkDeleteSet-8                 184           6437496 ns/op         8003588 B/op      1 allocs/op
BenchmarkDeleteSet-8                 184           6431757 ns/op         8003589 B/op      1 allocs/op
BenchmarkDeleteSetShort-8        8599725           137.4 ns/op           128 B/op          1 allocs/op
BenchmarkDeleteSetShort-8        8649344           137.3 ns/op           128 B/op          1 allocs/op

You can find them in separate branch in delete_test.go

@chocolacula
Copy link
Contributor Author

@elliotchance please review

@elliotchance elliotchance merged commit 36b1ca2 into elliotchance:master Jun 19, 2023
@elliotchance elliotchance changed the title Add Remove function Add Delete function Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants