diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-05-09 17:44:05 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-05-09 17:44:39 +0200 |
| commit | a61d8daec1eb8f5f22a6190d1b51e784faed8bdf (patch) | |
| tree | 2793aeb1c5c7508aca4b052df5751a78cad9441c /core | |
| parent | 113feacbc7efbfd2076ae04bc6b25ea740b47a50 (diff) | |
Add make version of bitset to slice.
Diffstat (limited to 'core')
| -rw-r--r-- | core/slice/slice.odin | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/core/slice/slice.odin b/core/slice/slice.odin index 170e4cbf3..6cb844b40 100644 --- a/core/slice/slice.odin +++ b/core/slice/slice.odin @@ -717,11 +717,27 @@ enum_slice_to_bitset :: proc(enums: []$E, $T: typeid/bit_set[E]) -> (bits: T) wh // e.g.: // sl := slice.bitset_to_enum_slice(flag_buf[:], bs) @(require_results) -bitset_to_enum_slice :: proc(buf: []$E, bs: $T) -> (slice: []E) where intrinsics.type_is_enum(E) && intrinsics.type_bit_set_elem_type(T) == E { +bitset_to_enum_slice_with_buffer :: proc(buf: []$E, bs: $T) -> (slice: []E) where intrinsics.type_is_enum(E) && intrinsics.type_bit_set_elem_type(T) == E { count := 0 for v in bs { buf[count] = v count += 1 } return buf[:count] -}
\ No newline at end of file +} + +// Turn a `bit_set[E]` into a `[]E`, allocates +// e.g.: +// sl := slice.bitset_to_enum_slice(bs) +@(require_results) +bitset_to_enum_slice_with_make :: proc(buf: []$E, bs: $T) -> (slice: []E) where intrinsics.type_is_enum(E) && intrinsics.type_bit_set_elem_type(T) == E { + + count := 0 + for v in bs { + buf[count] = v + count += 1 + } + return buf[:count] +} + +bitset_to_enum_slice :: proc{bitset_to_enum_slice_with_make, bitset_to_enum_slice_with_buffer}
\ No newline at end of file |