XU XUv0.8.8
中文

API

#slices

import: #slices

counts: 62 fns, 0 methods, 1 types, 0 consts, 0 ifaces

int/string/f64 slice helpers: contains/index/equal/reverse/clone/sort_func and more.

contains_int

XuAPI
pub fn contains_int(xs []int, v int) bool

Purpose

Concrete helpers: generic `==` is not allowed on Type::Param at check time.

Parameters

xs []int
slice to operate on ([]int)
v int
value (int)

Returns

bool — true or false

index_of_int

XuAPI
pub fn index_of_int(xs []int, v int) int

Purpose

Index of int. Returns -1 if not found.

Parameters

xs []int
slice to operate on ([]int)
v int
value (int)

Returns

int — index; -1 if missing

last_index_int

XuAPI
pub fn last_index_int(xs &[]int, v int) int

Purpose

Last index int.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
v int
value (int)

Returns

int — index; -1 if missing

last_index_str

XuAPI
pub fn last_index_str(xs &[]string, v string) int

Purpose

Last index str.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
v string
value (string)

Returns

int — index; -1 if missing

sum_int

XuAPI
pub fn sum_int(xs []int) int

Purpose

Digest int.

Parameters

xs []int
slice to operate on ([]int)

Returns

int — a value of this type

contains_str

XuAPI
pub fn contains_str(xs []string, v string) bool

Purpose

Contains str.

Parameters

xs []string
slice to operate on ([]string)
v string
value (string)

Returns

bool — true or false

index_of_str

XuAPI
pub fn index_of_str(xs []string, v string) int

Purpose

`slices.Index` — first index of v, -1 when absent. Returns -1 if not found.

Parameters

xs []string
slice to operate on ([]string)
v string
value (string)

Returns

int — index; -1 if missing

equal_ints

XuAPI
pub fn equal_ints(a &[]int, b &[]int) bool

Purpose

`slices.Equal` — element-wise equality (read-only borrows).

Parameters

a &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
b &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)

Returns

bool — true or false

equal_strs

XuAPI
pub fn equal_strs(a &[]string, b &[]string) bool

Purpose

Equal strs.

Parameters

a &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
b &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)

Returns

bool — true or false

reverse_ints

XuAPI
pub fn reverse_ints(a &mut []int)

Purpose

`slices.Reverse` — in place, through the exclusive borrow. Every element store is bounds-checked and overwriting an owning (string) element drops its old value first (S1/S3).

Parameters

a &mut []int
slice to operate on (exclusive borrow; type &mut []int)

reverse_strs

XuAPI
pub fn reverse_strs(a &mut []string)

Purpose

Reverse strs.

Parameters

a &mut []string
slice to operate on (exclusive borrow; type &mut []string)

clone_ints

XuAPI
pub fn clone_ints(xs &[]int) []int

Purpose

`slices.Clone` — owning copies; the source is only read.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)

Returns

[]int — slice result

clone_strs

XuAPI
pub fn clone_strs(xs &[]string) []string

Purpose

Clone strs.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)

Returns

[]string — slice result

compare_ints

XuAPI
pub fn compare_ints(a &[]int, b &[]int) int

Purpose

Compare int slice.

Parameters

a &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
b &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)

Returns

int — a value of this type

compare_strs

XuAPI
pub fn compare_strs(a &[]string, b &[]string) int

Purpose

Compare strs.

Parameters

a &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
b &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)

Returns

int — a value of this type

compact_ints

XuAPI
pub fn compact_ints(xs &[]int) []int

Purpose

Compact int slice.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)

Returns

[]int — slice result

compact_strs

XuAPI
pub fn compact_strs(xs &[]string) []string

Purpose

Compact strs.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)

Returns

[]string — slice result

insert_int

XuAPI
pub fn insert_int(xs &[]int, i int, v int) []int

Purpose

Insert int.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
i int
index or integer (int)
v int
value (int)

Returns

[]int — slice result

insert_str

XuAPI
pub fn insert_str(xs &[]string, i int, v string) []string

Purpose

Insert str.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
i int
index or integer (int)
v string
value (string)

Returns

[]string — slice result

delete_ints

XuAPI
pub fn delete_ints(xs &[]int, i int, j int) []int

Purpose

Delete int slice.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
i int
index or integer (int)
j int
index (int)

Returns

[]int — slice result

delete_strs

XuAPI
pub fn delete_strs(xs &[]string, i int, j int) []string

Purpose

Delete strs.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
i int
index or integer (int)
j int
index (int)

Returns

[]string — slice result

min_int

XuAPI
pub fn min_int(xs &[]int) int

Purpose

Min int. Throws on failure.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)

