#container/ring
Xu 0.16.0 API
import: #container/ring
counts: 9 functions, 4 methods, 1 types, 0 constants, 0 method sets
Ring list; values are owning strings.
struct Ring
pub struct Ring {
pub val []string
pub next []int
pub prev []int
pub cur int
}
Purpose
Structure encapsulating val, next, prev, cur.
Public fields
val []string- value
next []int- field ([]int)
prev []int- field ([]int)
cur int- field (int)
new
Purpose
Construct a new value of this type.
Parameters
n int- count, length, or limit (int)
Returns
Ring — a value of this type
len
Purpose
Return the length.
Parameters
r &Ring- rune (Unicode code point) (read-only borrow; caller keeps the original; type &Ring)
Returns
int — a value of this type
next
pub fn next(r &Ring, e int) int
Purpose
Take the next item, or end according to this type.
Parameters
r &Ring- rune (Unicode code point) (read-only borrow; caller keeps the original; type &Ring)
e int- e (int)
Returns
int — a value of this type
prev
pub fn prev(r &Ring, e int) int
Purpose
Execute prev.
Parameters
r &Ring- rune (Unicode code point) (read-only borrow; caller keeps the original; type &Ring)
e int- e (int)
Returns
int — a value of this type
move
pub fn move(r &Ring, e int, n int) int
Purpose
Execute move.
Parameters
r &Ring- rune (Unicode code point) (read-only borrow; caller keeps the original; type &Ring)
e int- e (int)
n int- count, length, or limit (int)
Returns
int — a value of this type
value
pub fn value(r &Ring, e int) string
Purpose
Execute value.
Parameters
r &Ring- rune (Unicode code point) (read-only borrow; caller keeps the original; type &Ring)
e int- e (int)
Returns
string — result string
($&Ring) set_value
pub fn (r $&Ring) set_value(e int, v string)
Purpose
Operation on $&Ring: set value.
Parameters
r $&Ring- The
Ring instance used by this call (exclusive borrow).
e int- e (int)
v string- value (string)
Returns
This call does not return a value.
cur
Purpose
Return the current element value or index of the ring.
Parameters
r &Ring- rune (Unicode code point) (read-only borrow; caller keeps the original; type &Ring)
Returns
int — a value of this type
($&Ring) set_cur
pub fn (r $&Ring) set_cur(e int)
Purpose
Operation on $&Ring: set cur.
Parameters
r $&Ring- The
Ring instance used by this call (exclusive borrow).
e int- e (int)
Returns
This call does not return a value.
values
pub fn values(r &Ring) []string
Purpose
Execute values.
Parameters
r &Ring- rune (Unicode code point) (read-only borrow; caller keeps the original; type &Ring)
Returns
[]string — slice result
do
pub fn do(r &Ring, f fn(string))
Purpose
Do visits each element once, clockwise from cur.
Parameters
r &Ring- rune (Unicode code point) (read-only borrow; caller keeps the original; type &Ring)
f fn(string)- Callback with signature
fn(string); pass the function value for this operation to invoke.
Returns
This call does not return a value.
($&Ring) unlink
pub fn (r $&Ring) unlink(e int, n int) Ring
Purpose
unlink removes n % Len elements starting at next(e). Returns the removed subring. If n % Len == 0, returns empty and leaves r unchanged.
Parameters
r $&Ring- The
Ring instance used by this call (exclusive borrow).
e int- e (int)
n int- count, length, or limit (int)
Returns
Ring — a value of this type
($&Ring) link
pub fn (r $&Ring) link(e int, s $&Ring) int
Purpose
link splices s after e so next(e) becomes s.cur. Consumes s (left empty). Returns the original next(e) as the new index of that element in r, or -1.
Parameters
r $&Ring- The
Ring instance used by this call (exclusive borrow).
e int- e (int)
s $&Ring- s (exclusive borrow; may modify the original; type $&Ring)
Returns
int — a value of this type