Lines Matching defs:buf
1188 fn random_sorted_fill(mut seed: u32, buf: &mut [u32]) {
1189 let mask = if buf.len() < 8192 {
1191 } else if buf.len() < 200_000 {
1197 for item in buf.iter_mut() {
1205 buf.sort();
3539 let buf = data.into_bytes();
3540 assert_eq!(buf, b"asdf");
4446 let buf = "hello".as_ptr();
4448 assert_eq!(*buf.offset(0), b'h');
4449 assert_eq!(*buf.offset(1), b'e');
4450 assert_eq!(*buf.offset(2), b'l');
4451 assert_eq!(*buf.offset(3), b'l');
4452 assert_eq!(*buf.offset(4), b'o');
12255 let mut buf = VecDeque::new();
12256 buf.extend(1..5);
12257 buf.retain(|&x| x % 2 == 0);
12258 let v: Vec<_> = buf.into_iter().collect();
13197 let mut buf = String::new();
13198 let _ = write!(&mut buf, "{}", 3);
13200 let w = &mut buf;
13209 t!(buf, "34helloline\nbar\n☃str");
13227 let mut buf = String::new();
13229 let w = &mut buf;
13234 let s = buf;
14712 /// buf: RawVec<T>,
14718 /// self.buf.reserve(self.len, elems.len());
14723 /// ptr::write(self.buf.ptr().add(self.len), x.clone());
14730 /// # let mut vector = MyVec { buf: RawVec::new(), len: 0 };
16844 /// * The memory at `buf` needs to have been previously allocated by the
16848 /// * The first `length` bytes at `buf` need to be valid UTF-8.
16853 /// The ownership of `buf` is effectively transferred to the
16884 pub unsafe fn from_raw_parts(buf: *mut u8, length: usize, capacity: usize) -> String {
16885 unsafe { String { vec: Vec::from_raw_parts(buf, length, capacity) } }
17936 let mut buf = String::new();
17937 buf.extend(iter);
17938 buf
17945 let mut buf = String::new();
17946 buf.extend(iter);
17947 buf
17954 let mut buf = String::new();
17955 buf.extend(iter);
17956 buf
17970 Some(mut buf) => {
17971 buf.extend(iterator);
17972 buf
17981 let mut buf = String::new();
17982 buf.extend(iter);
17983 buf
17998 let mut buf = cow.into_owned();
17999 buf.extend(iterator);
18000 buf
18447 let mut buf = String::new();
18448 buf.write_fmt(format_args!("{}", self))
18450 buf
22507 let mut buf = Vec::with_capacity(capacity);
22509 // `2^expn` repetition is done by doubling `buf` `expn`-times.
22510 buf.extend(self);
22515 // `buf.extend(buf)`:
22518 buf.as_ptr(),
22519 (buf.as_mut_ptr() as *mut T).add(buf.len()),
22520 buf.len(),
22522 // `buf` has capacity of `self.len() * n`.
22523 let buf_len = buf.len();
22524 buf.set_len(buf_len * 2);
22532 // first `rem` repetitions from `buf` itself.
22533 let rem_len = capacity - buf.len(); // `self.len() * rem`
22535 // `buf.extend(buf[0 .. rem_len])`:
22539 buf.as_ptr(),
22540 (buf.as_mut_ptr() as *mut T).add(buf.len()),
22543 // `buf.len() + rem_len` equals to `buf.capacity()` (`= self.len() * n`).
22544 buf.set_len(capacity);
22547 buf
22873 /// Merges non-decreasing runs `v[..mid]` and `v[mid..]` using `buf` as temporary storage, and
22878 /// The two slices must be non-empty and `mid` must be in bounds. Buffer `buf` must be long enough
22880 unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F)
22888 // The merge process first copies the shorter run into `buf`. Then it traces the newly copied
22903 // hole in `v` with the unconsumed range in `buf`, thus ensuring that `v` still holds every
22910 ptr::copy_nonoverlapping(v, buf, mid);
22911 hole = MergeHole { start: buf, end: buf.add(mid), dest: v };
22934 ptr::copy_nonoverlapping(v_mid, buf, len - mid);
22935 hole = MergeHole { start: buf, end: buf.add(len - mid), dest: v_mid };
22943 while v < *left && buf < *right {
23030 let mut buf = Vec::with_capacity(len / 2);
23077 buf.as_mut_ptr(),
26144 //! should emit output into the `f.buf` stream. It is up to each format trait
40243 fn ring_slices(buf: Self, head: usize, tail: usize) -> (Self, Self) {
40246 let (empty, buf) = buf.split_at(0);
40247 (buf.slice(tail, head), empty)
40249 let (mid, right) = buf.split_at(tail);
40448 buf: RawVec<T>,
40511 self.buf.ptr()
40521 self.buf.capacity()
40837 VecDeque { tail: 0, head: 0, buf: RawVec::with_capacity(cap) }
40849 /// let mut buf = VecDeque::new();
40850 /// buf.push_back(3);
40851 /// buf.push_back(4);
40852 /// buf.push_back(5);
40853 /// assert_eq!(buf.get(1), Some(&4));
40874 /// let mut buf = VecDeque::new();
40875 /// buf.push_back(3);
40876 /// buf.push_back(4);
40877 /// buf.push_back(5);
40878 /// if let Some(elem) = buf.get_mut(1) {
40882 /// assert_eq!(buf[1], 7);
40909 /// let mut buf = VecDeque::new();
40910 /// buf.push_back(3);
40911 /// buf.push_back(4);
40912 /// buf.push_back(5);
40913 /// assert_eq!(buf, [3, 4, 5]);
40914 /// buf.swap(0, 2);
40915 /// assert_eq!(buf, [5, 4, 3]);
40934 /// let buf: VecDeque<i32> = VecDeque::with_capacity(10);
40935 /// assert!(buf.capacity() >= 10);
40959 /// let mut buf: VecDeque<i32> = vec![1].into_iter().collect();
40960 /// buf.reserve_exact(10);
40961 /// assert!(buf.capacity() >= 11);
40982 /// let mut buf: VecDeque<i32> = vec![1].into_iter().collect();
40983 /// buf.reserve(10);
40984 /// assert!(buf.capacity() >= 11);
40996 self.buf.reserve_exact(used_cap, new_cap - used_cap);
41087 self.buf.try_reserve_exact(used_cap, new_cap - used_cap)?;
41105 /// let mut buf = VecDeque::with_capacity(15);
41106 /// buf.extend(0..4);
41107 /// assert_eq!(buf.capacity(), 15);
41108 /// buf.shrink_to_fit();
41109 /// assert!(buf.capacity() >= 4);
41129 /// let mut buf = VecDeque::with_capacity(15);
41130 /// buf.extend(0..4);
41131 /// assert_eq!(buf.capacity(), 15);
41132 /// buf.shrink_to(6);
41133 /// assert!(buf.capacity() >= 6);
41134 /// buf.shrink_to(0);
41135 /// assert!(buf.capacity() >= 4);
41192 self.buf.shrink_to_fit(target_cap);
41211 /// let mut buf = VecDeque::new();
41212 /// buf.push_back(5);
41213 /// buf.push_back(10);
41214 /// buf.push_back(15);
41215 /// assert_eq!(buf, [5, 10, 15]);
41216 /// buf.truncate(1);
41217 /// assert_eq!(buf, [5]);
41271 /// let mut buf = VecDeque::new();
41272 /// buf.push_back(5);
41273 /// buf.push_back(3);
41274 /// buf.push_back(4);
41276 /// let c: Vec<&i32> = buf.iter().collect();
41291 /// let mut buf = VecDeque::new();
41292 /// buf.push_back(5);
41293 /// buf.push_back(3);
41294 /// buf.push_back(4);
41295 /// for num in buf.iter_mut() {
41299 /// assert_eq!(&buf.iter_mut().collect::<Vec<&mut i32>>()[..], b);
41343 let buf = self.buffer_as_slice();
41344 RingSlices::ring_slices(buf, self.head, self.tail)
41379 let buf = self.buffer_as_mut_slice();
41380 RingSlices::ring_slices(buf, head, tail)
41756 /// let mut buf = VecDeque::new();
41757 /// assert_eq!(buf.pop_back(), None);
41758 /// buf.push_back(1);
41759 /// buf.push_back(3);
41760 /// assert_eq!(buf.pop_back(), Some(3));
41805 /// let mut buf = VecDeque::new();
41806 /// buf.push_back(1);
41807 /// buf.push_back(3);
41808 /// assert_eq!(3, *buf.back().unwrap());
41842 /// let mut buf = VecDeque::new();
41843 /// assert_eq!(buf.swap_remove_front(0), None);
41844 /// buf.push_back(1);
41845 /// buf.push_back(2);
41846 /// buf.push_back(3);
41847 /// assert_eq!(buf, [1, 2, 3]);
41849 /// assert_eq!(buf.swap_remove_front(2), Some(3));
41850 /// assert_eq!(buf, [2, 1]);
41877 /// let mut buf = VecDeque::new();
41878 /// assert_eq!(buf.swap_remove_back(0), None);
41879 /// buf.push_back(1);
41880 /// buf.push_back(2);
41881 /// buf.push_back(3);
41882 /// assert_eq!(buf, [1, 2, 3]);
41884 /// assert_eq!(buf.swap_remove_back(0), Some(1));
41885 /// assert_eq!(buf, [3, 2]);
42134 /// let mut buf = VecDeque::new();
42135 /// buf.push_back(1);
42136 /// buf.push_back(2);
42137 /// buf.push_back(3);
42138 /// assert_eq!(buf, [1, 2, 3]);
42140 /// assert_eq!(buf.remove(1), Some(2));
42141 /// assert_eq!(buf, [1, 3]);
42318 /// let mut buf: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
42319 /// let buf2 = buf.split_off(1);
42320 /// assert_eq!(buf, [1]);
42381 /// let mut buf: VecDeque<_> = vec![1, 2].into_iter().collect();
42383 /// buf.append(&mut buf2);
42384 /// assert_eq!(buf, [1, 2, 3, 4]);
42405 /// let mut buf = VecDeque::new();
42406 /// buf.extend(1..5);
42407 /// buf.retain(|&x| x % 2 == 0);
42408 /// assert_eq!(buf, [2, 4]);
42416 /// let mut buf = VecDeque::new();
42417 /// buf.extend(1..6);
42421 /// buf.retain(|_| (keep[i], i += 1).0);
42422 /// assert_eq!(buf, [2, 3, 5]);
42449 self.buf.reserve_exact(old_cap, old_cap);
42467 /// let mut buf = VecDeque::new();
42468 /// buf.push_back(5);
42469 /// buf.push_back(10);
42470 /// buf.push_back(15);
42471 /// assert_eq!(buf, [5, 10, 15]);
42473 /// buf.resize_with(5, Default::default);
42474 /// assert_eq!(buf, [5, 10, 15, 0, 0]);
42476 /// buf.resize_with(2, || unreachable!());
42477 /// assert_eq!(buf, [5, 10]);
42480 /// buf.resize_with(5, || { state += 1; state });
42481 /// assert_eq!(buf, [5, 10, 101, 102, 103]);
42515 /// let mut buf = VecDeque::with_capacity(15);
42517 /// buf.push_back(2);
42518 /// buf.push_back(1);
42519 /// buf.push_front(3);
42522 /// buf.make_contiguous().sort();
42523 /// assert_eq!(buf.as_slices(), (&[1, 2, 3] as &[_], &[] as &[_]));
42526 /// buf.make_contiguous().sort_by(|a, b| b.cmp(a));
42527 /// assert_eq!(buf.as_slices(), (&[3, 2, 1] as &[_], &[] as &[_]));
42535 /// let mut buf = VecDeque::new();
42537 /// buf.push_back(2);
42538 /// buf.push_back(1);
42539 /// buf.push_front(3);
42541 /// buf.make_contiguous();
42542 /// if let (slice, &[]) = buf.as_slices() {
42544 /// // while still having immutable access to `buf`.
42545 /// assert_eq!(buf.len(), slice.len());
42557 let buf = self.buf.ptr();
42572 ptr::copy(buf, buf.add(tail_len), self.head);
42574 ptr::copy_nonoverlapping(buf.add(self.tail), buf, tail_len);
42585 // to mean that we can just slice using `buf[tail..head]`.
42594 ptr::copy(buf.add(self.tail), buf.add(self.head), tail_len);
42596 ptr::copy_nonoverlapping(buf, buf.add(self.head + tail_len), self.head);
42626 ptr::swap(buf.add(i), buf.offset(src));
42664 /// let mut buf: VecDeque<_> = (0..10).collect();
42666 /// buf.rotate_left(3);
42667 /// assert_eq!(buf, [3, 4, 5, 6, 7, 8, 9, 0, 1, 2]);
42670 /// assert_eq!(i * 3 % 10, buf[0]);
42671 /// buf.rotate_left(3);
42673 /// assert_eq!(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
42707 /// let mut buf: VecDeque<_> = (0..10).collect();
42709 /// buf.rotate_right(3);
42710 /// assert_eq!(buf, [7, 8, 9, 0, 1, 2, 3, 4, 5, 6]);
42713 /// assert_eq!(0, buf[i * 3 % 10]);
42714 /// buf.rotate_right(3);
42716 /// assert_eq!(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
42969 /// let mut buf = VecDeque::new();
42970 /// buf.push_back(5);
42971 /// buf.push_back(10);
42972 /// buf.push_back(15);
42973 /// assert_eq!(buf, [5, 10, 15]);
42975 /// buf.resize(2, 0);
42976 /// assert_eq!(buf, [5, 10]);
42978 /// buf.resize(5, 20);
42979 /// assert_eq!(buf, [5, 10, 20, 20, 20]);
43228 let buf = RawVec::from_raw_parts(other_buf, capacity);
43229 VecDeque { tail: 0, head: len, buf }
43270 let buf = other.buf.ptr();
43275 ptr::copy(buf.add(other.tail), buf, len);
43277 Vec::from_raw_parts(buf, len, cap)
45873 pub(super) buf: NonNull<T>,
45950 self.buf = unsafe { NonNull::new_unchecked(RawVec::NEW.ptr()) };
45951 self.ptr = self.buf.as_ptr();
45952 self.end = self.buf.as_ptr();
46096 let _ = RawVec::from_raw_parts_in(self.0.buf.as_ptr(), self.0.cap, alloc);
46245 return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n };
46260 return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n };
46275 return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n };
46616 let has_advanced = iterator.buf.as_ptr() as *const _ != iterator.ptr;
46621 ptr::copy(it.ptr, it.buf.as_ptr(), it.len());
46623 return Vec::from_raw_parts(it.buf.as_ptr(), it.len(), it.cap);
46710 inner.buf.as_ptr(),
46712 inner.buf.as_ptr() as *mut T,
46723 debug_assert_eq!(src_buf, src.buf.as_ptr());
47183 buf: RawVec<T, A>,
47206 Vec { buf: RawVec::NEW, len: 0 }
47340 Vec { buf: RawVec::new_in(alloc), len: 0 }
47388 Vec { buf: RawVec::with_capacity_in(capacity, alloc), len: 0 }
47464 unsafe { Vec { buf: RawVec::from_raw_parts_in(ptr, capacity, alloc), len: length } }
47565 self.buf.capacity()
47588 self.buf.reserve(self.len, additional);
47614 self.buf.reserve_exact(self.len, additional);
47652 self.buf.try_reserve(self.len, additional)
47694 self.buf.try_reserve_exact(self.len, additional)
47718 self.buf.shrink_to_fit(self.len);
47745 self.buf.shrink_to_fit(cmp::max(self.len, min_capacity));
47778 let buf = ptr::read(&me.buf);
47780 buf.into_box(len).assume_init()
47913 let ptr = self.buf.ptr();
47949 let ptr = self.buf.ptr();
47960 self.buf.allocator()
48124 if len == self.buf.capacity() {
48443 if self.len == self.buf.capacity() {
48785 self.buf.capacity() - self.len,
48858 let spare_len = self.buf.capacity() - self.len;
49245 let cap = me.buf.capacity();
49247 buf: NonNull::new_unchecked(begin),
50077 vec.buf.reserve(len, additional);
51253 let buf: Box<[u8]> = self.as_bytes().into();
51254 unsafe { from_boxed_utf8_unchecked(buf) }
51404 let buf = RawVec::with_capacity(len);
51406 ptr::copy_nonoverlapping(slice.as_ptr(), buf.ptr(), len);
51407 buf.into_box(slice.len()).assume_init()