Lines Matching refs:item
52 /// * For every item in the list, the list owns the associated [`ListArc`] reference and has
343 /// This is called when an item is inserted into a [`List`].
381 /// The prev/next pointers for an item in a linked list.
385 /// The fields are null if and only if this item is not in a list.
496 /// Inserts `item` before `next` in the cycle.
507 item: ListArc<T, ID>,
510 let raw_item = ListArc::into_raw(item);
520 let item = unsafe { ListLinks::fields(list_links) };
525 // INVARIANT: A linked list with one item should be cyclic.
527 (*item).next = item;
528 (*item).prev = item;
530 self.first = item;
536 // ownership of the fields on `item`.
537 // INVARIANT: This correctly inserts `item` between `prev` and `next`.
539 (*item).next = next;
540 (*item).prev = prev;
541 (*prev).next = item;
542 (*next).prev = item;
546 item
549 /// Add the provided item to the back of the list.
550 pub fn push_back(&mut self, item: ListArc<T, ID>) {
554 unsafe { self.insert_inner(item, self.first) };
557 /// Add the provided item to the front of the list.
558 pub fn push_front(&mut self, item: ListArc<T, ID>) {
562 let new_elem = unsafe { self.insert_inner(item, self.first) };
568 /// Removes the last item from this list.
576 // SAFETY: The last item of this list is in this list.
580 /// Removes the first item from this list.
586 // SAFETY: The first item of this list is in this list.
590 /// Removes the provided item from this list and returns it.
592 /// This returns `None` if the item is not in the list. (Note that by the safety requirements,
593 /// this means that the item is not in any list.)
600 /// `item` must not be in a different linked list (with the same id).
601 pub unsafe fn remove(&mut self, item: &T) -> Option<ListArc<T, ID>> {
603 let mut item = unsafe { ListLinks::fields(T::view_links(item)) };
608 // * If `item` is not in any list, then these fields are read-only and null.
609 // * If `item` is in this list, then we have exclusive access to these fields since we
613 let ListLinksFields { next, prev } = unsafe { *item };
617 // This is really a no-op, but this ensures that `item` is a raw pointer that was
625 debug_assert_eq!(item, (*next).prev);
626 item = (*next).prev;
629 // SAFETY: We just checked that `item` is in a list, so the caller guarantees that it
631 Some(unsafe { self.remove_internal_inner(item, next, prev) })
637 /// Removes the provided item from the list.
641 /// `item` must point at an item in this list.
642 unsafe fn remove_internal(&mut self, item: *mut ListLinksFields) -> ListArc<T, ID> {
644 // since we have a mutable reference to the list containing `item`.
645 let ListLinksFields { next, prev } = unsafe { *item };
647 unsafe { self.remove_internal_inner(item, next, prev) }
650 /// Removes the provided item from the list.
654 /// The `item` pointer must point at an item in this list, and we must have `(*item).next ==
655 /// next` and `(*item).prev == prev`.
658 item: *mut ListLinksFields,
666 // * If the list has at least three items, then after removing the item, `prev` and `next`
668 // * If the list has two items, then the remaining item will point at itself.
669 // * If the list has one item, then `next == prev == item`, so these writes have no
670 // effect. The list remains unchanged and `item` is still in the list for now.
676 // INVARIANT: `item` is being removed, so the pointers should be null.
678 (*item).prev = ptr::null_mut();
679 (*item).next = ptr::null_mut();
682 // * If `item` was not the first item, then `self.first` should remain unchanged.
683 // * If `item` was the first item and there is another item, then we just updated
684 // `prev->next` to `next`, which is the new first item, and setting `item->next` to null
686 // * If `item` was the only item in the list, then `prev == item`, and we just set
687 // `item->next` to null, so this correctly sets `first` to null now that the list is
689 if self.first == item {
690 // SAFETY: The `prev` pointer is the value that `item->prev` had when it was in this
696 // SAFETY: `item` used to be in the list, so it is dereferenceable by the type invariants
698 let list_links = unsafe { ListLinks::from_fields(item) };
707 /// The items of `other` are added to the back of `self`, so the last item of `other` becomes
708 /// the last item of `self`.
775 while let Some(item) = self.pop_front() {
776 drop(item);
817 let item = unsafe { T::view_value(ListLinks::from_fields(current)) };
825 Some(unsafe { ArcBorrow::from_raw(item) })
1063 fn insert_inner(&mut self, item: ListArc<T, ID>) -> *mut ListLinksFields {
1072 let item = unsafe { self.list.insert_inner(item, ptr) };
1074 // INVARIANT: We just inserted `item`, so it's a member of list.
1075 self.list.first = item;
1077 item
1081 pub fn insert(mut self, item: ListArc<T, ID>) {
1086 self.insert_inner(item);
1092 pub fn insert_next(&mut self, item: ListArc<T, ID>) {
1093 self.next = self.insert_inner(item);
1099 pub fn insert_prev(&mut self, item: ListArc<T, ID>) {
1100 self.insert_inner(item);