mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
bitfield: minor documentation and function tweaks (#10549)
This commit is contained in:
@@ -340,6 +340,8 @@ pub fn (instance BitField) clone() BitField {
|
||||
|
||||
// cmp compares two bit arrays bit by bit and returns 'true' if they are
|
||||
// identical by length and contents and 'false' otherwise.
|
||||
[deprecated: 'use a == b instead']
|
||||
[deprecated_after: '2021-06-29']
|
||||
pub fn (instance BitField) cmp(input BitField) bool {
|
||||
if instance.size != input.size {
|
||||
return false
|
||||
@@ -352,6 +354,18 @@ pub fn (instance BitField) cmp(input BitField) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
pub fn (a BitField) == (b BitField) bool {
|
||||
if a.size != b.size {
|
||||
return false
|
||||
}
|
||||
for i in 0 .. zbitnslots(a.size) {
|
||||
if a.field[i] != b.field[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// pop_count returns the number of set bits (ones) in the array.
|
||||
pub fn (instance BitField) pop_count() int {
|
||||
size := instance.size
|
||||
@@ -391,7 +405,7 @@ pub fn (haystack BitField) pos(needle BitField) int {
|
||||
}
|
||||
for i := 0; i <= diff; i++ {
|
||||
needle_candidate := haystack.slice(i, needle_size + i)
|
||||
if needle_candidate.cmp(needle) {
|
||||
if needle_candidate == needle {
|
||||
// needle matches a sub-array of haystack; return starting position of the sub-array
|
||||
return i
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user