| ... | @@ -574,6 +574,19 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -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 | /// Frees the backing allocation and leaves the map in an undefined state. | 590 | /// Frees the backing allocation and leaves the map in an undefined state. |
| 578 | /// Note that this does not free keys or values. You must take care of that | 591 | /// Note that this does not free keys or values. You must take care of that |
| 579 | /// before calling this function, if it is needed. | 592 | /// before calling this function, if it is needed. |