-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversion of raw pointers into buckets #435
Comments
This doesn't work when Also |
I did not know about that property of I attempted an implementation using that, but I ran into another issue. As I am trying to construct a linked list of buckets, I would like a way to have dummy head/tail buckets to enable easy removal, however I found no clean way to do that. Since conversion from raw pointer to Two ways I came up with would be to make a free-standing bucket (which I suppose violates the intuition of what a bucket is supposed to be) or allowing accessing |
I don't think that would work, can't you just use an Incidentally I had a look at your |
You are using Bucket to build a linked list, won't Bucket fail when new values are inserted in the RawTable? |
Sorry for not replying sooner (and thanks for the ping). I have somewhat forgotten about this issue as I have worked on other projects.
I use
This would no longer allow O(1) deletion from arbitrary positions in the list, which I require for the LRU-cache to ensure O(1) getting. A get-operation on an LRU-cache marks the retrieved element as "most recently used" and thus has to remove it from the list and put it at the head. In a
That would require a branch during removal. If the removed element has a predecessor, it must be updated to point to the removed element's successor as its own. If the removed element does not have a predecessor, this cannot be done (same for successors). To avoid having to branch here, I use a dummy head/tail element to serve as the predecessor of the first element and successor of the last element. Then, I can ignore this condition and handle each element equally. I learned this trick from the After considering the implications for |
Currently, it is possible to convert
Bucket
s into raw pointers throughBucket::as_ptr
, but I was unable to find a reverse. Would it be possible to offer a[unsafe] fn Bucket::from_ptr(ptr: *mut T) -> Bucket<T>
?As a use case, I am using raw pointers into a raw table and would like to efficiently store optional pointers as nullable. A function like this would allow me to model it as follows.
The best I found is the ugly and implementation-dependent
std::mem::transmute(ptr.add(1))
.The text was updated successfully, but these errors were encountered: