package core:slice

⌘K
Ctrl+K
or
/

    Index

    Constants (0)

    This section is empty.

    Variables (0)

    This section is empty.

    Procedures (104)
    Procedure Groups (2)

    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

    Permutation_Iterator ¶

    Permutation_Iterator :: struct($Value: typeid) {}
     

    An in-place permutation iterator.

    Related Procedures With Parameters
    Related Procedures With Returns

    Constants

    This section is empty.

    Variables

    This section is empty.

    Procedures

    all_of ¶

    all_of :: proc(s: $T/[]$T, value: $T) -> bool {…}

    all_of_proc ¶

    all_of_proc :: proc(s: $T/[]$T, f: proc($T) -> bool) -> bool {…}

    any_of ¶

    any_of :: proc(s: $T/[]$T, value: $T) -> bool {…}

    any_of_proc ¶

    any_of_proc :: proc(s: $T/[]$T, f: proc($T) -> bool) -> bool {…}

    as_ptr ¶

    as_ptr :: proc(array: $T/[]$T) -> [^]$T {…}
    binary_search :: proc(array: $T/[]$T, key: $T) -> (index: int, found: bool) {…}
     

    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.

    For slices of more complex types see: binary_search_by

    Example:
    /*
    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)
    

    binary_search_by ¶

    binary_search_by :: proc(array: $T/[]$T, key: $T, f: proc($T, $T) -> Ordering) -> (index: int, found: bool) {…}
     

    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.

    The array elements and key may be different types. This allows the filter procedure to compare keys against a slice of structs, one struct value at a time.

    Returns:
    index: int found: bool

    bitset_to_enum_slice_with_buffer ¶

    bitset_to_enum_slice_with_buffer :: proc(buf: []$T, bs: $T) -> (slice: []$T) {…}
     

    Turn a bit_set[E] into a []E e.g.: sl := slice.bitset_to_enum_slice(flag_buf[:], bs)

    bitset_to_enum_slice_with_make ¶

    bitset_to_enum_slice_with_make :: proc(bs: $T, $E: typeid, allocator := context.allocator) -> (slice: []typeid) {…}
     

    Turn a bit_set[E] into a []E, allocates e.g.: sl := slice.bitset_to_enum_slice(bs)

    bytes_from_ptr ¶

    bytes_from_ptr :: proc "contextless" (ptr: rawptr, byte_count: int) -> []u8 {…}
     

    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

    cmp ¶

    cmp :: proc(a, b: $T) -> Ordering {…}

    cmp_proc ¶

    cmp_proc :: proc($E: typeid) -> proc(typeid, typeid) -> Ordering {…}

    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 {…}

    count ¶

    count :: proc(s: $T/[]$T, value: $T) -> (n: int) {…}

    count_proc ¶

    count_proc :: proc(s: $T/[]$T, f: proc($T) -> bool) -> (n: int) {…}

    destroy_permutation_iterator ¶

    destroy_permutation_iterator :: proc(iter: Permutation_Iterator($T), allocator := context.allocator) {…}
     

    Free the state allocated by make_permutation_iterator.

    Inputs:
    iter: The iterator created by make_permutation_iterator. allocator: The allocator used to create the iterator. (default is context.allocator)

    dot_product ¶

    dot_product :: proc(a, b: $T/[]$T) -> (r: $T, ok: bool) {…}

    enum_slice_to_bitset ¶

    enum_slice_to_bitset :: proc(enums: []$T, $T: typeid/bit_set[T]) -> (bits: T) {…}
     

    Turn a []E into bit_set[E] e.g.: bs := slice.enum_slice_to_bitset(my_flag_slice, rl.ConfigFlags)

    enumerated_array ¶

    enumerated_array :: proc(ptr: ^$T) -> []$T {…}
     

    Convert a pointer to an enumerated array to a slice of the element type

    equal ¶

    equal :: proc(a, b: $T/[]$T) -> bool {…}

    fill ¶

    fill :: proc(array: $T/[]$T, value: $T) {…}

    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 ¶

    first :: proc(array: $T/[]$T) -> $T {…}

    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.

    get ¶

    get :: proc(array: $T/[]$T, index: int) -> (value: $T, ok: bool) {…}

    get_ptr ¶

    get_ptr :: proc(array: $T/[]$T, index: int) -> (value: ^$T, ok: bool) {…}

    has_prefix ¶

    has_prefix :: proc(array: $T/[]$T, needle: $T/[]$T) -> bool {…}

    has_suffix ¶

    has_suffix :: proc(array: $T/[]$T, needle: $T/[]$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 ¶

    is_sorted_by :: proc(array: $T/[]$T, less: proc(i, j: $T) -> bool) -> bool {…}

    is_sorted_by_key ¶

    is_sorted_by_key :: proc(array: $T/[]$T, key: proc($T) -> $T) -> bool {…}

    is_sorted_cmp ¶

    is_sorted_cmp :: proc(array: $T/[]$T, cmp: proc(i, j: $T) -> Ordering) -> bool {…}

    last ¶

    last :: proc(array: $T/[]$T) -> $T {…}

    last_ptr ¶

    last_ptr :: proc(array: $T/[]$T) -> ^$T {…}

    length ¶

    length :: proc(a: $T/[]$T) -> int {…}
    linear_search :: proc(array: $T/[]$T, key: $T) -> (index: int, found: bool) {…}
     

    Searches the given slice for the given element in O(n) time.

    If you need a custom search condition, see linear_search_proc

    Inputs:
    array: The slice to search in. key: The element to search for.

    Returns:
    index: The index i, such that array[i] is the first occurrence of key in array, or -1 if key is not present in array.

    Example:
    index: int
    found: bool
    
    a := []i32{10, 10, 10, 20}
    
    index, found = linear_search_reverse(a, 10)
    assert(index == 0 && found == true)
    
    index, found = linear_search_reverse(a, 30)
    assert(index == -1 && found == false)
    
    // Note that `index == 1`, since it is relative to `a[2:]`
    index, found = linear_search_reverse(a[2:], 20)
    assert(index == 1 && found == true)
    

    linear_search_proc ¶

    linear_search_proc :: proc(array: $T/[]$T, f: proc($T) -> bool) -> (index: int, found: bool) {…}
     

    Searches the given slice for the first element satisfying predicate f in O(n) time.

    Inputs:
    array: The slice to search in. f: The search condition.

    Returns:
    index: The index i, such that array[i] is the first x in array for which f(x) == true, or -1 if such x does not exist.

    linear_search_reverse ¶

    linear_search_reverse :: proc(array: $T/[]$T, key: $T) -> (index: int, found: bool) {…}
     

    Searches the given slice for the given element in O(n) time, starting from the slice end.

    If you need a custom search condition, see linear_search_reverse_proc

    Inputs:
    array: The slice to search in. key: The element to search for.

    Returns:
    index: The index i, such that array[i] is the last occurrence of key in array, or -1 if key is not present in array.

    Example:
    index: int
    found: bool
    
    a := []i32{10, 10, 10, 20}
    
    index, found = linear_search_reverse(a, 20)
    assert(index == 3 && found == true)
    
    index, found = linear_search_reverse(a, 10)
    assert(index == 2 && found == true)
    
    index, found = linear_search_reverse(a, 30)
    assert(index == -1 && found == false)
    
    // Note that `index == 1`, since it is relative to `a[2:]`
    index, found = linear_search_reverse(a[2:], 20)
    assert(index == 1 && found == true)
    

    linear_search_reverse_proc ¶

    linear_search_reverse_proc :: proc(array: $T/[]$T, f: proc($T) -> bool) -> (index: int, found: bool) {…}
     

    Searches the given slice for the last element satisfying predicate f in O(n) time, starting from the slice end.

    Inputs:
    array: The slice to search in. f: The search condition.

    Returns:
    index: The index i, such that array[i] is the last x in array for which f(x) == true, or -1 if such x does not exist.

    make_permutation_iterator ¶

    make_permutation_iterator :: proc(slice: []$T, allocator := context.allocator) -> (iter: Permutation_Iterator($T), error: runtime.Allocator_Error) #optional_ok {…}
     

    Make an iterator to permute a slice in-place.

    Allocates Using Provided Allocator

    This procedure allocates some state to assist in permutation and does not make a copy of the underlying slice. If you want to permute a slice without altering the underlying data, use clone to create a copy, then permute that instead.

    Inputs:
    slice: The slice to permute. allocator: (default is context.allocator)

    Returns:
    iter: The iterator, to be passed to permute. error: An Allocator_Error, if allocation failed.

    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), err: runtime.Allocator_Error) {…}

    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 ¶

    max :: proc(s: $T/[]$T) -> (res: $T, ok: bool) #optional_ok {…}

    max_index ¶

    max_index :: proc(s: $T/[]$T) -> (max_index: int, ok: bool) #optional_ok {…}
     

    Find the index of the (first) maximum element in a slice.

    min ¶

    min :: proc(s: $T/[]$T) -> (res: $T, ok: bool) #optional_ok {…}

    min_index ¶

    min_index :: proc(s: $T/[]$T) -> (min_index: int, ok: bool) #optional_ok {…}
     

    Find the index of the (first) minimum element in a slice.

    min_max ¶

    min_max :: proc(s: $T/[]$T) -> (min, max: $T, ok: bool) {…}

    none_of ¶

    none_of :: proc(s: $T/[]$T, value: $T) -> bool {…}

    none_of_proc ¶

    none_of_proc :: proc(s: $T/[]$T, f: proc($T) -> bool) -> bool {…}

    permute ¶

    permute :: proc(iter: ^Permutation_Iterator($T)) -> (ok: bool) {…}
     

    Permute a slice in-place.

    Note that the first iteration will always be the original, unpermuted slice.

    Inputs:
    iter: The iterator created by make_permutation_iterator.

    Returns:
    ok: True if the permutation succeeded, false if the iteration is complete.

    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

    ptr_add ¶

    ptr_add :: proc(p: $P/^$T, x: int) -> ^$T {…}

    ptr_rotate ¶

    ptr_rotate :: proc(left: int, mid: ^$T, right: int) {…}

    ptr_sub ¶

    ptr_sub :: proc(p: $P/^$T, x: int) -> ^$T {…}

    ptr_swap_non_overlapping ¶

    ptr_swap_non_overlapping :: proc(x, y: rawptr, len: int) {…}

    ptr_swap_overlapping ¶

    ptr_swap_overlapping :: proc(x, y: rawptr, len: int) {…}

    reduce ¶

    reduce :: proc(s: $T/[]$T, initializer: $T, f: proc($T, $T) -> $T) -> $T {…}

    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 ¶

    reverse :: proc(array: $T/[]$T) {…}

    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 {…}

    size ¶

    size :: proc "contextless" (a: $T/[]$T) -> int {…}
     

    Gets the byte size of the backing data

    sort ¶

    sort :: proc(data: $T/[]$T) {…}
     

    sort sorts a slice This sort is not guaranteed to be stable

    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 ¶

    stable_sort :: proc(data: $T/[]$T) {…}
     

    stable_sort sorts a slice

    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 ¶

    swap :: proc(array: $T/[]$T, a, b: int) {…}

    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.

    to_dynamic ¶

    to_dynamic :: clone_to_dynamic
     

    copies slice into a new dynamic array

    to_type ¶

    to_type :: proc(buf: []u8, $T: typeid) -> (typeid, bool) #optional_ok {…}
     

    Turns a byte slice into a type.

    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.

    zero ¶

    zero :: proc(array: $T/[]$T) {…}

    Procedure Groups

    Source Files

    Generation Information

    Generated with odin version dev-2024-11 (vendor "odin") Windows_amd64 @ 2024-11-16 21:10:10.078921500 +0000 UTC