| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public void set(int index, double val) |
| 237 | { |
| 238 | if(index > length()-1 || index < 0) |
| 239 | throw new IndexOutOfBoundsException(index + " does not fit in [0," + length + ")"); |
| 240 | |
| 241 | |
| 242 | clearCaches(); |
| 243 | int insertLocation = Arrays.binarySearch(indexes, 0, used, index); |
| 244 | if(insertLocation >= 0) |
| 245 | { |
| 246 | if(val != 0)//set it |
| 247 | values[insertLocation] = val; |
| 248 | else//shift used count and everyone over |
| 249 | { |
| 250 | removeNonZero(insertLocation); |
| 251 | } |
| 252 | } |
| 253 | else if(val != 0)//dont insert 0s, that is stupid |
| 254 | insertValue(insertLocation, index, val); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Takes the negative insert location value returned by {@link Arrays#binarySearch(int[], int, int, int) } |