bitfield: has depends on the order of invalid and set indices

Open Beginner friendly
#32,709 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
data

Research direction

Start with the has method and the get_bit helper in the bitfield module, which the issue says treats out-of-range positions as zero. Run the two-line repro from the issue (bitfield.from_str('00100') with has(-1, 2) and has(2, -1)) to confirm the order-dependent results. Done when both argument orders return the same answer and the result matches the rule that each position is checked independently.

Written by the indexing model from the issue text.

Description

On dev at a1342333f2, run this with ./v -gc none run repro.v:

import bitfield

fn main() {
	bf := bitfield.from_str('00100')
	println(bf.has(-1, 2))
	println(bf.has(2, -1))
}

The first query reports false and the reversed query reports true. Both ask whether any of the same positions is set. Position 2 is set, and get_bit treats an out-of-range position as zero. has should apply that rule to each requested position.

[!NOTE]
You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Dominant language
V
Stars
38.1k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
682

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vlang/v

All issues in vlang/v

Similar issues

More Data Engineering issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.