(&self, index: &BigInt)
| 148 | |
| 149 | #[inline] |
| 150 | pub fn get(&self, index: &BigInt) -> Option<BigInt> { |
| 151 | let start = self.start.as_bigint(); |
| 152 | let step = self.step.as_bigint(); |
| 153 | let stop = self.stop.as_bigint(); |
| 154 | if self.is_empty() { |
| 155 | return None; |
| 156 | } |
| 157 | |
| 158 | if index.is_negative() { |
| 159 | let length = self.compute_length(); |
| 160 | let index: BigInt = &length + index; |
| 161 | if index.is_negative() { |
| 162 | return None; |
| 163 | } |
| 164 | |
| 165 | Some(if step.is_one() { |
| 166 | start + index |
| 167 | } else { |
| 168 | start + step * index |
| 169 | }) |
| 170 | } else { |
| 171 | let index = if step.is_one() { |
| 172 | start + index |
| 173 | } else { |
| 174 | start + step * index |
| 175 | }; |
| 176 | |
| 177 | if (step.is_positive() && stop > &index) || (step.is_negative() && stop < &index) { |
| 178 | Some(index) |
| 179 | } else { |
| 180 | None |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | #[inline] |
| 186 | fn compute_length(&self) -> BigInt { |
no test coverage detected