refactor: make BitVec
indexing more consistent with List
indexing
#400
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.
The current
BitVec.getLsb
/getMsb
functions index bitvectors withNat
s, returningfalse
for out-of-bounds indexes.I propose to rename these functions to
getLsbD
/getMsbD
(D
for default value), in line withList.getD
.This frees up the
getLsb
/getMsb
name for indexing with a guaranteed in-boundsi : Fin _
, just likeList.get
.Similarly, rename
msb
(which might index out-of-bounds for an empty bitvector) tomsbD
, and add a newmsb
taking a known non-empty bitvector (i.e.,BitVec (n+1)
), c.f.List.headD
/List.head
. And add short-handslsb
/lsbD
to get the least-significant bit for symmetry.The comparison is not perfect:
List.getD
allows the caller to specify a default value for out-of-bounds indices, whereas the newly addedBitVec.getLsbD
assumesfalse
as the default value. An indexing function which returnstrue
for out-of-bounds indices does not seem necessary to me, but I am curious to hear other opinions on this.