Skip to main content

parse

Function parse 

Source
pub fn parse(input: &str) -> Result<PartitionSpec, String>
Expand description

Parse a cursor=... spec string into a PartitionSpec.

Accepts all three forms documented in SRD 71:

  • Form 1 — single sub-range: 0..53%, [0..53%), 100..1000, 0.05..0.5, 100..50%. Bracket placement and closure markers ([ ] ( )) are tolerated but advisory; the closure is always [start, end).
  • Form 2 — delta list: 2%,10%,*%, 0.02,0.10,*, 1000,5000,*, 1000,10%,*, 20%,30%. Tail tokens: * (remainder as one partition), ... (repeat the preceding delta until the extent is used up, e.g. 90%,1%,...), */N (remainder divided into N equal partitions, e.g. 90%,*/10), */recipe:args (remainder shaped by recipe weights, e.g. 90%,*/fib:5). Entry modifiers: <delta>xN finite repetition (1%x5 = five 1% chunks), ~<delta> gap (~10% consumes 10% of the extent without emitting a partition).
  • Form 3 — pre-baked recipe: linear:N, ratios:a,b,c,…, mul:R, mul:S,R, bin:N, fib:N, ln:N, geom:N,R, zipf:s,N, pareto:alpha,N, front_heavy:N, back_heavy:N.

The whole spec follows the token grammar chunking [in window] [order] — a whitespace-delimited in scopes the chunking to a Form 1 window (linear:5 in 25%..75%), and a trailing order keyword (unchanged / smallest_first / largest_first / random) reorders the resolved list for iteration (fib:5 largest_first).

Whitespace is otherwise ignored. Bracket characters ([, ], (, )) are stripped unconditionally — they’re advisory closure markers in the grammar (everything’s always [start, end) at resolve time), so any placement parses the same way.