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

バイト列の変換とあまりの部分の処理 #9

Closed
kawasin73 opened this issue Nov 9, 2018 · 1 comment
Closed

バイト列の変換とあまりの部分の処理 #9

kawasin73 opened this issue Nov 9, 2018 · 1 comment
Assignees

Comments

@kawasin73
Copy link
Owner

kawasin73 commented Nov 9, 2018

bitset では、[]byte[]uint64 に変換する。もし、バイト列の長さが 8 の倍数でない場合にどのように対応するかを考察する

@kawasin73 kawasin73 self-assigned this Nov 9, 2018
@kawasin73 kawasin73 mentioned this issue Nov 9, 2018
15 tasks
@kawasin73
Copy link
Owner Author

バイト列を拡張しない仕様である ( #6 ) ため、バイト列の長さが 8 の倍数でなくあまりが発生するときの対処法としては以下のものが考えられる。

  • 余った部分を含めて []uint64 に型変換する(長さは (len(buf) + 7) / 8 になる)
  • 余った部分を無視して []uint64 に型変換する(長さは len(buf) / 8 になる)
  • エラーを返して型変換しない

余った部分を含めた場合最後の要素の uint64 にアクセスしたときに不正なメモリアクセスをすることになるため採用しない。

余った部分を無視して型変換する場合は、余った部分も含めてビットベクトルの処理が行われるとユーザが期待していた場合、その間違いに気づけないためユーザがバグを実装する可能性がある。

エラーを返して型変換する場合は、ユーザの使いやすさが著しく悪くなり柔軟性が落ちるが、ユーザは間違った長さのバイト列を渡したことに気づける利点がある。そのため、 エラーを返して型変換する 手法を採用する。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant