Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor implementation to use an internal slice instead of a pair of…
… indices. This commit refactors the implementation use an internal slice instead of indices, which significantly simplifies the implementation and closes #57. The problem with #57 was that using a pair of indices to keep track of where the head and the tail of the slice are located only works correctly for `mem::size_of::<T>() % allocation_granularity() == 0` because in that case, there is a unique map from indices to elements in memory. consider a T that's 3 bytes wide, for which `mem::size_of::<T>() % allocation_granularity() != 0`, then we can have: ``` // first region mirrored region // [T02, T10, T11, T12, -, -, T00, T01] | [T02, T10, T11, T12, -, -, T00, T01] ``` such that poping the first element leaves ``` // first region mirrored region // [-, T10, T11, T12, -, -, -, -] | [-, T10, T11, T12, -, -, -, -] ``` An integer indexing scheme in multiples of `size_of::<T>()` that starts at the beginning of the first memory region cannot cope with this (e.g. we'd need to say that the head of the slice starts at index 0.5). One way to work around that would be to use indices to bytes instead (or equivalently, pointers). This PR does that, by changing the layout from a pair of indices to Ts, to a pointer to the first T, and a length (that is, a slice).
- Loading branch information