Returns

int — a value of this type

max_int

XuAPI
pub fn max_int(xs &[]int) int

Purpose

Max int. Throws on failure.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)

Returns

int — a value of this type

contains_f64

XuAPI
pub fn contains_f64(xs &[]f64, v f64) bool

Purpose

Contains f64.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
v f64
value (f64)

Returns

bool — true or false

index_of_f64

XuAPI
pub fn index_of_f64(xs &[]f64, v f64) int

Purpose

Index of f64. Returns -1 if not found.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
v f64
value (f64)

Returns

int — index; -1 if missing

equal_f64s

XuAPI
pub fn equal_f64s(a &[]f64, b &[]f64) bool

Purpose

Equal f64 slice.

Parameters

a &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
b &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)

Returns

bool — true or false

clone_f64s

XuAPI
pub fn clone_f64s(xs &[]f64) []f64

Purpose

Clone f64 slice.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)

Returns

[]f64 — slice result

reverse_f64s

XuAPI
pub fn reverse_f64s(a &mut []f64)

Purpose

Reverse f64 slice.

Parameters

a &mut []f64
slice to operate on (exclusive borrow; type &mut []f64)

min_f64

XuAPI
pub fn min_f64(xs &[]f64) f64

Purpose

Min f64. Throws on failure.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)

Returns

f64 — a value of this type

max_f64

XuAPI
pub fn max_f64(xs &[]f64) f64

Purpose

Max f64. Throws on failure.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)

Returns

f64 — a value of this type

compare_f64s

XuAPI
pub fn compare_f64s(a &[]f64, b &[]f64) int

Purpose

Compare f64 slice.

Parameters

a &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
b &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)

Returns

int — a value of this type

compact_f64s

XuAPI
pub fn compact_f64s(xs &[]f64) []f64

Purpose

Compact f64 slice.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)

Returns

[]f64 — slice result

insert_f64

XuAPI
pub fn insert_f64(xs &[]f64, i int, v f64) []f64

Purpose

Insert f64.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
i int
index or integer (int)
v f64
value (f64)

Returns

[]f64 — slice result

delete_f64s

XuAPI
pub fn delete_f64s(xs &[]f64, i int, j int) []f64

Purpose

Delete f64 slice.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
i int
index or integer (int)
j int
index (int)

Returns

[]f64 — slice result

struct SearchResult

XuAPI
pub struct SearchResult {
    pub index int
    pub found bool
}

Purpose

Public struct `SearchResult`.

Parameters

index int
field (int)
found bool
field (bool)

binary_search_ints

XuAPI
pub fn binary_search_ints(xs &[]int, v int) SearchResult

Purpose

Binary search a sorted slice; returns index and whether it was found.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
v int
value (int)

Returns

SearchResult — a value of this type

binary_search_strs

XuAPI
pub fn binary_search_strs(xs &[]string, v string) SearchResult

Purpose

Binary search a sorted slice; returns index and whether it was found.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
v string
value (string)

Returns

SearchResult — a value of this type

binary_search_f64s

XuAPI
pub fn binary_search_f64s(xs &[]f64, v f64) SearchResult

Purpose

Binary search a sorted slice; returns index and whether it was found.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
v f64
value (f64)

Returns

SearchResult — a value of this type

replace_ints

XuAPI
pub fn replace_ints(xs &[]int, i int, j int, add &[]int) []int

Purpose

Replace int slice.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
i int
index or integer (int)
j int
index (int)
add &[]int
add (borrowed; caller keeps it; type &[]int)

Returns

[]int — slice result

replace_strs

XuAPI
pub fn replace_strs(xs &[]string, i int, j int, add &[]string) []string

Purpose

Replace strs.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
i int
index or integer (int)
j int
index (int)
add &[]string
add (borrowed; caller keeps it; type &[]string)

Returns

[]string — slice result

concat_ints

XuAPI
pub fn concat_ints(a &[]int, b &[]int) []int

Purpose

Concat int slice.

Parameters

a &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
b &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)

Returns

[]int — slice result

repeat_ints

XuAPI
pub fn repeat_ints(xs &[]int, n int) []int

Purpose

Repeat int slice. Throws on failure.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
n int
count, length, or limit (int)

Returns

[]int — slice result

repeat_strs

XuAPI
pub fn repeat_strs(xs &[]string, n int) []string

Purpose

Repeat strs. Throws on failure.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
n int
count, length, or limit (int)

Returns

[]string — slice result

index_func_ints

XuAPI
pub fn index_func_ints(xs &[]int, f fn(int) bool) int

Purpose

Index callback int slice.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

Returns

int — index; -1 if missing

