Skip to content

Commit 750bcc4

Browse files
authored
Merge pull request #81 from davidv1992/lockfreefrozenvec-too-small
Fixed lockfree frozen vec being too small.
2 parents 94214fa + 9c75ab5 commit 750bcc4

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/index_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<K: Eq + Hash, V: StableDeref, S: BuildHasher> FrozenIndexMap<K, V, S> {
9090
}
9191

9292
/// Returns a reference to the value corresponding to the key.
93-
///
93+
///
9494
/// # Arguments
9595
/// * `k` may be any type that implements [`Equivalent<K>`].
9696
///
@@ -119,7 +119,7 @@ impl<K: Eq + Hash, V: StableDeref, S: BuildHasher> FrozenIndexMap<K, V, S> {
119119
}
120120

121121
/// Returns the index corresponding to the key
122-
///
122+
///
123123
/// # Arguments
124124
/// * `k` may be any type that implements [`Equivalent<K>`].
125125
///
@@ -175,7 +175,7 @@ impl<K: Eq + Hash, V: StableDeref, S: BuildHasher> FrozenIndexMap<K, V, S> {
175175
}
176176

177177
/// Returns a reference to the key, along with its index and a reference to its value
178-
///
178+
///
179179
/// # Arguments
180180
/// * `k` may be any type that implements [`Equivalent<K>`].
181181
///

src/index_set.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<T: Eq + Hash + StableDeref, S: BuildHasher> FrozenIndexSet<T, S> {
117117
// }
118118

119119
/// Returns a reference to the value passed as argument if present in the set.
120-
///
120+
///
121121
/// # Arguments
122122
/// * `k` may be any type that implements [`Equivalent<T>`].
123123
///
@@ -146,10 +146,10 @@ impl<T: Eq + Hash + StableDeref, S: BuildHasher> FrozenIndexSet<T, S> {
146146
}
147147

148148
/// Returns the index corresponding to the value if present in the set
149-
///
149+
///
150150
/// # Arguments
151151
/// * `k` may be any type that implements [`Equivalent<T>`].
152-
///
152+
///
153153
/// # Examples
154154
///
155155
/// ```
@@ -176,7 +176,7 @@ impl<T: Eq + Hash + StableDeref, S: BuildHasher> FrozenIndexSet<T, S> {
176176

177177
/// Returns a reference to the value passed as argument if present in the set,
178178
/// along with its index
179-
///
179+
///
180180
/// # Arguments
181181
/// * `k` may be any type that implements [`Equivalent<T>`].
182182
///

src/sync.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,13 +665,15 @@ const fn buffer_index(i: usize) -> usize {
665665
(((usize::BITS + 1 - (i + 1).leading_zeros()) >> 1) - 1) as usize
666666
}
667667

668-
const NUM_BUFFERS: usize = (usize::BITS >> 2) as usize;
668+
/// Each buffer covers 2 bits of address space, so we need half as many
669+
/// buffers as bits in a usize.
670+
const NUM_BUFFERS: usize = (usize::BITS / 2) as usize;
669671

670672
/// Append-only threadsafe version of `std::vec::Vec` where
671673
/// insertion does not require mutable access.
672674
/// Does not lock for reading, only allows `Copy` types and
673675
/// will spinlock on pushes without affecting reads.
674-
/// Note that this data structure is `64` pointers large on
676+
/// Note that this data structure is `34` pointers large on
675677
/// 64 bit systems,
676678
/// in contrast to `Vec` which is `3` pointers large.
677679
pub struct LockFreeFrozenVec<T: Copy> {

0 commit comments

Comments
 (0)