(squash this) address Jae's comments on `NumTrueBitsBefore`

This commit is contained in:
ValarDragon 2018-08-13 18:46:33 -07:00
parent 8d28344e84
commit 6beaf6e72d
3 changed files with 6 additions and 8 deletions

View File

@ -71,12 +71,10 @@ func (bA *CompactBitArray) SetIndex(i int, v bool) bool {
return true return true
} }
// NumOfTrueBitsBefore returns the location of the given index, among the // NumTrueBitsBefore returns the number of bits set to true before the
// values in the bit array that are set to true. // given index. e.g. if bA = _XX__XX, NumOfTrueBitsBefore(4) = 2, since
// e.g. if bA = _XX_X_X, NumOfTrueBitsBefore(4) = 2, since // there are two bits set to true before index 4.
// the value at index 4 of the bit array is the third func (bA *CompactBitArray) NumTrueBitsBefore(index int) int {
// value that is true. (And it is 0-indexed)
func (bA *CompactBitArray) NumOfTrueBitsBefore(index int) int {
numTrueValues := 0 numTrueValues := 0
for i := 0; i < index; i++ { for i := 0; i < index; i++ {
if bA.GetIndex(i) { if bA.GetIndex(i) {

View File

@ -33,7 +33,7 @@ func getIndex(pk crypto.PubKey, keys []crypto.PubKey) int {
// AddSignature adds a signature to the multisig, at the corresponding index. // AddSignature adds a signature to the multisig, at the corresponding index.
// If the signature already exists, replace it. // If the signature already exists, replace it.
func (mSig *Multisignature) AddSignature(sig []byte, index int) { func (mSig *Multisignature) AddSignature(sig []byte, index int) {
newSigIndex := mSig.BitArray.NumOfTrueBitsBefore(index) newSigIndex := mSig.BitArray.NumTrueBitsBefore(index)
// Signature already exists, just replace the value there // Signature already exists, just replace the value there
if mSig.BitArray.GetIndex(index) { if mSig.BitArray.GetIndex(index) {
mSig.Sigs[newSigIndex] = sig mSig.Sigs[newSigIndex] = sig

View File

@ -47,7 +47,7 @@ func (pk *ThresholdMultiSignaturePubKey) VerifyBytes(msg []byte, marshalledSig [
return false return false
} }
// ensure at least k signatures are set // ensure at least k signatures are set
if sig.BitArray.NumOfTrueBitsBefore(size) < int(pk.K) { if sig.BitArray.NumTrueBitsBefore(size) < int(pk.K) {
return false return false
} }
// index in the list of signatures which we are concerned with. // index in the list of signatures which we are concerned with.