Open
Conversation
oda
reviewed
Mar 14, 2026
| capacityが0からスタートしたとき、100回insertするとメモリ領域の伸張は合計6回発生する。 | ||
| 0 + 3 + 7 + 14 + 28 + 56 = 108 | ||
| 108 / 10 ^ 8 = 0.00000108s = 1.08μs となる。 | ||
| 1.08μsを節約するためにHashSet::with_capacity(emails.len())を理解して書いているのであれば、ソフトウェアエンジニアの常識から外れている行為だなと思った。 |
There was a problem hiding this comment.
実際のところコピー自体はもう少し速いかもしれません。CPU のクロックと SIMD やメモリー帯域の関係で。ただ、この場合、安全側に倒すのに越したことはないです。
一方で、OS がメモリーのアロケーションをするので、API 呼び出しなどもろもろコストは乗るでしょう。
まあ、結論はあまり違和感がありませんが、結構適当な計算であるというふうに思っていただいたほうがいいかと思います。
There was a problem hiding this comment.
with_capacity 自体はつけてもいいと思いますが、大まかな見積もりは意識しておきましょう、ということです。
mamo3gr
reviewed
Mar 19, 2026
| nums.reverse(); | ||
| return; | ||
| }; | ||
| let Some(swap_index) = nums |
There was a problem hiding this comment.
上を rfind_first_decreasing_index にするなら、こちらも next_larger_index など、内容を表す命名にしたいです。swapすることは後の処理で分かりますし。
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題: 31. Next Permutation
次に解く問題: 8. String to Integer (atoi)
ファイルの構成:
./src/bin/<各ステップ>.rs