| ... | ... | @@ -26,11 +26,13 @@ pub fn MultiArrayList(comptime T: type) type { |
| 26 | 26 | bytes: [*]u8 = undefined, |
| 27 | 27 | len: usize = 0, |
| 28 | 28 | capacity: usize = 0, |
| 29 | pointer_stability: std.debug.SafetyLock = .{}, |
| 29 | 30 | |
| 30 | 31 | pub const empty: Self = .{ |
| 31 | 32 | .bytes = undefined, |
| 32 | 33 | .len = 0, |
| 33 | 34 | .capacity = 0, |
| 35 | .pointer_stability = .{}, |
| 34 | 36 | }; |
| 35 | 37 | |
| 36 | 38 | /// Initialize with capacity to hold exactly `num` elements. |
| ... | ... | @@ -80,13 +82,16 @@ pub fn MultiArrayList(comptime T: type) type { |
| 80 | 82 | ptrs: [field_names.len][*]u8, |
| 81 | 83 | len: usize, |
| 82 | 84 | capacity: usize, |
| 85 | pointer_stability: std.debug.SafetyLock, |
| 83 | 86 | |
| 84 | 87 | pub const empty: Slice = .{ |
| 85 | 88 | .ptrs = undefined, |
| 86 | 89 | .len = 0, |
| 87 | 90 | .capacity = 0, |
| 91 | .pointer_stability = .{}, |
| 88 | 92 | }; |
| 89 | 93 | |
| 94 | /// The returned pointer may be invalidated by various operations to this Slice. |
| 90 | 95 | pub fn items(self: Slice, comptime field: Field) []FieldType(field) { |
| 91 | 96 | const F = FieldType(field); |
| 92 | 97 | if (self.capacity == 0) { |
| ... | ... | @@ -100,7 +105,9 @@ pub fn MultiArrayList(comptime T: type) type { |
| 100 | 105 | return casted_ptr[0..self.len]; |
| 101 | 106 | } |
| 102 | 107 | |
| 108 | /// Invalidates pre-existing pointers to fields of the element at index `index`. |
| 103 | 109 | pub fn set(self: *Slice, index: usize, elem: T) void { |
| 110 | self.pointer_stability.assertUnlocked(); |
| 104 | 111 | const e = switch (@typeInfo(T)) { |
| 105 | 112 | .@"struct" => elem, |
| 106 | 113 | .@"union" => Elem.fromT(elem), |
| ... | ... | @@ -123,25 +130,31 @@ pub fn MultiArrayList(comptime T: type) type { |
| 123 | 130 | }; |
| 124 | 131 | } |
| 125 | 132 | |
| 133 | /// Invalidates pre-existing pointers to fields of the element at indices `a` and `b`. |
| 126 | 134 | pub fn swap(self: Slice, a: usize, b: usize) void { |
| 135 | self.pointer_stability.assertUnlocked(); |
| 127 | 136 | inline for (@typeInfo(Field).@"enum".field_names) |field_name| { |
| 128 | 137 | const its = self.items(@field(Field, field_name)); |
| 129 | 138 | std.mem.swap(@FieldType(T, field_name), &its[a], &its[b]); |
| 130 | 139 | } |
| 131 | 140 | } |
| 132 | 141 | |
| 142 | /// The returned MultiArrayList inherits the locked/unlocked state of this Slice |
| 133 | 143 | pub fn toMultiArrayList(self: Slice) Self { |
| 134 | 144 | if (self.ptrs.len == 0 or self.capacity == 0) { |
| 135 | | return .{}; |
| 145 | return .empty; |
| 136 | 146 | } |
| 137 | 147 | return .{ |
| 138 | 148 | .bytes = self.ptrs[sizes.fields[0]], |
| 139 | 149 | .len = self.len, |
| 140 | 150 | .capacity = self.capacity, |
| 151 | .pointer_stability = self.pointer_stability, |
| 141 | 152 | }; |
| 142 | 153 | } |
| 143 | 154 | |
| 155 | /// Invalidates all element pointers |
| 144 | 156 | pub fn deinit(self: *Slice, gpa: Allocator) void { |
| 157 | self.pointer_stability.assertUnlocked(); |
| 145 | 158 | var other = self.toMultiArrayList(); |
| 146 | 159 | other.deinit(gpa); |
| 147 | 160 | self.* = undefined; |
| ... | ... | @@ -160,9 +173,27 @@ pub fn MultiArrayList(comptime T: type) type { |
| 160 | 173 | .ptrs = ptrs, |
| 161 | 174 | .len = len, |
| 162 | 175 | .capacity = len, |
| 176 | .pointer_stability = s.pointer_stability, |
| 163 | 177 | }; |
| 164 | 178 | } |
| 165 | 179 | |
| 180 | /// Puts the Slice into a state where any method call that |
| 181 | /// would cause an existing item pointer to become invalidated will |
| 182 | /// instead trigger an assertion. |
| 183 | /// |
| 184 | /// `lockPointers` may be called multiple times. This allows multiple |
| 185 | /// independent users of the hash map to keep it locked simultaneously. |
| 186 | /// |
| 187 | /// `unlockPointers` returns the Slice to the previous state. |
| 188 | pub fn lockPointers(self: *Slice) void { |
| 189 | self.pointer_stability.lockShared(); |
| 190 | } |
| 191 | |
| 192 | /// Undoes one call to `lockPointers`. |
| 193 | pub fn unlockPointers(self: *Slice) void { |
| 194 | self.pointer_stability.unlockShared(); |
| 195 | } |
| 196 | |
| 166 | 197 | /// This function is used in the debugger pretty formatters in lib/lldb/ to fetch the |
| 167 | 198 | /// child field order and entry type to facilitate fancy debug printing for this type. |
| 168 | 199 | fn dbHelper(self: *Slice, child: *Elem, field: *Field, entry: *Entry) void { |
| ... | ... | @@ -219,12 +250,32 @@ pub fn MultiArrayList(comptime T: type) type { |
| 219 | 250 | }; |
| 220 | 251 | |
| 221 | 252 | /// Release all allocated memory. |
| 253 | /// Invalidates all element pointers. |
| 222 | 254 | pub fn deinit(self: *Self, gpa: Allocator) void { |
| 223 | 255 | gpa.free(self.allocatedBytes()); |
| 224 | 256 | self.* = undefined; |
| 225 | 257 | } |
| 226 | 258 | |
| 259 | /// Puts the MultiArrayList into a state where any method call that |
| 260 | /// would cause an existing item pointer to become invalidated will |
| 261 | /// instead trigger an assertion. |
| 262 | /// |
| 263 | /// `lockPointers` may be called multiple times. This allows multiple |
| 264 | /// independent users of the hash map to keep it locked simultaneously. |
| 265 | /// |
| 266 | /// `unlockPointers` returns the MultiArrayList to the previous state. |
| 267 | pub fn lockPointers(self: *Self) void { |
| 268 | self.pointer_stability.lockShared(); |
| 269 | } |
| 270 | |
| 271 | /// Undoes one call to `lockPointers`. |
| 272 | pub fn unlockPointers(self: *Self) void { |
| 273 | self.pointer_stability.unlockShared(); |
| 274 | } |
| 275 | |
| 227 | 276 | /// The caller owns the returned memory. Empties this MultiArrayList. |
| 277 | /// Does not invalidate element pointers. |
| 278 | /// The returned Slice inherits its locked/unlocked state from this MultiArrayList. |
| 228 | 279 | pub fn toOwnedSlice(self: *Self) Slice { |
| 229 | 280 | const result = self.slice(); |
| 230 | 281 | self.* = .empty; |
| ... | ... | @@ -234,11 +285,14 @@ pub fn MultiArrayList(comptime T: type) type { |
| 234 | 285 | /// Compute pointers to the start of each field of the array. |
| 235 | 286 | /// If you need to access multiple fields, calling this may |
| 236 | 287 | /// be more efficient than calling `items()` multiple times. |
| 288 | /// Does not invalidate element pointers. |
| 289 | /// The returned Slice inherits its locked/unlocked state from this MultiArrayList. |
| 237 | 290 | pub fn slice(self: Self) Slice { |
| 238 | 291 | var result: Slice = .{ |
| 239 | 292 | .ptrs = undefined, |
| 240 | 293 | .len = self.len, |
| 241 | 294 | .capacity = self.capacity, |
| 295 | .pointer_stability = self.pointer_stability, |
| 242 | 296 | }; |
| 243 | 297 | var ptr: [*]u8 = self.bytes; |
| 244 | 298 | for (sizes.bytes, sizes.fields) |field_size, i| { |
| ... | ... | @@ -251,12 +305,15 @@ pub fn MultiArrayList(comptime T: type) type { |
| 251 | 305 | /// Get the slice of values for a specified field. |
| 252 | 306 | /// If you need multiple fields, consider calling slice() |
| 253 | 307 | /// instead. |
| 308 | /// The returned pointer may be invalidated by various operations to this MultiArrayList. |
| 254 | 309 | pub fn items(self: Self, comptime field: Field) []FieldType(field) { |
| 255 | 310 | return self.slice().items(field); |
| 256 | 311 | } |
| 257 | 312 | |
| 258 | 313 | /// Overwrite one array element with new data. |
| 314 | /// Invalidates previously existing pointers to fields of that element. |
| 259 | 315 | pub fn set(self: *Self, index: usize, elem: T) void { |
| 316 | self.pointer_stability.assertUnlocked(); |
| 260 | 317 | var slices = self.slice(); |
| 261 | 318 | slices.set(index, elem); |
| 262 | 319 | } |
| ... | ... | @@ -266,13 +323,17 @@ pub fn MultiArrayList(comptime T: type) type { |
| 266 | 323 | return self.slice().get(index); |
| 267 | 324 | } |
| 268 | 325 | |
| 326 | /// Invalidates previously existing pointers to fields of the element |
| 327 | /// at indices `a` and `b`. |
| 269 | 328 | pub fn swap(self: Self, a: usize, b: usize) void { |
| 329 | self.pointer_stability.assertUnlocked(); |
| 270 | 330 | return self.slice().swap(a, b); |
| 271 | 331 | } |
| 272 | 332 | |
| 273 | 333 | /// Extend the list by 1 element. |
| 274 | 334 | /// |
| 275 | 335 | /// Allocates more memory as necessary. |
| 336 | /// Invalidates element pointers if more memory is needed. |
| 276 | 337 | pub fn append(self: *Self, gpa: Allocator, elem: T) Allocator.Error!void { |
| 277 | 338 | try self.ensureUnusedCapacity(gpa, 1); |
| 278 | 339 | self.appendAssumeCapacity(elem); |
| ... | ... | @@ -281,6 +342,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 281 | 342 | /// Extend the list by 1 element. |
| 282 | 343 | /// |
| 283 | 344 | /// Asserts that capacity is sufficient to hold an additional item. |
| 345 | /// Never invalidates element pointers. |
| 284 | 346 | pub fn appendAssumeCapacity(self: *Self, elem: T) void { |
| 285 | 347 | assert(self.len < self.capacity); |
| 286 | 348 | self.len += 1; |
| ... | ... | @@ -291,6 +353,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 291 | 353 | /// |
| 292 | 354 | /// If capacity is not sufficient to hold an additional |
| 293 | 355 | /// item, returns `error.OutOfMemory`. |
| 356 | /// Never invalidates element pointers. |
| 294 | 357 | pub fn appendBounded(self: *Self, elem: T) error{OutOfMemory}!void { |
| 295 | 358 | if (self.capacity - self.len < 1) return error.OutOfMemory; |
| 296 | 359 | return appendAssumeCapacity(self, elem); |
| ... | ... | @@ -300,6 +363,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 300 | 363 | /// index with uninitialized data. |
| 301 | 364 | /// |
| 302 | 365 | /// Allocates more memory as necessary. |
| 366 | /// Invalidates element pointers if more memory is needed. |
| 303 | 367 | pub fn addOne(self: *Self, gpa: Allocator) Allocator.Error!usize { |
| 304 | 368 | try self.ensureUnusedCapacity(gpa, 1); |
| 305 | 369 | return self.addOneAssumeCapacity(); |
| ... | ... | @@ -309,6 +373,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 309 | 373 | /// index with uninitialized data. |
| 310 | 374 | /// |
| 311 | 375 | /// Asserts that capacity is sufficient to hold an additional item. |
| 376 | /// Never invalidates element pointers. |
| 312 | 377 | pub fn addOneAssumeCapacity(self: *Self) usize { |
| 313 | 378 | assert(self.len < self.capacity); |
| 314 | 379 | const index = self.len; |
| ... | ... | @@ -321,6 +386,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 321 | 386 | /// |
| 322 | 387 | /// If capacity is not sufficient to hold an additional |
| 323 | 388 | /// item, returns `error.OutOfMemory`. |
| 389 | /// Never invalidates element pointers. |
| 324 | 390 | pub fn addOneBounded(self: *Self) error{OutOfMemory}!usize { |
| 325 | 391 | if (self.capacity - self.len < 1) return error.OutOfMemory; |
| 326 | 392 | return addOneAssumeCapacity(self); |
| ... | ... | @@ -329,6 +395,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 329 | 395 | /// Remove and return the last element from the list, or return `null` if list is empty. |
| 330 | 396 | /// Invalidates pointers to fields of the removed element. |
| 331 | 397 | pub fn pop(self: *Self) ?T { |
| 398 | self.pointer_stability.assertUnlocked(); |
| 332 | 399 | if (self.len == 0) return null; |
| 333 | 400 | const val = self.get(self.len - 1); |
| 334 | 401 | self.len -= 1; |
| ... | ... | @@ -340,6 +407,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 340 | 407 | /// sets the given index to the specified element. |
| 341 | 408 | /// |
| 342 | 409 | /// Allocates more memory as necessary. |
| 410 | /// Invalidates pointers to shifted elements. |
| 343 | 411 | pub fn insert(self: *Self, gpa: Allocator, index: usize, elem: T) !void { |
| 344 | 412 | try self.ensureUnusedCapacity(gpa, 1); |
| 345 | 413 | self.insertAssumeCapacity(index, elem); |
| ... | ... | @@ -350,9 +418,11 @@ pub fn MultiArrayList(comptime T: type) type { |
| 350 | 418 | /// sets the given index to the specified element. |
| 351 | 419 | /// |
| 352 | 420 | /// Asserts that capacity is sufficient to hold an additional item. |
| 421 | /// Invalidates pointers to shifted elements. |
| 353 | 422 | pub fn insertAssumeCapacity(self: *Self, index: usize, elem: T) void { |
| 354 | 423 | assert(self.len < self.capacity); |
| 355 | 424 | assert(index <= self.len); |
| 425 | self.pointer_stability.assertUnlocked(); |
| 356 | 426 | self.len += 1; |
| 357 | 427 | const entry = switch (@typeInfo(T)) { |
| 358 | 428 | .@"struct" => elem, |
| ... | ... | @@ -376,6 +446,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 376 | 446 | /// |
| 377 | 447 | /// If capacity is not sufficient to hold an additional |
| 378 | 448 | /// item, returns `error.OutOfMemory`. |
| 449 | /// Invalidates pointers to shifted elements. |
| 379 | 450 | pub fn insertBounded(self: *Self, index: usize, elem: T) error{OutOfMemory}!void { |
| 380 | 451 | if (self.capacity - self.len < 1) return error.OutOfMemory; |
| 381 | 452 | return insertAssumeCapacity(self, index, elem); |
| ... | ... | @@ -384,7 +455,9 @@ pub fn MultiArrayList(comptime T: type) type { |
| 384 | 455 | /// Remove the specified item from the list, swapping the last |
| 385 | 456 | /// item in the list into its position. Fast, but does not |
| 386 | 457 | /// retain list ordering. |
| 458 | /// Invalidates pointers to fields of the item at the end of the list. |
| 387 | 459 | pub fn swapRemove(self: *Self, index: usize) void { |
| 460 | self.pointer_stability.assertUnlocked(); |
| 388 | 461 | const slices = self.slice(); |
| 389 | 462 | inline for (field_names, 0..) |_, i| { |
| 390 | 463 | const field_slice = slices.items(@as(Field, @fromBackingInt(@intCast(i)))); |
| ... | ... | @@ -396,7 +469,9 @@ pub fn MultiArrayList(comptime T: type) type { |
| 396 | 469 | |
| 397 | 470 | /// Remove the specified item from the list, shifting items |
| 398 | 471 | /// after it to preserve order. |
| 472 | /// Invalidates pointers to shifted elements. |
| 399 | 473 | pub fn orderedRemove(self: *Self, index: usize) void { |
| 474 | self.pointer_stability.assertUnlocked(); |
| 400 | 475 | const slices = self.slice(); |
| 401 | 476 | inline for (field_names, 0..) |_, field_index| { |
| 402 | 477 | const field_slice = slices.items(@as(Field, @fromBackingInt(@intCast(field_index)))); |
| ... | ... | @@ -423,6 +498,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 423 | 498 | /// Invalidates element pointers beyond the first deleted index. |
| 424 | 499 | pub fn orderedRemoveMany(self: *Self, sorted_indexes: []const usize) void { |
| 425 | 500 | if (sorted_indexes.len == 0) return; |
| 501 | self.pointer_stability.assertUnlocked(); |
| 426 | 502 | const slices = self.slice(); |
| 427 | 503 | var shift: usize = 1; |
| 428 | 504 | for (sorted_indexes[0 .. sorted_indexes.len - 1], sorted_indexes[1..]) |removed, end| { |
| ... | ... | @@ -447,6 +523,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 447 | 523 | |
| 448 | 524 | /// Adjust the list's length to `new_len`. |
| 449 | 525 | /// Does not initialize added items, if any. |
| 526 | /// Invalidates element pointers if additional memory is required. |
| 450 | 527 | pub fn resize(self: *Self, gpa: Allocator, new_len: usize) Allocator.Error!void { |
| 451 | 528 | try self.ensureTotalCapacity(gpa, new_len); |
| 452 | 529 | self.len = new_len; |
| ... | ... | @@ -455,11 +532,12 @@ pub fn MultiArrayList(comptime T: type) type { |
| 455 | 532 | /// Attempt to reduce allocated capacity to `new_len`. |
| 456 | 533 | /// If `new_len` is greater than zero, this may fail to reduce the capacity, |
| 457 | 534 | /// but the data remains intact and the length is updated to new_len. |
| 535 | /// Invalidates element pointers if additional memory is required. |
| 458 | 536 | pub fn shrinkAndFree(self: *Self, gpa: Allocator, new_len: usize) void { |
| 459 | 537 | if (new_len == 0) return clearAndFree(self, gpa); |
| 460 | | |
| 461 | 538 | assert(new_len <= self.capacity); |
| 462 | 539 | assert(new_len <= self.len); |
| 540 | self.pointer_stability.assertUnlocked(); |
| 463 | 541 | |
| 464 | 542 | const other_bytes = gpa.alignedAlloc(u8, sizes.big_align, capacityInBytes(new_len)) catch { |
| 465 | 543 | const self_slice = self.slice(); |
| ... | ... | @@ -476,7 +554,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 476 | 554 | self.len = new_len; |
| 477 | 555 | return; |
| 478 | 556 | }; |
| 479 | | var other = Self{ |
| 557 | var other: Self = .{ |
| 480 | 558 | .bytes = other_bytes.ptr, |
| 481 | 559 | .capacity = new_len, |
| 482 | 560 | .len = new_len, |
| ... | ... | @@ -494,7 +572,9 @@ pub fn MultiArrayList(comptime T: type) type { |
| 494 | 572 | self.* = other; |
| 495 | 573 | } |
| 496 | 574 | |
| 575 | /// Invalidates all element pointers. |
| 497 | 576 | pub fn clearAndFree(self: *Self, gpa: Allocator) void { |
| 577 | self.pointer_stability.assertUnlocked(); |
| 498 | 578 | gpa.free(self.allocatedBytes()); |
| 499 | 579 | self.* = .empty; |
| 500 | 580 | } |
| ... | ... | @@ -503,11 +583,13 @@ pub fn MultiArrayList(comptime T: type) type { |
| 503 | 583 | /// Invalidates pointers to elements `items[new_len..]`. |
| 504 | 584 | /// Keeps capacity the same. |
| 505 | 585 | pub fn shrinkRetainingCapacity(self: *Self, new_len: usize) void { |
| 586 | self.pointer_stability.assertUnlocked(); |
| 506 | 587 | self.len = new_len; |
| 507 | 588 | } |
| 508 | 589 | |
| 509 | 590 | /// Invalidates all element pointers. |
| 510 | 591 | pub fn clearRetainingCapacity(self: *Self) void { |
| 592 | self.pointer_stability.assertUnlocked(); |
| 511 | 593 | self.len = 0; |
| 512 | 594 | } |
| 513 | 595 | |
| ... | ... | @@ -542,6 +624,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 542 | 624 | /// `new_capacity` must be greater or equal to `len`. |
| 543 | 625 | pub fn setCapacity(self: *Self, gpa: Allocator, new_capacity: usize) Allocator.Error!void { |
| 544 | 626 | assert(new_capacity >= self.len); |
| 627 | self.pointer_stability.assertUnlocked(); |
| 545 | 628 | const new_bytes = try gpa.alignedAlloc(u8, sizes.big_align, capacityInBytes(new_capacity)); |
| 546 | 629 | if (self.len == 0) { |
| 547 | 630 | gpa.free(self.allocatedBytes()); |
| ... | ... | @@ -549,7 +632,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 549 | 632 | self.capacity = new_capacity; |
| 550 | 633 | return; |
| 551 | 634 | } |
| 552 | | var other = Self{ |
| 635 | var other: Self = .{ |
| 553 | 636 | .bytes = new_bytes.ptr, |
| 554 | 637 | .capacity = new_capacity, |
| 555 | 638 | .len = self.len, |
| ... | ... | @@ -568,8 +651,9 @@ pub fn MultiArrayList(comptime T: type) type { |
| 568 | 651 | |
| 569 | 652 | /// Create a copy of this list with a new backing store, |
| 570 | 653 | /// using the specified allocator. |
| 654 | /// The returned MultiArrayList is in an unlocked state. |
| 571 | 655 | pub fn clone(self: Self, gpa: Allocator) Allocator.Error!Self { |
| 572 | | var result = Self{}; |
| 656 | var result: Self = .{}; |
| 573 | 657 | errdefer result.deinit(gpa); |
| 574 | 658 | try result.ensureTotalCapacity(gpa, self.len); |
| 575 | 659 | result.len = self.len; |
| ... | ... | @@ -584,9 +668,11 @@ pub fn MultiArrayList(comptime T: type) type { |
| 584 | 668 | return result; |
| 585 | 669 | } |
| 586 | 670 | |
| 671 | /// Invalidates element pointers. |
| 587 | 672 | /// `ctx` has the following method: |
| 588 | 673 | /// `fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool` |
| 589 | 674 | fn sortInternal(self: Self, a: usize, b: usize, ctx: anytype, comptime mode: std.sort.Mode) void { |
| 675 | self.pointer_stability.assertUnlocked(); |
| 590 | 676 | const sort_context: struct { |
| 591 | 677 | sub_ctx: @TypeOf(ctx), |
| 592 | 678 | slice: Slice, |
| ... | ... | @@ -616,6 +702,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 616 | 702 | } |
| 617 | 703 | |
| 618 | 704 | /// This function guarantees a stable sort, i.e the relative order of equal elements is preserved during sorting. |
| 705 | /// Invalidates element pointers. |
| 619 | 706 | /// Read more about stable sorting here: https://en.wikipedia.org/wiki/Sorting_algorithm#Stability |
| 620 | 707 | /// If this guarantee does not matter, `sortUnstable` might be a faster alternative. |
| 621 | 708 | /// `ctx` has the following method: |
| ... | ... | @@ -625,6 +712,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 625 | 712 | } |
| 626 | 713 | |
| 627 | 714 | /// Sorts only the subsection of items between indices `a` and `b` (excluding `b`) |
| 715 | /// Invalidates element pointers. |
| 628 | 716 | /// This function guarantees a stable sort, i.e the relative order of equal elements is preserved during sorting. |
| 629 | 717 | /// Read more about stable sorting here: https://en.wikipedia.org/wiki/Sorting_algorithm#Stability |
| 630 | 718 | /// If this guarantee does not matter, `sortSpanUnstable` might be a faster alternative. |
| ... | ... | @@ -635,6 +723,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 635 | 723 | } |
| 636 | 724 | |
| 637 | 725 | /// This function does NOT guarantee a stable sort, i.e the relative order of equal elements may change during sorting. |
| 726 | /// Invalidates element pointers. |
| 638 | 727 | /// Due to the weaker guarantees of this function, this may be faster than the stable `sort` method. |
| 639 | 728 | /// Read more about stable sorting here: https://en.wikipedia.org/wiki/Sorting_algorithm#Stability |
| 640 | 729 | /// `ctx` has the following method: |
| ... | ... | @@ -644,6 +733,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 644 | 733 | } |
| 645 | 734 | |
| 646 | 735 | /// Sorts only the subsection of items between indices `a` and `b` (excluding `b`) |
| 736 | /// Invalidates element pointers. |
| 647 | 737 | /// This function does NOT guarantee a stable sort, i.e the relative order of equal elements may change during sorting. |
| 648 | 738 | /// Due to the weaker guarantees of this function, this may be faster than the stable `sortSpan` method. |
| 649 | 739 | /// Read more about stable sorting here: https://en.wikipedia.org/wiki/Sorting_algorithm#Stability |