Skip to content

Commit

Permalink
rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Dec 31, 2024
1 parent c6c0e85 commit c6c8183
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
14 changes: 7 additions & 7 deletions core/trie/bitarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,12 @@ func (b *BitArray) Equal(x *BitArray) bool {

// Returns true if bit n-th is set, where n = 0 is LSB.
func (b *BitArray) IsBitSetFromLSB(n uint8) bool {
return b.BitSetFromLSB(n) == 1
return b.BitFromLSB(n) == 1
}

// Returns the bit value at position n, where n = 0 is LSB.
// If n is out of bounds, returns 0.
func (b *BitArray) BitSetFromLSB(n uint8) uint8 {
func (b *BitArray) BitFromLSB(n uint8) uint8 {
if n >= b.len {
return 0
}
Expand All @@ -381,26 +381,26 @@ func (b *BitArray) BitSetFromLSB(n uint8) uint8 {
}

func (b *BitArray) IsBitSet(n uint8) bool {
return b.BitSet(n) == 1
return b.Bit(n) == 1
}

// Returns the bit value at position n, where n = 0 is MSB.
// If n is out of bounds, returns 0.
func (b *BitArray) BitSet(n uint8) uint8 {
func (b *BitArray) Bit(n uint8) uint8 {
if n >= b.Len() {
return 0
}

return b.BitSetFromLSB(b.Len() - n - 1)
return b.BitFromLSB(b.Len() - n - 1)
}

// Returns the bit value at the most significant bit
func (b *BitArray) MSB() uint8 {
return b.BitSet(0)
return b.Bit(0)

Check warning on line 399 in core/trie/bitarray.go

View check run for this annotation

Codecov / codecov/patch

core/trie/bitarray.go#L398-L399

Added lines #L398 - L399 were not covered by tests
}

func (b *BitArray) LSB() uint8 {
return b.BitSetFromLSB(0)
return b.BitFromLSB(0)

Check warning on line 403 in core/trie/bitarray.go

View check run for this annotation

Codecov / codecov/patch

core/trie/bitarray.go#L402-L403

Added lines #L402 - L403 were not covered by tests
}

func (b *BitArray) IsEmpty() bool {
Expand Down
28 changes: 0 additions & 28 deletions core/trie/bitarray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,34 +1552,6 @@ func TestIsBitSet(t *testing.T) {
}
}

func TestDebug(t *testing.T) {
tests := []struct {
name string
ba BitArray
pos uint8
want bool
}{
{
name: "bit in second word",
ba: BitArray{
len: 128,
words: [4]uint64{0, 1, 0, 0},
},
pos: 63,
want: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.ba.IsBitSet(tt.pos)
if got != tt.want {
t.Errorf("IsBitSet(%d) = %v, want %v", tt.pos, got, tt.want)
}
})
}
}

func TestFeltConversion(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit c6c8183

Please sign in to comment.