API
#container/ring
Xu 0.8.8 API
import: #container/ring
counts: 9 fns, 4 methods, 1 types, 0 consts, 0 ifaces
Ring list; values are owning strings.
struct Ring
pub struct Ring {
pub val []string
pub next []int
pub prev []int
pub cur int
}
Purpose
Circular list aligned with `container/ring`, specialized to owning strings (no `temp`, no element pointers). a Ring owns a dense circular arena; element handles are indices. Unlink/link rebuild the active cycle (O(n)) — fine for the small rings this package targets. Do(fn) available since (fn values).
Parameters
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) (borrowed; caller keeps it; 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) (borrowed; caller keeps it; type &Ring)
e int- e (int)
Returns
int — a value of this type
prev
pub fn prev(r &Ring, e int) int
Purpose
prev; returns int.
Parameters
r &Ring- rune (Unicode code point) (borrowed; caller keeps it; 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
move; returns int.
Parameters
r &Ring- rune (Unicode code point) (borrowed; caller keeps it; 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
value; returns string.
Parameters
r &Ring- rune (Unicode code point) (borrowed; caller keeps it; type &Ring)
e int- e (int)
Returns
string — result string
(&mut Ring) set_value
pub fn (r &mut Ring) set_value(e int, v string)
Purpose
Method on `&mut Ring`: set value.
Parameters
r &mut Ring- receiver &mut Ring (exclusive borrow)
e int- e (int)
v string- value (string)
cur
Purpose
cur; returns int.
Parameters
r &Ring- rune (Unicode code point) (borrowed; caller keeps it; type &Ring)
Returns
int — a value of this type
(&mut Ring) set_cur
pub fn (r &mut Ring) set_cur(e int)
Purpose
Method on `&mut Ring`: set cur.
Parameters
r &mut Ring- receiver &mut Ring (exclusive borrow)
e int- e (int)
values
pub fn values(r &Ring) []string
Purpose
values; returns []string.
Parameters
r &Ring- rune (Unicode code point) (borrowed; caller keeps it; 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) (borrowed; caller keeps it; type &Ring)
f fn(string)- byte callback: argument is 0..255, return whether it matches
(&mut Ring) unlink
pub fn (r &mut 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 &mut Ring- receiver &mut Ring (exclusive borrow)
e int- e (int)
n int- count, length, or limit (int)
Returns
Ring — a value of this type
(&mut Ring) link
pub fn (r &mut Ring) link(e int, s &mut 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 &mut Ring- receiver &mut Ring (exclusive borrow)
e int- e (int)
s &mut Ring- source string (exclusive borrow; type &mut Ring)
Returns
int — a value of this type