4 ms·
That’s what I did (at repl.it anyway)... how do I print the values in a Range of Vectors?
by andy_ppp 6y ago
That’s what I did (at repl.it anyway)... how do I print the values in a Range of Vectors?
- cdirkx 6y agoWhat would you expect those values to be?
- kibwen 6y agoThe range doesn't have values. A range defined by Rust has a start point and an end point, and no other semantics. Some additional functions then add behavior if the types contained in the range can be compared via greater-than, etc. Vecs in Rust can be compared if their contents can be compared. For a range of two vecs, foo and bar, to ask if a third vec is "contained" in that range is to ask if it compares greater than foo and less than bar.
- andy_ppp 6y agoOkay thanks for the explanation!
- redrobein 6y agoDoes debug print not work {:?}
- gpm 6y agoYou don't, because that doesn't make mathematical sense. Let's say I have the range [1].. [2], what is in this range? Well vectors are sorted in lexicographic order, so every vector that starts with 1. What comes after [1]? Suppose it's any vector whose first non zero digit is in place n (e.g. n = 2 and the vector is [1, 0, 3, 1]). I can make a vector that comes earlier in the ordering by just inserting another 0 (e.g. [1, 0, 0, 3, 1]). This means that the vector has no non zero digit... but it is obvious that [1] doesn't come after [1], and that [1, 1] comes before [2] so [2] isn't the next vector, so (by proof by contradiction) there actually just isn't a well defined concept of next vector. As a result I definitely can't just list the vectors in a range in order.
- nybble41 6y ago> there actually just isn't a well defined concept of next vector I think there is a well-defined next vector, it just isn't very useful. The next vector after [1] for a vector of unsigned integers would have to be [1, 0]. And then [1, 0, 0], [1, 0, 0, 0], etc. (For signed integers substitute T::MIN instead of 0.)