package core:slice
Index
Types (3)
Constants (0)
This section is empty.
Variables (0)
This section is empty.
Procedures (94)
- all_of
- all_of_proc
- any_of
- any_of_proc
- as_ptr
- binary_search
- binary_search_by
- bytes_from_ptr
- clone
- clone_to_dynamic
- cmp
- cmp_proc
- concatenate
- contains
- count
- count_proc
- dot_product
- enumerated_array
- equal
- fill
- filter
- filter_reverse
- first
- first_ptr
- from_ptr
- get
- get_ptr
- has_prefix
- has_suffix
- into_dynamic
- is_empty
- is_sorted
- is_sorted_by
- is_sorted_by_cmp
- is_sorted_by_key
- is_sorted_cmp
- last
- last_ptr
- length
- linear_search
- linear_search_proc
- map_entries
- map_entry_infos
- map_keys
- map_values
- mapper
- max
- max_index
- min
- min_index
- min_max
- none_of
- none_of_proc
- prefix_length
- ptr_add
- ptr_rotate
- ptr_sub
- ptr_swap_non_overlapping
- ptr_swap_overlapping
- reduce
- reduce_reverse
- reinterpret
- repeat
- reverse
- reverse_sort
- reverse_sort_by
- reverse_sort_by_cmp
- reverse_sort_by_key
- rotate_left
- rotate_right
- scanner
- simple_equal
- sort
- sort_by
- sort_by_cmp
- sort_by_indices_allocate
- sort_by_indices_overwrite
- sort_by_key
- sort_by_with_indices
- sort_with_indices
- split_at
- split_first
- split_last
- stable_sort
- stable_sort_by
- stable_sort_by_cmp
- swap
- swap_between
- swap_with_slice
- to_bytes
- to_dynamic
- unique
- unique_proc
- zero
Procedure Groups (1)
Types
Map_Entry ¶
Map_Entry :: struct($Key: typeid, $Value: typeid) where intrinsics.type_is_valid_map_key(Key) {}
Map_Entry_Info ¶
Map_Entry_Info :: struct($Key: typeid, $Value: typeid) where intrinsics.type_is_valid_map_key(Key) {}
Ordering ¶
Ordering :: enum int { Less = -1, Equal = 0, Greater = 1, }
Related Procedures With Returns
Constants
This section is empty.
Variables
This section is empty.
Procedures
binary_search ¶
Binary search searches the given slice for the given element.
If the slice is not sorted, the returned index is unspecified and meaningless. If the value is found then the returned int is the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then the returned int is the index where a matching element could be inserted while maintaining sorted order. # Examples Looks up a series of four elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in `[1, 4]`. ``` index: int found: bool s := []i32{0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55} index, found = slice.binary_search(s, 13) assert(index == 9 && found == true) index, found = slice.binary_search(s, 4) assert(index == 7 && found == false) index, found = slice.binary_search(s, 100) assert(index == 13 && found == false) index, found = slice.binary_search(s, 1) assert(index >= 1 && index <= 4 && found == true) ``` For slices of more complex types see: binary_search_by
bytes_from_ptr ¶
Turn a pointer and a length into a byte slice.
clone ¶
clone :: proc(a: $T/[]$T, allocator := context.allocator, loc := #caller_location) -> ([]$T, runtime.Allocator_Error) #optional_ok {…}
copies a slice into a new slice
clone_to_dynamic ¶
clone_to_dynamic :: proc(a: $T/[]$T, allocator := context.allocator, loc := #caller_location) -> ([dynamic]$T, runtime.Allocator_Error) #optional_ok {…}
copies slice into a new dynamic array
concatenate ¶
concatenate :: proc(a: []$T/[]$T, allocator := context.allocator) -> (res: $T/[]$T, err: runtime.Allocator_Error) #optional_ok {…}
contains ¶
contains :: proc(array: $T/[]$T, value: $T) -> bool {…}
dot_product ¶
dot_product :: proc(a, b: $T/[]$T) -> (r: $T, ok: bool) {…}
enumerated_array ¶
enumerated_array :: proc(ptr: ^$T) -> []$T {…}
Convert a pointer to an enumerated array to a slice of the element type
filter ¶
filter :: proc(s: $T/[]$T, f: proc(_: $T) -> bool, allocator := context.allocator) -> (res: $T/[]$T, err: runtime.Allocator_Error) #optional_ok {…}
filter_reverse ¶
filter_reverse :: proc(s: $T/[]$T, f: proc(_: $T) -> bool, allocator := context.allocator) -> (res: $T/[]$T, err: runtime.Allocator_Error) #optional_ok {…}
first_ptr ¶
first_ptr :: proc(array: $T/[]$T) -> ^$T {…}
from_ptr ¶
from_ptr :: proc "contextless" (ptr: ^$T, count: int) -> []$T {…}
Turn a pointer and a length into a slice.
has_prefix ¶
has_prefix :: proc(array: $T/[]$T, needle: $T) -> bool {…}
has_suffix ¶
has_suffix :: proc(array: $T/[]$T, needle: $T) -> bool {…}
into_dynamic ¶
into_dynamic :: proc(a: $T/[]$T) -> [dynamic]$T {…}
Converts slice into a dynamic array without cloning or allocating memory
is_empty ¶
is_empty :: proc(a: $T/[]$T) -> bool {…}
is_sorted ¶
is_sorted :: proc(array: $T/[]$T) -> bool {…}
is_sorted_by_cmp ¶
is_sorted_by_cmp :: is_sorted_cmp
is_sorted_by_key ¶
is_sorted_by_key :: proc(array: $T/[]$T, key: proc(_: $T) -> $T) -> bool {…}
last_ptr ¶
last_ptr :: proc(array: $T/[]$T) -> ^$T {…}
map_entries ¶
map_entries :: proc(m: $T/map[$T]$T, allocator := context.allocator) -> (entries: []Map_Entry($Key, $Value), err: runtime.Allocator_Error) {…}
map_entry_infos ¶
map_entry_infos :: proc(m: $T/map[$T]$T, allocator := context.allocator) -> (entries: []Map_Entry_Info($Key, $Value)) {…}
map_keys ¶
map_keys :: proc(m: $T/map[$T]$T, allocator := context.allocator) -> (keys: []$T, err: runtime.Allocator_Error) {…}
map_values ¶
map_values :: proc(m: $T/map[$T]$T, allocator := context.allocator) -> (values: []$T, err: runtime.Allocator_Error) {…}
mapper ¶
mapper :: proc(s: $T/[]$T, f: proc(_: $T) -> $T, allocator := context.allocator) -> (r: []$T, err: runtime.Allocator_Error) #optional_ok {…}
max_index ¶
Find the index of the (first) maximum element in a slice.
min_index ¶
Find the index of the (first) minimum element in a slice.
prefix_length ¶
prefix_length :: proc(a, b: $T/[]$T) -> (n: int) {…}
return the prefix length common between slices a
and b
.
slice.prefix_length([]u8{1, 2, 3, 4}, []u8{1}) -> 1 slice.prefix_length([]u8{1, 2, 3, 4}, []u8{1, 2, 3}) -> 3 slice.prefix_length([]u8{1, 2, 3, 4}, []u8{2, 3, 4}) -> 0
reduce_reverse ¶
reduce_reverse :: proc(s: $T/[]$T, initializer: $T, f: proc(_: $T, _: $T) -> $T) -> $T {…}
reinterpret ¶
reinterpret :: proc "contextless" ($T: typeid/[]T, s: []T) -> []T {…}
Turn a slice of one type, into a slice of another type.
Only converts the type and length of the slice itself. The length is rounded down to the nearest whole number of items. ``` large_items := []i64{1, 2, 3, 4} small_items := slice.reinterpret([]i32, large_items) assert(len(small_items) == 8) ``` ``` small_items := []byte{1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0} large_items := slice.reinterpret([]i64, small_items) assert(len(large_items) == 1) // only enough bytes to make 1 x i64; two would need at least 8 bytes. ```
repeat ¶
repeat :: proc(s: $T/[]$T, count: int, allocator := context.allocator) -> (b: $T/[]$T, err: runtime.Allocator_Error) #optional_ok {…}
reverse_sort ¶
reverse_sort :: proc(data: $T/[]$T) {…}
reverse_sort_by ¶
reverse_sort_by :: proc(data: $T/[]$T, less: proc(i, j: $T) -> bool) {…}
reverse_sort_by_cmp ¶
reverse_sort_by_cmp :: proc(data: $T/[]$T, cmp: proc(i, j: $T) -> Ordering) {…}
reverse_sort_by_key ¶
reverse_sort_by_key :: proc(data: $T/[]$T, key: proc(_: $T) -> $T) {…}
rotate_left ¶
rotate_left :: proc(array: $T/[]$T, mid: int) {…}
rotate_right ¶
rotate_right :: proc(array: $T/[]$T, k: int) {…}
scanner ¶
scanner :: proc(s: $T/[]$T, initializer: $T, f: proc(_: $T, _: $T) -> $T, allocator := context.allocator) -> (res: []$T, err: runtime.Allocator_Error) #optional_ok {…}
simple_equal ¶
simple_equal :: proc(a, b: $T/[]$T) -> bool {…}
sort_by ¶
sort_by :: proc(data: $T/[]$T, less: proc(i, j: $T) -> bool) {…}
sort_by sorts a slice with a given procedure to test whether two values are ordered "i < j" This sort is not guaranteed to be stable
sort_by_cmp ¶
sort_by_cmp :: proc(data: $T/[]$T, cmp: proc(i, j: $T) -> Ordering) {…}
sort_by_indices_allocate ¶
sort_by_indices_allocate :: proc(data: $T/[]$T, indices: []int, allocator := context.allocator) -> (sorted: $T/[]$T) {…}
sort_by_indices_overwrite ¶
sort_by_indices_overwrite :: proc(data: $T/[]$T, indices: []int) {…}
sort_by_key ¶
sort_by_key :: proc(data: $T/[]$T, key: proc(_: $T) -> $T) {…}
TODO(bill): Should sort_by_key
exist or is sort_by
more than enough?
sort_by_with_indices ¶
sort_by_with_indices :: proc(data: $T/[]$T, less: proc(i, j: $T) -> bool, allocator := context.allocator) -> (indices: []int) {…}
sort_by sorts a slice with a given procedure to test whether two values are ordered "i < j" This sort is not guaranteed to be stable
sort_with_indices ¶
sort_with_indices :: proc(data: $T/[]$T, allocator := context.allocator) -> (indices: []int) {…}
sort sorts a slice and returns a slice of the original indices This sort is not guaranteed to be stable
split_at ¶
split_at :: proc(array: $T/[]$T, index: int) -> (a, b: $T/[]$T) {…}
split_first ¶
split_first :: proc(array: $T/[]$T) -> (first: $T, rest: $T/[]$T) {…}
split_last ¶
split_last :: proc(array: $T/[]$T) -> (rest: $T/[]$T, last: $T) {…}
stable_sort_by ¶
stable_sort_by :: proc(data: $T/[]$T, less: proc(i, j: $T) -> bool) {…}
stable_sort_by sorts a slice with a given procedure to test whether two values are ordered "i < j"
stable_sort_by_cmp ¶
stable_sort_by_cmp :: proc(data: $T/[]$T, cmp: proc(i, j: $T) -> Ordering) {…}
swap_between ¶
swap_between :: proc(a, b: $T/[]$T) {…}
swap_with_slice ¶
swap_with_slice :: proc(a, b: $T/[]$T, loc := #caller_location) {…}
to_bytes ¶
to_bytes :: proc "contextless" (s: []$T) -> []u8 {…}
Turn a slice into a byte slice.
See `slice.reinterpret` to go the other way.
unique ¶
unique :: proc(s: $T/[]$T) -> $T/[]$T {…}
'unique' replaces consecutive runs of equal elements with a single copy. The procedures modifies the slice in-place and returns the modified slice.
unique_proc ¶
unique_proc :: proc(s: $T/[]$T, eq: proc(_: $T, _: $T) -> bool) -> $T/[]$T {…}
'unique_proc' replaces consecutive runs of equal elements with a single copy using a comparison procedure The procedures modifies the slice in-place and returns the modified slice.
Procedure Groups
sort_by_indices ¶
sort_by_indices :: proc{ sort_by_indices_allocate, _sort_by_indices, }
Source Files
Generation Information
Generated with odin version dev-2024-04 (vendor "odin") Windows_amd64 @ 2024-04-26 21:08:58.630668900 +0000 UTC