mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-13 06:43:35 +00:00
Add make version of bitset to slice.
This commit is contained in:
@@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
// 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}
|
||||
Reference in New Issue
Block a user