Skip to content

Commit

Permalink
Refactor implementation to use an internal slice instead of a pair of…
Browse files Browse the repository at this point in the history
… 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
gnzlbg committed May 3, 2019
1 parent 5f49768 commit 8074e61
Show file tree
Hide file tree
Showing 2 changed files with 204 additions and 162 deletions.
Loading

0 comments on commit 8074e61

Please # to comment.