MCPcopy Create free account
hub / github.com/tendermint/tendermint / Sub

Method Sub

libs/bits/bit_array.go:187–208  ·  view source on GitHub ↗

Sub subtracts the two bit-arrays bitwise, without carrying the bits. Note that carryless subtraction of a - b is (a and not b). The output is the same as bA, regardless of o's size. If bA is longer than o, o is right padded with zeroes

(o *BitArray)

Source from the content-addressed store, hash-verified

185// The output is the same as bA, regardless of o's size.
186// If bA is longer than o, o is right padded with zeroes
187func (bA *BitArray) Sub(o *BitArray) *BitArray {
188 if bA == nil || o == nil {
189 // TODO: Decide if we should do 1's complement here?
190 return nil
191 }
192 bA.mtx.Lock()
193 o.mtx.Lock()
194 // output is the same size as bA
195 c := bA.copyBits(bA.Bits)
196 // Only iterate to the minimum size between the two.
197 // If o is longer, those bits are ignored.
198 // If bA is longer, then skipping those iterations is equivalent
199 // to right padding with 0's
200 smaller := tmmath.MinInt(len(bA.Elems), len(o.Elems))
201 for i := 0; i < smaller; i++ {
202 // &^ is and not in golang
203 c.Elems[i] &^= o.Elems[i]
204 }
205 bA.mtx.Unlock()
206 o.mtx.Unlock()
207 return c
208}
209
210// IsEmpty returns true iff all bits in the bit array are 0
211func (bA *BitArray) IsEmpty() bool {

Callers 15

TestSubFunction · 0.95
GenPrivKeySecp256k1Function · 0.80
splitIntoBlockIntervalsFunction · 0.80
purgeExpiredTxsMethod · 0.80
LessMethod · 0.80
receiveRequestMethod · 0.80
crawlPeersMethod · 0.80
clockFunction · 0.80
isExpiredMethod · 0.80
verifyMethod · 0.80
gossipDataRoutineMethod · 0.80

Calls 3

copyBitsMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65

Tested by 2

TestSubFunction · 0.76