You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working on simple exhaustive algorithm to CNF satisfiability problem. Tried my minimum code here:
pubfnsolve_cnf_plain() -> bool{let n = 3;let one = bitvec![1];letmut var = bitvec![0; n];let max = bitvec![1; n];while var <= max {println!("{:?} {:?}",&var,&max);
var += one.clone();}true}
I expect to print only 8 line of output assuring bits 000 to 111 is searched. However the actual output is like:
This occurred because BitSlice uses a lexicographic sort per-bit before comparing lengths; string "aaa" sorts less than "ab" for the same reason.
This is a confluence of behavior I actually hadn't considered before, thank you. I provided arithmetic operators so that people could use the structures as arbitrary-sized integers, but I use lexicographic instead of integer sorting! That is a bug.
In the interim, you can get fixed-width arithmetic by using .as_mut_bitslice().
I am going to remove the integer arithmetic capability entirely in 0.18. I do not have a plan at this time to pull it into a bitvec_num crate. Your current code can be replaced with
for n in0u8 .. 8{let pat = &n.bits::<Lsb0>()[.. 3];println!("{:?}", pat);}
in order to correctly count through the integers while viewing their bit-pattern representation.
If you expect to need integer arithmetic beyond what can be done with ordinary Rust integers and bit-pattern views of them, please weigh in on #17 and I can get that ball rolling.
I am working on simple exhaustive algorithm to CNF satisfiability problem. Tried my minimum code here:
I expect to print only 8 line of output assuring bits 000 to 111 is searched. However the actual output is like:
There are extra lines when I add 1 to 111 (into 1000), it seems that the program misjudged
1000 <= 111
(actually should be1000 > 111
).Is my code correct, or is there some problem in this library? Thanks!
(My persional opinion is that the problem may be found at some
PartialOrd
impl inside this crate)The text was updated successfully, but these errors were encountered: