bitvec icon indicating copy to clipboard operation
bitvec copied to clipboard

Implement `BitArc` and `BitRc`

Open myrrlyn opened this issue 6 years ago • 0 comments
trafficstars

Currently bitvec has a slice, a box, and a vector, but it does not have reference-counted boxes.

I would like to export BitArc and BitRc types which, like BitBox, use a BitPtr core pointer structure and recreate the standard library's Arc and Rc APIs as appropriate.

This issue is not marked as "good first issue" because it will require an understanding of how the BitPtr structure describes a memory span, as well as how the standard library's Arc and Rc implement their backing store.

Suggested implementation sketch:

struct BitArcBox {
  strong: AtomicUsize,
  weak: AtomicUsize,
  region: BitSlice
}
struct BitRcBox {
  // same, but non-atomic
}
struct BitArc {
  ptr: BitPtr, // point to BitArcBox
}
struct BitRc {
  // same, but BitRcBox
}

(add requisite type parameters; I didn't feel like including them here)

Implementation question: should the BitPtr point to the start of the boxed structure, or to the start of the slice region inside it?

I am willing to explain the library's core BitPtr structure enough for you to feel confident in manipulating it in the (A)Rc handles, but you do not need to be intimately familiar with its internal operation. It is probably sufficient to think of it as a very clever slice pointer. You need to be more familiar with the standard library pattern we are copying than with the internals of the crate.

Once the types are created and working, they will need the stdlib API ported over to them. A standing delivery requirement of the crate is that it should be as close to drop-in compatible with the standard types as possible. There are some impossibilities that we just cannot implement without changing the language, but everything the language permits, we should follow.

myrrlyn avatar Aug 30 '19 00:08 myrrlyn