contains_func_ints

XuAPI
pub fn contains_func_ints(xs &[]int, f fn(int) bool) bool

Purpose

Contains callback int slice.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

Returns

bool — true or false

index_func_strs

XuAPI
pub fn index_func_strs(xs &[]string, f fn(string) bool) int

Purpose

Index callback strs.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
f fn(string) bool
byte callback: argument is 0..255, return whether it matches

Returns

int — index; -1 if missing

concat_strs

XuAPI
pub fn concat_strs(a &[]string, b &[]string) []string

Purpose

Concat strs.

Parameters

a &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
b &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)

Returns

[]string — slice result

sort_ints_func

XuAPI
pub fn sort_ints_func(a &mut []int, less fn(int, int) bool)

Purpose

Concrete SortFunc stand-ins. Generic `sort_func#T` wrapping `sort.slice_func` panics the frozen primer (xuhir index 263) and would fail every oracle fixture that imports this package.

Parameters

a &mut []int
slice to operate on (exclusive borrow; type &mut []int)
less fn(int, int) bool
less callback: true means left < right (function value; type fn(int, int) bool)

sort_strs_func

XuAPI
pub fn sort_strs_func(a &mut []string, less fn(string, string) bool)

Purpose

Sort strs callback.

Parameters

a &mut []string
slice to operate on (exclusive borrow; type &mut []string)
less fn(string, string) bool
less callback: true means left < right (function value; type fn(string, string) bool)

last_index_func_ints

XuAPI
pub fn last_index_func_ints(xs &[]int, f fn(int) bool) int

Purpose

Last index callback int slice.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

Returns

int — index; -1 if missing

last_index_func_strs

XuAPI
pub fn last_index_func_strs(xs &[]string, f fn(string) bool) int

Purpose

Last index callback strs.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
f fn(string) bool
byte callback: argument is 0..255, return whether it matches

Returns

int — index; -1 if missing

min_str

XuAPI
pub fn min_str(xs &[]string) string

Purpose

Min str. Throws on failure.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)

Returns

string — result string

max_str

XuAPI
pub fn max_str(xs &[]string) string

Purpose

Max str. Throws on failure.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)

Returns

string — result string

is_sorted_ints

XuAPI
pub fn is_sorted_ints(xs &[]int) bool

Purpose

Whether it is sorted ints.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)

Returns

bool — true or false

is_sorted_strs

XuAPI
pub fn is_sorted_strs(xs &[]string) bool

Purpose

Whether it is sorted strs.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)

Returns

bool — true or false

last_index_f64

XuAPI
pub fn last_index_f64(xs &[]f64, v f64) int

Purpose

Last index f64.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
v f64
value (f64)

Returns

int — index; -1 if missing

concat_f64s

XuAPI
pub fn concat_f64s(a &[]f64, b &[]f64) []f64

Purpose

Concat f64 slice.

Parameters

a &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
b &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)

Returns

[]f64 — slice result

replace_f64s

XuAPI
pub fn replace_f64s(xs &[]f64, i int, j int, add &[]f64) []f64

Purpose

Replace f64 slice.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
i int
index or integer (int)
j int
index (int)
add &[]f64
add (borrowed; caller keeps it; type &[]f64)

Returns

[]f64 — slice result

repeat_f64s

XuAPI
pub fn repeat_f64s(xs &[]f64, n int) []f64

Purpose

Repeat f64 slice. Throws on failure.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)
n int
count, length, or limit (int)

Returns

[]f64 — slice result

is_sorted_f64s

XuAPI
pub fn is_sorted_f64s(xs &[]f64) bool

Purpose

Whether it is sorted f64s.

Parameters

xs &[]f64
slice to operate on (borrowed; caller keeps it; type &[]f64)

Returns

bool — true or false

contains_func_strs

XuAPI
pub fn contains_func_strs(xs &[]string, f fn(string) bool) bool

Purpose

Contains callback strs.

Parameters

xs &[]string
slice to operate on (borrowed; caller keeps it; type &[]string)
f fn(string) bool
byte callback: argument is 0..255, return whether it matches

Returns

bool — true or false

compact_func_ints

XuAPI
pub fn compact_func_ints(xs &[]int, eq fn(int, int) bool) []int

Purpose

Compact callback int slice.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
eq fn(int, int) bool
eq (function value; type fn(int, int) bool)

Returns

[]int — slice result

delete_func_ints

XuAPI
pub fn delete_func_ints(xs &[]int, f fn(int) bool) []int

Purpose

Delete callback int slice.

Parameters

xs &[]int
slice to operate on (borrowed; caller keeps it; type &[]int)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

Returns

[]int — slice result