| ... | ... | @@ -574,6 +574,19 @@ pub fn ArrayHashMapUnmanaged( |
| 574 | 574 | }; |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | pub fn init(allocator: Allocator, key_list: []const K, value_list: []const V) !Self { |
| 578 | var self: Self = .{}; |
| 579 | try self.entries.resize(allocator, key_list.len); |
| 580 | errdefer self.entries.deinit(allocator); |
| 581 | @memcpy(self.keys(), key_list); |
| 582 | if (@sizeOf(V) != 0) { |
| 583 | assert(key_list.len == value_list.len); |
| 584 | @memcpy(self.values(), value_list); |
| 585 | } |
| 586 | try self.reIndex(allocator); |
| 587 | return self; |
| 588 | } |
| 589 | |
| 577 | 590 | /// Frees the backing allocation and leaves the map in an undefined state. |
| 578 | 591 | /// Note that this does not free keys or values. You must take care of that |
| 579 | 592 | /// before calling this function, if it is needed. |