Ranks and blocks in sorted lists #
In a list sorted by a key, the entries with a given key form one contiguous block, which starts right after the entries with smaller keys. These facts underlie counting-sort and rank arguments, such as the LF-mapping of the Burrows–Wheeler transform.
Main results #
List.getElem?_filter_countP_take: among the entries satisfyingp, entryrsits at the number of earlier entries satisfyingp.List.Pairwise.filter_eq_takeWhile: filtering by a predicate whose true entries precede its false entries keeps a prefix.List.Pairwise.filter_key_eq: in a list sorted by a keyf, the entries with keygare the block that starts after the entries with smaller key.List.Pairwise.count_take_countP_lt_add: in a sorted list, the prefix that endskplaces into the block ofccontainsmin k (l.count c)copies ofc.
theorem List.Pairwise.filter_key_eq {α : Type u_1} {β : Type u_2} [LinearOrder β] (f : α → β) (g : β) {l : List α} :
In a list sorted by a key f, the entries with key g form one block, which starts after
the entries with smaller key.
theorem List.Pairwise.count_take_countP_lt_add {α : Type u_1} [LinearOrder α] (c : α) (k : ℕ) {l : List α} :
In a sorted list, the prefix that ends k places into the block of c contains
min k (l.count c) copies of c.