Lines Matching full:item

36 /// * For every item in the list, the list owns the associated [`ListArc`] reference and has
102 /// This is called when an item is inserted into a [`List`].
140 /// The prev/next pointers for an item in a linked list.
144 /// The fields are null if and only if this item is not in a list.
248 /// Add the provided item to the back of the list.
249 pub fn push_back(&mut self, item: ListArc<T, ID>) { in push_back()
250 let raw_item = ListArc::into_raw(item); in push_back()
260 let item = unsafe { ListLinks::fields(list_links) }; in push_back() localVariable
263 self.first = item; in push_back()
265 // INVARIANT: A linked list with one item should be cyclic. in push_back()
267 (*item).next = item; in push_back()
268 (*item).prev = item; in push_back()
276 // ownership of the fields on `item`. in push_back()
277 // INVARIANT: This correctly inserts `item` between `prev` and `next`. in push_back()
279 (*item).next = next; in push_back()
280 (*item).prev = prev; in push_back()
281 (*prev).next = item; in push_back()
282 (*next).prev = item; in push_back()
287 /// Add the provided item to the front of the list.
288 pub fn push_front(&mut self, item: ListArc<T, ID>) { in push_front()
289 let raw_item = ListArc::into_raw(item); in push_front()
300 let item = unsafe { ListLinks::fields(list_links) }; in push_front() localVariable
304 // INVARIANT: A linked list with one item should be cyclic. in push_front()
306 (*item).next = item; in push_front()
307 (*item).prev = item; in push_front()
314 // ownership of the fields on `item`. in push_front()
315 // INVARIANT: This correctly inserts `item` between `prev` and `next`. in push_front()
317 (*item).next = next; in push_front()
318 (*item).prev = prev; in push_front()
319 (*prev).next = item; in push_front()
320 (*next).prev = item; in push_front()
323 self.first = item; in push_front()
326 /// Removes the last item from this list.
334 // SAFETY: The last item of this list is in this list. in pop_back()
338 /// Removes the first item from this list.
344 // SAFETY: The first item of this list is in this list. in pop_front()
348 /// Removes the provided item from this list and returns it.
350 /// This returns `None` if the item is not in the list. (Note that by the safety requirements,
351 /// this means that the item is not in any list.)
355 /// `item` must not be in a different linked list (with the same id).
356 pub unsafe fn remove(&mut self, item: &T) -> Option<ListArc<T, ID>> { in remove()
357 let mut item = unsafe { ListLinks::fields(T::view_links(item)) }; in remove() localVariable
362 // * If `item` is not in any list, then these fields are read-only and null. in remove()
363 // * If `item` is in this list, then we have exclusive access to these fields since we in remove()
367 let ListLinksFields { next, prev } = unsafe { *item }; in remove()
371 // This is really a no-op, but this ensures that `item` is a raw pointer that was in remove()
379 debug_assert_eq!(item, (*next).prev); in remove()
380 item = (*next).prev; in remove()
383 // SAFETY: We just checked that `item` is in a list, so the caller guarantees that it in remove()
385 Some(unsafe { self.remove_internal_inner(item, next, prev) }) in remove()
391 /// Removes the provided item from the list.
395 /// `item` must point at an item in this list.
396 unsafe fn remove_internal(&mut self, item: *mut ListLinksFields) -> ListArc<T, ID> { in remove_internal()
398 // since we have a mutable reference to the list containing `item`. in remove_internal()
399 let ListLinksFields { next, prev } = unsafe { *item }; in remove_internal()
401 unsafe { self.remove_internal_inner(item, next, prev) } in remove_internal()
404 /// Removes the provided item from the list.
408 /// The `item` pointer must point at an item in this list, and we must have `(*item).next ==
409 /// next` and `(*item).prev == prev`.
412 item: *mut ListLinksFields, in remove_internal_inner()
420 // * If the list has at least three items, then after removing the item, `prev` and `next` in remove_internal_inner()
422 // * If the list has two items, then the remaining item will point at itself. in remove_internal_inner()
423 // * If the list has one item, then `next == prev == item`, so these writes have no in remove_internal_inner()
424 // effect. The list remains unchanged and `item` is still in the list for now. in remove_internal_inner()
430 // INVARIANT: `item` is being removed, so the pointers should be null. in remove_internal_inner()
432 (*item).prev = ptr::null_mut(); in remove_internal_inner()
433 (*item).next = ptr::null_mut(); in remove_internal_inner()
436 // * If `item` was not the first item, then `self.first` should remain unchanged. in remove_internal_inner()
437 // * If `item` was the first item and there is another item, then we just updated in remove_internal_inner()
438 // `prev->next` to `next`, which is the new first item, and setting `item->next` to null in remove_internal_inner()
440 // * If `item` was the only item in the list, then `prev == item`, and we just set in remove_internal_inner()
441 // `item->next` to null, so this correctly sets `first` to null now that the list is in remove_internal_inner()
443 if self.first == item { in remove_internal_inner()
444 // SAFETY: The `prev` pointer is the value that `item->prev` had when it was in this in remove_internal_inner()
450 // SAFETY: `item` used to be in the list, so it is dereferenceable by the type invariants in remove_internal_inner()
452 let list_links = unsafe { ListLinks::from_fields(item) }; in remove_internal_inner()
461 /// The items of `other` are added to the back of `self`, so the last item of `other` becomes
462 /// the last item of `self`.
525 while let Some(item) = self.pop_front() { in drop()
526 drop(item); in drop()
546 type Item = ArcBorrow<'a, T>; typedef
567 let item = unsafe { T::view_value(ListLinks::from_fields(current)) }; in next() localVariable
575 Some(unsafe { ArcBorrow::from_raw(item) }) in next()
651 type Item = ArcBorrow<'a, T>; typedef
664 type Item = ListArc<T, ID>; typedef
681 type Item = ListArc<T, ID>; typedef